Repository navigation
feat(grading): stop the grading queue at the plan's quota limit - #129
Merged
Merged
Conversation
regrade.py had a dollar cap but could not see the subscription plan's usage windows, so a five-hour or seven-day limit failed every session in flight and each failure was kept and charged. The coordinator now reads the meters of the queue's client before the preflight, before it prepares a batch and again before it writes the batch's reservation, and reuses a reading for up to five minutes. At or over quotaStopPercent (optional in the authorization, default 95), with a Claude sign-in about to expire, or with unreadable meters, it launches nothing more, lets running sessions settle and map, and ends in the state quota-stopped with exit 4. status.json keeps the reason and the run's last reading. The next run resumes once the meters allow, and dispatches a batch that was already prepared from its existing workspace. A cap that cannot fund the next batch stops the queue as budget-stopped before any reading or preflight. A failure or an exhausted cap that follows a quota stop decides the run's state and exit code. The meter reader moves from review_queue.py to subscription_meters.py, which imports only the standard library, so a grading authorization pins that one file and not the review runner. The review queue keeps its messages, stop reasons and exit codes. A meter response of the wrong shape is now an unreadable reading in both queues, where it raised an uncaught AttributeError. regrade_queues.sh notes a quota stop in driver.log and passes exit 4 on. The regrade plan script pins subscription_meters.py.
kamui
commented
Oct 12, 2026
kamui
left a comment
Owner
Author
There was a problem hiding this comment.
Approved (advisory) — no findings.
Ambiguities
- A failure while the quota-stopped queue settles — (a) Every later failure overrides other stops; (b) Failure replaces quota-stopped; the first non-quota stop keeps precedence. Applied: The second reading follows the PR tradeoffs and existing stop ordering. Failed attempts remain recorded and rechecked on resume.
Reviewed 3027b0d. All 8 changed files and the affected launch, settlement and restart paths reviewed. No actionable defect found. Publishing as COMMENT under kamui with gating withheld.
Review details
Intent: Stop grading launches at the subscription quota while retaining running sessions and resumable prepared work.
Issue fit: Meets this PR's controller scope and supports #30. Grading, authorization, audit and dataset publication remain separate work in that issue.
Reviewed: 3027b0d against merge-base 068e8a6.
Checks:
- At the reviewed head, 63 regrade tests and 7 focused review-queue meter tests passed.
- CI grading logs report 918 tests, 18 skipped and no failures at the reviewed head.
- Live provider meter calls were not repeated; coverage uses fake-provider tests and code traces.
- Independent checks confirmed draining within the cap and prepared-workspace reuse. If cap exhaustion wins first, budget-stopped retains precedence; failed receipts remain recorded and gate new launches on resume.
This was referenced Oct 12, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The grading queue has a dollar cap but cannot see the subscription plan's usage windows. When a five-hour or seven-day limit is hit, every session in flight fails like any other failure: the queue stops with up to one failed attempt per worker, each kept and charged. The regrade of the last-push cohort is about 190 Opus sessions on a plan, so a limit is expected and has to be an orderly, resumable stop.
regrade.pynow reads the plan's meters the way the review queue does and stops launching before the limit.Scope
bench/tools/subscription_meters.py(new):meters,used,read_meters,sign_in_expiring,quota_stop, moved out ofreview_queue.py. Standard library only.bench/tools/review_queue.py: uses the module. Its behaviour is unchanged, except that a wrong-shaped meter response is now a blocked launch and no longer an uncaughtAttributeError.bench/tools/regrade.py: reads the meters before the preflight, before preparing a batch and again before writing its reservation, reusing a reading for up to 300 s. At or overquotaStopPercent(optional authorization field, default 95), with a Claude sign-in about to expire, or with unreadable meters, it launches nothing more, lets running sessions settle and map, and endsquota-stoppedwith exit 4.bench/tools/regrade_queues.sh: logs a quota stop indriver.logand passes exit 4 on.docs/research/cohort-rebuild-2026-10-05/regrade/plan.py: pins the new module for new authorizations.docs/grading-readiness.md: the quota section.Tradeoffs
regrade.pydoes not import the review queue. An authorization pins the runner's files, and importingreview_queue.pywould have made every review-queue edit block grading until a new authorization.budget-stoppedbefore any reading or preflight. Before, the preflight ran first.Blast Radius
Both queues' launch paths. The review queue's readings, messages and exit codes were compared with
mainagainst a fake provider and for an unreadable sign-in file, and are byte-identical. A saved grading authorization pins the oldregrade.py, so it needs a new version before it runs with this controller, as for any controller change. No queue is running onmain's tools; the review-code run in flight uses its own freeze commit.Verification
python3 -m unittest discover -s bench/tools -p "test_regrade.py": 63 pass.python3 -m unittest discover -s bench/tools -p "test_review_queue.py": 62 pass.bun run test:bench: 918 tests, one failure,test_codex_grading.test_catalog_preserves_native_model_instructions, which also fails onmainon this host and passes in CI.Part of #30