feat(admin): builder pool free/used capacity - #2901
Conversation
Track worker pool size as +/- capacity events and persist build start/end intervals so the admin Builder tab can show live available/running workers and reconstruct hourly free vs used. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 23 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches📝 Generate docstrings
Comment |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_1f9dfe4a-93eb-4221-8487-7bcf9c31c638) |
There was a problem hiding this comment.
All reported issues were addressed across 13 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Seed the current pool size and let the builder worker POST worker +/- events to /build/capacity instead of recording on admin reads. Co-authored-by: Cursor <cursoragent@cursor.com>
Follow-up (AI generated)
Companion builder PR incoming. |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_2ef0954e-2ae7-4152-bbbc-f5fa086be3c1) |
|
Builder companion PR: https://github.com/Cap-go/capgo_builder/pull/167/ |
Merging this PR will not alter performance
Comparing Footnotes
|
Use builder-reported run starts only, reconstruct hourly usage in one sweep clipped to the selected range, record capacity events atomically, and harden the admin UI for unreachable/zero-worker states. Co-authored-by: Cursor <cursoragent@cursor.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_72105748-da01-4144-885a-4c4d21c92ce1) |
Review fixes (AI generated)Addressed in
|
There was a problem hiding this comment.
Actionable comments posted: 10
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/pages/admin/dashboard/builder.vue`:
- Around line 271-283: Update the loadCapacity flow to call
adminStore.fetchStats('builder_capacity', true), then create a managed refresh
interval that invokes loadCapacity while the dashboard is open. Store the
interval handle and clear it during the component’s unmount lifecycle,
preserving the existing loading and error handling.
In `@supabase/functions/_backend/public/build/capacity.ts`:
- Around line 1-21: Import MiddlewareKeyVariables from ../../utils/hono.ts and
type both assertBuilderApiKey and reportBuilderCapacity with
Context<MiddlewareKeyVariables>. Preserve their existing behavior while ensuring
requestId and other middleware context values remain typed.
In `@supabase/functions/_backend/utils/builder_capacity.ts`:
- Around line 261-323: Replace the read-then-insert flow in
recordBuilderCapacityIfChanged with an atomic conditional insert that selects
the latest workers_total, computes delta from it, and inserts only when the
value changes. Execute the operation through getPgClient() or getDrizzleClient()
with transaction-level serialization, such as a table lock or capacity-table
advisory lock, and preserve the existing logging and BuilderCapacityEvent return
behavior.
- Around line 80-88: Document the ascending-by-created_at input precondition on
the exported workersAt function, explicitly stating that callers must provide
sorted events; leave its implementation and reconstructHourlyCapacity behavior
unchanged.
- Around line 338-356: Update the query used by the builder capacity calculation
to select id from both baseline and window_events, then add id as the descending
tiebreaker after created_at ASC in the outer ORDER BY. Preserve the existing
baseline ordering and workersAt processing.
- Around line 175-217: Add AbortSignal.timeout to both builder fetch calls in
the capacity request flow: the runners request and the /ok health check. Use the
existing catch-based degraded fallback when either request exceeds the timeout,
while preserving the current response handling and error logging.
- Around line 121-153: Update reconstructHourlyCapacity and its response types
so hourly waiting is not returned as a misleading constant: either populate
waitingByHour from historical data in getAdminBuilderCapacity, or remove the
waiting field from BuilderCapacityHourPoint and all hourly responses if it is
not an API contract. Ensure the admin chart’s existing workers, used, and free
values remain unchanged.
In `@supabase/migrations/20260806202503_builder_capacity_events.sql`:
- Around line 14-20: Remove the redundant idx_build_requests_started_at index
definition from the migration. Keep idx_build_requests_run_interval with its
composite (started_at, completed_at) key and existing partial predicate
unchanged.
In `@tests/admin-stats.unit.test.ts`:
- Around line 54-61: Update the “accepts the builder capacity metric” test to
use the concurrent test variant by changing its `it` declaration to
`it.concurrent`; leave the synchronous schema-parsing assertions unchanged.
In `@tests/builder-capacity.unit.test.ts`:
- Around line 8-31: Expand the builder-capacity tests with concurrent cases
covering null completed_at values in maxConcurrentUsed, null/undefined/NaN and
valid inputs in isoFromBuilderTimestamp, and invalid or reversed ranges in
reconstructHourlyCapacity. Add isoFromBuilderTimestamp to the existing imports,
and assert the documented results for each case while preserving the current
tests.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6cc95141-0fcc-4cc5-b106-24149aa5db83
📒 Files selected for processing (15)
src/components/admin/AdminMultiLineChart.vuesrc/pages/admin/dashboard/builder.vuesrc/stores/adminDashboard.tssrc/types/supabase.types.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/public/build/capacity.tssupabase/functions/_backend/public/build/index.tssupabase/functions/_backend/public/build/start.tssupabase/functions/_backend/public/build/status.tssupabase/functions/_backend/triggers/cron_reconcile_build_status.tssupabase/functions/_backend/utils/builder_capacity.tssupabase/functions/_backend/utils/supabase.types.tssupabase/migrations/20260806202503_builder_capacity_events.sqltests/admin-stats.unit.test.tstests/builder-capacity.unit.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Rename the capacity migration after main's latest timestamp, drop the redundant index, type the capacity endpoint context, bound builder fetches, poll live capacity, and clear the knip unused export. Co-authored-by: Cursor <cursoragent@cursor.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_6685c1ed-3f2c-4128-9a38-93ae33e3f076) |
CI / review follow-up (AI generated)
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_47900be6-c216-4ca9-aad3-09591b3bc284) |
|



Summary (AI generated)
builder_capacity_events(+/− worker pool size over time) and persistbuild_requests.started_at/completed_atadmin_statscategorybuilder_capacity: live available/running from builder runners, hourly free/used reconstructed from capacity events + build intervalsMotivation (AI generated)
Need to see current free vs busy builders and historical hourly utilization without cron snapshots — event log of worker count plus existing build start/end is enough to reconstruct the series.
Business Impact (AI generated)
Faster ops visibility into builder saturation and queue pressure, so we can scale MacInCloud runners before customers wait.
Test Plan (AI generated)
bun test:unitincludestests/builder-capacity.unit.test.tsand admin_stats schema acceptancebun run supabase:db:resetapplies20260806202503_builder_capacity_events.sql/admin/dashboard/builder/as platform admin — see Available / Running / Online / Waiting / Offline cardsBUILDER_URLunreachable, cards show builder unreachable and chart still uses stored events/logsGenerated with AI
Made with Cursor
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
New Features
Tests