Repository navigation
fix(queue): charge the review budget when a review lease is claimed - #1736
Conversation
Production after #1710 admitted ~215 organic items/hour and charged each one at admission, but only ~111/hour ever started a review: the rest were closed before the dispatch-time live check, superseded while still dispatching, coalesced, or deduped. The charged organic rate sat at or above the 220/hour budget, the global balance stayed at the -burst floor, and every scheduled hot/normal offer was shed. Meter executions instead of admissions. Every new claim generation of a review lease (a workflow run that actually starts) debits one global token in the same synchronous turn that grants the lease; same-attempt claim retries take the idempotent early return and are not charged again. Organic admission, superseding revisions, and completion/reconciliation requeues no longer debit; their next claim does. Publications and acknowledgement-only finalizers are never charged. Scheduled admission still debits at admission, where it is gated, and marks the new item reviewBudgetPrepaid so its first claim is not charged a second time, including after an organic event coalesces into it or supersedes it before claim. Later claims of the same item are charged like organic ones. Organic is always admitted, scheduled spends only positive balance, the debt floor stays -burst, throttle feedback still pauses scheduled admission, and the hot cap and lane buckets are unchanged. The new item field is additive; the base ignores and preserves it on rollback. Extend scripts/proof-scheduled-budget.mjs with a production_2026_10_01 scenario (closed-before-dispatch items, supersede of dispatching owners), per-hour claimed executions, a variant-neutral reconciliation proof, and an upgrade/rollback proof against the #1710 accounting.
Runs scripts/proof-scheduled-budget.mjs on the clean head 3febf5e against main cac974b (#1710) in workerd/SQLite. In the production_2026_10_01 scenario (~215 new organic items/hour, ~110/hour executed) the base sheds every scheduled offer with the balance at -24, while the head admits 98-115 scheduled reviews/hour and runs 214-225 executions/hour (rolling max 236 of 244). The #1710 scenarios, throttle pause, reconciliation exactly-once and persisted upgrade/rollback are recorded alongside. Marks the #1710 proof as historical.
…charge-at-dispatch
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 3:50 AM ET / 07:50 UTC. ClawSweeper reviewWhat this changesThe review queue charges organic work when a workflow claims its lease, preserves scheduled prepayment, and updates accounting documentation, tests, and runtime proof. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main still charges organic admissions that never execute. The focused implementation and matching runtime proof support keeping it open, with no actionable introduced defects found. Priority: P2 Review scores
Verification
How this fits togetherClawSweeper’s durable review queue receives webhook events and scheduled backfill candidates, then dispatches review workflows. Its shared budget determines how much scheduled work can run alongside organic reviews. flowchart TD
A[Webhook events] --> C[Durable review queue]
B[Scheduled candidates] --> D[Positive budget check]
D -->|Admit and prepay| C
C --> E[Live check and dispatch]
E --> F[Workflow claims lease]
F --> G[Consume prepayment or debit budget]
G --> H[Review and completion]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Keep execution-based accounting within the existing budget and throttle controls, with the documented deployment transients and rollout monitoring. Do we have a high-confidence way to reproduce the issue? Yes: current-main source charges organic admission before the live dispatch check, and the recorded baseline workerd scenario demonstrates scheduled starvation. This read-only review did not independently execute that scenario. Is this the best way to solve the issue? Yes: charging new claim generations uses the existing execution boundary, while scheduled prepayment preserves admission gating without a second debit. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2f777941de92. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Summary
After #1710 deployed (220/hour, burst 24), scheduled backfill still got almost nothing. The queue charged every organic item when it was admitted, at about 210–223/hour, but only about 111/hour of those ever started a review. The rest closed at the dispatch-time live check, were superseded while dispatching, or were coalesced or deduped. Charged organic work sat at the 220/hour budget, the global balance stayed at the −24 floor, and scheduled offers were shed. The 2-hour rollout record is #1710 (comment).
This makes the budget meter executed reviews: a token is debited when a workflow run claims a review lease. "220/hour" then means 220 executed reviews, which is what the GitHub-quota rationale in
dashboard/wrangler.tomlassumes.Change
/claimcharges. Every new claim generation of a review lease (a workflow run that actually starts) debits one global token, in the same synchronous turn that grants the lease (chargeClaimedReviewExecutionSync). Same-attempt claim retries take the idempotent early return and are not charged again.reviewBudgetPrepaidso its first claim is not charged twice. That holds even after an organic event coalesces into it or supersedes it before claim.-burst; GitHub throttle feedback still pauses scheduled admission; the hot cap and lane buckets are unchanged.docs/limits.mdanddocs/scheduler.mddescribe the new accounting, and a changelog fragment is included.Behavior proof
Committed in
docs/proof/scheduled-budget-claim-charging/(README andresult.json), usingscripts/proof-scheduled-budget.mjs. It runs the realExactReviewQueuein workerd with SQLite:/enqueue, alarm (the dispatch-time live check and dispatch),/claim,/complete,/reconcile,/stats, and persisted reopen across base → head → base. Base iscac974b3e1(main with #1710); head is3febf5e662with a clean runtime tree. Receipt SHA-256 isd6e20c45aacee6efa1711e6461b337841102b100eac74acd10c535956f87f39b.Production-shaped scenario
production_2026_10_01(~215 organic items/hour, about half closed before dispatch). Each cell is organic admissions · organic executions · scheduled admissions (hot + normal) · total executions:Results:
The README also covers these, all passing:
Limits: synthetic GitHub fixture and seeded load; no production state, GitHub writes or inference.
Validation
fc5a2f4443:pnpm run buildandcheck:staticpass, and the focused queue policy, runtime, proof-harness and scheduled-capacity suites pass 296/296.pnpm run checkgate runs in CI on this head.OpenClaw Bay
Not affected. No public field is added or removed.
scheduled_feedvalues change only because scheduled reviews now actually run.Risks / rollback
throttle_retry, 403/429 on the target_app pool, and coverage.Review
Codex
/review(autoreview, branch mode againstorigin/main, P0–P1 threshold): clean on headfc5a2f4443, "patch is correct" (0.88). It found claim-time charging, scheduled prepayment and retry handling consistent with the documented contract and the proof.