Skip to content

Commit 1b2e2e1

Browse files
committed
build(plugins): cap concurrent CGO plugin builds
* Limit default parallelism to four with DEVLAKE_PLUGIN_PARALLELISM override to reduce OOM on small hosts. * Add Cursor cost_reconciliation.sql queries and remove obsolete README rak_tools reference. Signed-off-by: Joshua Smith <jbsmith7741@gmail.com>
1 parent e43eaa1 commit 1b2e2e1

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

backend/plugins/cursor/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ Grafana dashboard JSON lives under `grafana/dashboards/mysql/`:
135135
| AI Cost Efficiency (Cursor panels) | `ai-cost-efficiency.json` ||
136136
| Multi-AI Comparison (Cursor panels) | `multi-ai-comparison.json` ||
137137

138-
See `grafana/dashboards/mysql/cursor-usage.json` for the dashboard definition and [rak_tools/grafana.md](../../../rak_tools/grafana.md) for currency formatting and Grafana version notes.
139-
140138
## Error handling
141139

142140
| Symptom | Likely cause |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- Cursor cost reconciliation queries
2+
-- Run against the lake database after a full billing-cycle event backfill.
3+
--
4+
-- Note: SUM(charged_cents) from events only reconciles with /teams/spend when
5+
-- ALL usage events for the billing cycle are collected (paginate filtered-usage-events).
6+
7+
-- Team-level rollup comparison
8+
SELECT
9+
ROUND(SUM(spend_cents) / 100, 2) AS spend_usd,
10+
ROUND(SUM(included_spend_cents) / 100, 2) AS included_usd,
11+
ROUND(SUM(spend_cents + included_spend_cents) / 100, 2) AS total_cycle_usd
12+
FROM _tool_cursor_user_spend;
13+
14+
SELECT
15+
ROUND(SUM(charged_cents) / 100, 2) AS event_charged_usd,
16+
ROUND(SUM(total_cents) / 100, 2) AS event_model_usd,
17+
COUNT(*) AS event_count,
18+
MIN(event_time) AS earliest_event,
19+
MAX(event_time) AS latest_event
20+
FROM _tool_cursor_usage_events;
21+
22+
-- Per-user: billing cycle spend vs event charged (since billing cycle start)
23+
SELECT
24+
s.email,
25+
ROUND(s.spend_cents / 100, 2) AS spend_usd,
26+
ROUND(s.included_spend_cents / 100, 2) AS included_usd,
27+
ROUND((s.spend_cents + s.included_spend_cents) / 100, 2) AS total_cycle_usd,
28+
ROUND(COALESCE(SUM(e.charged_cents), 0) / 100, 2) AS event_charged_usd,
29+
COUNT(e.event_id) AS event_count
30+
FROM _tool_cursor_user_spend s
31+
LEFT JOIN _tool_cursor_usage_events e
32+
ON s.email = e.user_email
33+
AND e.event_time >= s.billing_cycle_start
34+
GROUP BY s.email, s.spend_cents, s.included_spend_cents
35+
ORDER BY total_cycle_usd DESC;
36+
37+
-- Users with events but no spend row (should be empty)
38+
SELECT DISTINCT e.user_email
39+
FROM _tool_cursor_usage_events e
40+
LEFT JOIN _tool_cursor_user_spend s ON e.user_email = s.email
41+
WHERE s.email IS NULL;

backend/scripts/build-plugins.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,29 @@ fi
6464

6565

6666
PIDS=""
67+
# Cap concurrent CGO plugin builds. Unbounded nproc OOMs Docker Desktop / small VMs.
68+
# Override with DEVLAKE_PLUGIN_PARALLELISM=N (default: min(4, nproc)).
69+
if [ -n "$DEVLAKE_PLUGIN_PARALLELISM" ]; then
70+
PARALLELISM="$DEVLAKE_PLUGIN_PARALLELISM"
71+
else
72+
PARALLELISM=4
73+
if command -v nproc >/dev/null 2>&1; then
74+
PARALLELISM=$(nproc)
75+
elif command -v sysctl >/dev/null 2>&1; then
76+
PARALLELISM=$(sysctl -n hw.ncpu)
77+
fi
78+
if [ "$PARALLELISM" -gt 4 ]; then
79+
PARALLELISM=4
80+
fi
81+
fi
82+
echo "Plugin build parallelism: $PARALLELISM"
6783
for PLUG in $PLUGINS; do
6884
NAME=$(basename $PLUG)
6985
echo "Building plugin $NAME to bin/plugins/$NAME/$NAME.so with args: $* --gcflags="$GCFLAGS""
7086
go build -buildmode=plugin --gcflags="$GCFLAGS" -o $PLUGIN_OUTPUT_DIR/$NAME/$NAME.so $PLUG/*.go &
7187
PIDS="$PIDS $!"
7288
# avoid too many processes causing signal killed
7389
COUNT=$(echo "$PIDS" | wc -w)
74-
PARALLELISM=4
75-
if command -v nproc >/dev/null 2>&1; then
76-
PARALLELISM=$(nproc)
77-
elif command -v sysctl >/dev/null 2>&1; then
78-
PARALLELISM=$(sysctl -n hw.ncpu)
79-
fi
8090
if [ "$COUNT" -ge "$PARALLELISM" ]; then
8191
for PID in $PIDS; do
8292
wait $PID

0 commit comments

Comments
 (0)