Skip to content

fix(queue): charge the review budget when a review lease is claimed - #1736

Merged
steipete merged 3 commits into
mainfrom
fix/scheduled-budget-charge-at-dispatch
Oct 1, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/scheduled-budget-charge-at-dispatch

Conversation

@steipete

@steipete steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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.toml assumes.

Change

  • /claim charges. 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.
  • Organic admission no longer charges. That includes superseding revisions, coalesces, dedupes and completion/reconciliation requeues; their next claim pays. Publications and acknowledgement-only finalizers are never charged.
  • Scheduled admission still debits when admitted, where it is gated, and marks the item reviewBudgetPrepaid so its first claim is not charged twice. That holds even after an organic event coalesces into it or supersedes it before claim.
  • Preserved from perf(queue): charge organic executions and let scheduled backfill use its review budget #1710: organic is always admitted; scheduled spends only positive balance; the debt floor is -burst; GitHub throttle feedback still pauses scheduled admission; the hot cap and lane buckets are unchanged.
  • Storage: the new item field is additive, and the base build ignores and preserves it on rollback. docs/limits.md and docs/scheduler.md describe the new accounting, and a changelog fragment is included.

Behavior proof

Committed in docs/proof/scheduled-budget-claim-charging/ (README and result.json), using scripts/proof-scheduled-budget.mjs. It runs the real ExactReviewQueue in workerd with SQLite: /enqueue, alarm (the dispatch-time live check and dispatch), /claim, /complete, /reconcile, /stats, and persisted reopen across base → head → base. Base is cac974b3e1 (main with #1710); head is 3febf5e662 with a clean runtime tree. Receipt SHA-256 is d6e20c45aacee6efa1711e6461b337841102b100eac74acd10c535956f87f39b.

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:

Variant Hour 1 Hour 2 Hour 3
base 215 · 103 · 23+13 · 139 238 · 127 · 0+0 · 127 240 · 107 · 0+0 · 107
head 215 · 103 · 35+80 · 218 238 · 127 · 30+68 · 225 240 · 107 · 30+77 · 214

Results:

  • Base: every scheduled offer is shed after the first burst, and the balance sits at −24, matching production.
  • Head: 98–115 scheduled reviews/hour, total executions 214–225/hour, and the busiest rolling hour is 236 (≤ 220 + 24).
  • Both: organic admission is 100%.

The README also covers these, all passing:

Limits: synthetic GitHub fixture and seeded load; no production state, GitHub writes or inference.

Validation

  • On the merged head fc5a2f4443: pnpm run build and check:static pass, and the focused queue policy, runtime, proof-harness and scheduled-capacity suites pass 296/296.
  • The full pnpm run check gate runs in CI on this head.

OpenClaw Bay

Not affected. No public field is added or removed. scheduled_feed values change only because scheduled reviews now actually run.

Risks / rollback

  • One timing difference: right after a large organic spike, a scheduled offer can use balance that existed before the spike's claims land. In the proof, the busiest rolling hour is lower on the head (437 vs 466 for a 400-item spike).
  • Rollback is a revert. The base build reads and preserves the new field, and admission-time charging resumes.
  • Rollout watch stays as recorded on perf(queue): charge organic executions and let scheduled backfill use its review budget #1710: throttle_retry, 403/429 on the target_app pool, and coverage.

Review

Codex /review (autoreview, branch mode against origin/main, P0–P1 threshold): clean on head fc5a2f4443, "patch is correct" (0.88). It found claim-time charging, scheduled prepayment and retry handling consistent with the documented contract and the proof.

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.
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 3:50 AM ET / 07:50 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: fc5a2f4443a85ab012730f2ed26ae5dc708e64c1

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused patch with strong source-matched runtime and persistence evidence, and no blocking correctness findings.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): Matching source hashes connect the changed queue claim owner to recorded workerd/SQLite enqueue, dispatch, claim, completion, reconciliation, and throttle scenarios, showing restored scheduled throughput and exactly-once charging. Six persisted restart cases verify compatible records and document accounting transients; live GitHub quota and inference remain outside the controlled proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): Matching source hashes connect the changed queue claim owner to recorded workerd/SQLite enqueue, dispatch, claim, completion, reconciliation, and throttle scenarios, showing restored scheduled throughput and exactly-once charging. Six persisted restart cases verify compatible records and document accounting transients; live GitHub quota and inference remain outside the controlled proof.
Evidence reviewed 8 items Introduced accounting change: The pinned main-to-head delta removes organic admission and successor-requeue debits, adds scheduled prepayment, and charges new claim generations. Same-attempt retries return before charging; publications and terminal acknowledgement finalizers are excluded.
Still missing on main: The fetched main implementation explicitly debits new organic items at admission and has no scheduled prepayment marker at creation. The latest supplied release commit does not contain this queue file, so it does not establish a shipped replacement for this change.
Runtime proof identity: Receipt SHA-256 d6e20c45aacee6efa1711e6461b337841102b100eac74acd10c535956f87f39b and the harness, queue, configuration, and workflow hashes match the checked-out files. Comparing the tested source commit 3febf5e with the reviewed head produces no differences in these runtime inputs.
Findings None None.
Security None None.

