Skip to content

feat(grading): stop the grading queue at the plan's quota limit - #129

Merged
kamui merged 1 commit into
mainfrom
t3code/issue-30-regrade-quota-stop
Oct 12, 2026
Merged

kamui merged 1 commit into
mainfrom
t3code/issue-30-regrade-quota-stop

Conversation

@kamui

@kamui kamui commented Oct 12, 2026

Copy link
Copy Markdown
Owner

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.py now 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 of review_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 uncaught AttributeError.
  • 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 over quotaStopPercent (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 ends quota-stopped with exit 4.
  • bench/tools/regrade_queues.sh: logs a quota stop in driver.log and 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

  • The meter code is its own module so that regrade.py does not import the review queue. An authorization pins the runner's files, and importing review_queue.py would have made every review-queue edit block grading until a new authorization.
  • A reading is reused for 300 s, not the review queue's 3600 s. Several Opus workers can move a five-hour window from under 95% to the limit within an hour.
  • An unreadable meter stops the queue resumably; it is not ignored.
  • A failure or an exhausted cap that follows a quota stop decides the run's state, so a session that hits the real limit while the queue settles is not reported as a clean stop.
  • A cap that cannot fund the next batch now stops as budget-stopped before 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 main against a fake provider and for an unreadable sign-in file, and are byte-identical. A saved grading authorization pins the old regrade.py, so it needs a new version before it runs with this controller, as for any controller change. No queue is running on main'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 on main on this host and passes in CI.
  • One live Claude meter read through the grading path returned both usage windows (before the code moved into its own module; the move is covered by the fake-provider comparison). The Codex meter path is not run live.
  • Reviewed by Codex GPT-6.1 Sol (high): four findings, all fixed with a test each.

Part of #30

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 kamui left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kamui
kamui merged commit 914a5f5 into main Oct 12, 2026
4 checks passed
@kamui
kamui deleted the t3code/issue-30-regrade-quota-stop branch October 12, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant