Repository navigation
fix(queue): charge the review budget at Codex generation start - #1738
Conversation
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 7:01 PM ET / 23:01 UTC (Revision 4). ClawSweeper reviewWhat this changesMove review-budget charging to the workflow’s startup heartbeat so claimed runs that exit during setup leave capacity available for scheduled reviews. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main still charges at claim. No actionable patch defect remains, and Peter’s recorded acceptance resolves the prior rollout blocker. Priority: P2 Review scores
Verification
How this fits togetherClawSweeper’s exact-review queue receives organic events and scheduled review requests, then leases work to GitHub Actions. Its shared budget determines how much scheduled work can run alongside organic reviews. flowchart TD
A[Organic events] --> C[Exact review queue]
B[Scheduled requests] --> C
C --> D[Workflow claims lease]
D --> E[Startup ownership check]
E --> F[Charge once or consume prepayment]
F --> G[Review generation]
F --> H[Remaining scheduled capacity]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Meter review starts once per claim generation while preserving scheduled prepayment, with the accepted rollout audit and budget monitoring. Do we have a high-confidence way to reproduce the issue? Yes: main charges every new claim before generation, and the committed real-queue comparison demonstrates starvation when claims exit during setup. This read-only review inspected that evidence without rerunning it. Is this the best way to solve the issue? Yes: using the existing startup heartbeat is a narrow accounting repair, and the runtime receipt verifies retry idempotency, prepayment, and persisted compatibility. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6e783d80e517. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Organic runs claim about 220 leases/hour, and roughly a third exit before Codex starts: live-item admission skips, or the lease is superseded during setup. Charging the review budget at claim spent the whole 220/hour allowance on organic claims, so scheduled hot intake and normal backfill stayed shed with reason scheduled_rate. A claim now records which claim generation still owes a token. The workflow's existing startup ownership check (verify_startup_authority, right before generation) sends generation_start: true on the lease heartbeat. The queue charges that generation once there. A scheduled prepayment is consumed at that point instead. Retried starts, stale leases, plain heartbeats and status heartbeats never charge. Leases claimed (and charged) under the previous Worker carry no marker, so they are not charged twice during the rollout.
02b72f8 to
69699c1
Compare
Summary
Scheduled backfill is still starved after #1736. The public budget telemetry from #1737 shows why:
scheduled_feed.token_balancesits around −3.activeis 1 of 32.scheduled_rate(89,253 since reset).Organic runs claim about 220 leases/hour, and roughly a third of them exit before Codex starts: live-item admission skips, or the lease is superseded during setup. Charging at claim spends the whole 220/hour allowance on claims, and many of those claims never run a review.
This PR moves the charge to the moment Codex generation actually starts. That is the existing startup ownership check in the review step, which the workflow already performs immediately before generation.
Change
.github/workflows/sweep.yml:verify_startup_authorityaddsgeneration_start: trueto the lease heartbeat it already sends before generation. Both review paths (ordinary and oversized) call it. Plain periodic heartbeats are unchanged.dashboard/exact-review-queue.ts:/claimno longer debits. It recordsreviewBudgetChargeGeneration(the claim generation that owes one token)./heartbeatvalidatesgeneration_start(truewith phasereview, else400 invalid_generation_start). After the lease-tuple and status-supersession checks pass, it charges once when the marker matches the live claim generation, then deletes the marker in the same synchronous write.clearExactReviewLeaseclears the marker.docs/limits.md,docs/scheduler.md, and thedashboard/wrangler.tomlrationale comment now describe generation-start charging. This is a comment-only change; no configured value changes. The perf(queue): charge organic executions and let scheduled backfill use its review budget #1710 and fix(queue): charge the review budget when a review lease is claimed #1736 proofs are marked historical. A changelog fragment is included.Behavior proof
The proof is committed in
docs/proof/scheduled-budget-generation-start/(README andresult.json). It uses the extendedscripts/proof-scheduled-budget.mjsand runs the realExactReviewQueueSQLite Durable Object in workerd with productionwrangler.tomlvalues. Both variants receive the same generation-start heartbeats.6566c6974a(origin/main at proof time).830d2c1f8b, clean runtime tree. After rebasing ontof7c8c55f33,dashboard/exact-review-queue.ts,dashboard/wrangler.toml,.github/workflows/sweep.ymland the harness are byte-identical to the proven files (same SHA-256 as the receipt).26cd16811d5b578edcf08adcd392931a515321f8a63b8c52f9d9f1d5b3ae8dda.The production scenario models about 220 organic claims/hour, with a third exiting before generation. Totals are over 3 simulated hours:
Other properties the proof holds:
claimandsuccessor_claim; the head charges atgeneration_startandsuccessor_generation_start. Retries and replays cost 0.Limits: the arrival mix, the exit-before-generation share, and latencies are synthetic but seeded. The proof uses no live inference, production state, or GitHub writes. The workflow shell is covered by the test below rather than by this harness.
Validation
pnpm run build:all,pnpm run lintandpnpm run check:staticpass.node --test test/dashboard-*.test.ts test/exact-review-*.test.ts test/sweep-workflow.test.ts: 1,323 tests, 0 failed.test/dashboard-worker-queue-policy.test.tsfail on the base and pass on the head.test/sweep-workflow.test.tscase runs the realverify_startup_authorityagainst a stubbed control plane. It covers the owned and superseded responses, asserts the exact payload, and checks that both generation paths call it.scripts/e2e/exact-review-start-authority.mjswas updated after the first CI run failed on it. It runs the real review-step shell against a loopback queue, but only on Linux, so the macOS run had skipped it. It now asserts that every startup-check attempt carriesgeneration_start: true, including retries until one is accepted, and that every periodic heartbeat after an accepted start does not. All 12 scenarios pass in a Linux container (node:24-bookworm, Node 24.21.0) on head69699c1cfd. For example,currentsends 3 requests with 1 start,retry-currentsends 503 then 200 with 2 starts, andrevoked-after-startsends 2 requests with 1 start.test/exact-review-start-authority.test.tsadditionally requires exactly one generation-start request on thecurrentpath.Rollout and rollback
Charges cannot be doubled. Leases claimed and charged before the Worker deploy carry no marker, so their generation start is free (proven above). Two one-time undercharge windows remain:
generation_start. It goes uncharged only if its claim lands after the Worker deploy. Claims normally land about a minute after dispatch, and the Worker deploys a few minutes after the merge, so this mostly affects old-workflow runs whose runner pickup is delayed. The ceiling is the review runs in flight at deploy: 80 slots, with about 14 active as of 2026-10-04 22:27 UTC.An uncharged start costs one scheduled admission token, so the worst case is a single burst of extra scheduled reviews. It is bounded by the in-flight leases, and realistically single digits. A charge is never lost permanently, and nothing is charged twice.
Maintainer decision (Peter, 2026-10-04): accept the bounded transient and land once CI and the current ClawSweeper review are green. Dispatch is not paused during the deploy.
After the merge, the rollout is:
After deploy, watch:
scheduled_feed.token_balanceshould rise off the floor.scheduled_feed.activeand the lane balances should start spending.lanes.review.shed_reasons_since_reset.scheduled_rateshould grow more slowly.OpenClaw Bay
Not affected. No public status field, value, or lifecycle stage changes.
reviewBudgetChargeGenerationis internal item state.Risks / rollback
Started Codex reviews rise toward the configured 220/hour, which is the budget's intended meter, instead of about 160/hour. Runs that exit early still cost a few GitHub requests (claim and live-item check) that the budget no longer meters. Those requests are small next to the ~30 a review makes, and the 220/hour rationale keeps more than half of the installation bucket free. Rollback is a revert; the base ignores the new field and marker.
Review
Codex
/review(autoreview, branch mode againstorigin/main, P0–P1 threshold): clean on rebased head69699c1cfd, which includes the e2e update; no accepted or actionable findings. It was also clean earlier on02b72f8a83.The ClawSweeper review of
02b72f8a83reported proof sufficient and no findings. Its remaining items are the rollout decision above.