How this fits together

ClawSweeper’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]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Queue and regression delta queue production +31/-24; tests +215/-36 The runtime change stays focused while coverage exercises claim retries, reruns, successors, and scheduled prepayment.
Persisted compatibility 6 restart cases across 2 rate profiles The proof checks the additive stored marker through upgrade and rollback.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This repairs scheduled review starvation caused by charging organic work that never executes.
  • add merge-risk: 🚨 automation: Changing budget charging directly affects scheduled workflow volume and GitHub demand; recorded runtime proof covers the retained, previously approved budget and throttle controls.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Matching source hashes connect the changed queue claim owner to recorded workerd/SQLite enqueue, dispatch, claim, completion, reconciliation, and throttle scenarios, showing restored scheduled throughput and exactly-once charging. Six persisted restart cases verify compatible records and document accounting transients; live GitHub quota and inference remain outside the controlled proof.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Matching source hashes connect the changed queue claim owner to recorded workerd/SQLite enqueue, dispatch, claim, completion, reconciliation, and throttle scenarios, showing restored scheduled throughput and exactly-once charging. Six persisted restart cases verify compatible records and document accounting transients; live GitHub quota and inference remain outside the controlled proof.

Label justifications:

  • P2: This repairs scheduled review starvation caused by charging organic work that never executes.
  • merge-risk: 🚨 automation: Changing budget charging directly affects scheduled workflow volume and GitHub demand; recorded runtime proof covers the retained, previously approved budget and throttle controls.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Matching source hashes connect the changed queue claim owner to recorded workerd/SQLite enqueue, dispatch, claim, completion, reconciliation, and throttle scenarios, showing restored scheduled throughput and exactly-once charging. Six persisted restart cases verify compatible records and document accounting transients; live GitHub quota and inference remain outside the controlled proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Matching source hashes connect the changed queue claim owner to recorded workerd/SQLite enqueue, dispatch, claim, completion, reconciliation, and throttle scenarios, showing restored scheduled throughput and exactly-once charging. Six persisted restart cases verify compatible records and document accounting transients; live GitHub quota and inference remain outside the controlled proof.

Evidence

What I checked:

  • Introduced accounting change: The pinned main-to-head delta removes organic admission and successor-requeue debits, adds scheduled prepayment, and charges new claim generations. Same-attempt retries return before charging; publications and terminal acknowledgement finalizers are excluded. (dashboard/exact-review-queue.ts:2824, fc5a2f4443a8)
  • Still missing on main: The fetched main implementation explicitly debits new organic items at admission and has no scheduled prepayment marker at creation. The latest supplied release commit does not contain this queue file, so it does not establish a shipped replacement for this change. (dashboard/exact-review-queue.ts:2491, 2f777941de92)
  • Runtime proof identity: Receipt SHA-256 d6e20c45aacee6efa1711e6461b337841102b100eac74acd10c535956f87f39b and the harness, queue, configuration, and workflow hashes match the checked-out files. Comparing the tested source commit 3febf5e with the reviewed head produces no differences in these runtime inputs. (docs/proof/scheduled-budget-claim-charging/README.md:35, fc5a2f4443a8)
  • Production-path behavior proof: The inspected harness runs the actual queue in workerd/SQLite with a native loopback GitHub fixture through enqueue, live dispatch checks, claim, completion, reconciliation, and stats. Recorded production-shaped executions increase from 139/127/107 to 218/225/214 per hour, with 98–115 scheduled admissions per hour and a 236-execution rolling maximum. Reconciliation records two executions costing two tokens without replay debits; throttle cooldown admits zero scheduled items and all 31 organic arrivals. Workload, clock, and GitHub responses are synthetic; live quota and inference are outside this proof. (scripts/proof-scheduled-budget.mjs:339, fc5a2f4443a8)
  • Existing-state compatibility: Six persisted base-to-head-to-base restart cases cover positive, exhausted, and populated lane state at 60/6 and 220/24. Records survive, upgrade does not mint credit, and rollback preserves the unknown prepayment field. The proof explicitly documents temporary double charging of base-admitted work on upgrade and uncharged head-admitted work on rollback; these affect pacing rather than record compatibility. (docs/proof/scheduled-budget-claim-charging/README.md:133, fc5a2f4443a8)
  • Related merged work and operating scope: GitHub verifies perf(queue): charge organic executions and let scheduled backfill use its review budget #1710 merged as cac974b. Its supplied discussion records approval of the 220/hour target, 24-item burst, hot-lane rate, cadence, and rollout watch. This PR retains those settings and the existing unconditional-organic/debt-floor contract while correcting the charging point; the earlier PR does not supersede this correction. (cac974b3e1da)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 7849c6a into main Oct 1, 2026
23 checks passed
@steipete
steipete deleted the fix/scheduled-budget-charge-at-dispatch branch October 1, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant