Repository navigation
feat(quota): When an agent hits quota or a spend limit, Stage 2 misreports the stop as an empty o... - #474
Merged
thomashan merged 17 commits intoDec 2, 2026
Conversation
Description:
When an agent hits quota or a spend limit, Stage 2 misreports the stop as an empty or invalid plan instead of a quota cause, and Stages 2, 3, and 4 halt immediately instead of stepping down the runner's configured model fallback ladder while persisting a per-model cooldown marker.
Goal:
Classify Stage 2 planner quota stops and automatically step down intra-ladder models on quota exits in Stages 2, 3, and 4, persisting per-model cooldown markers and halting cleanly at the checkpoint only when the entire ladder is exhausted. (1) In apps/sandbox-executor/src/sandbox_executor/runners/spec.py, add `quota_fallback_ladder: tuple[str, ...] = ()` to `RunnerSpec`; declare `("gemini-4-neon", "gemini-4-argon", "gemini-4-hydrogen", "gemini-3.8-flash")` on `SPEC` in runners/antigravity.py and `("claude-fable-5-2", "claude-opus-5-5", "claude-sonnet-4-6", "claude-haiku-4-5")` on `SPEC` in runners/claude.py without altering `model_capabilities`, `RUNNER_CAPABILITIES`, `DEFAULT_MODELS`, or `holon models`. (2) In apps/sandbox-executor/src/sandbox_executor/model_tiers.py, add `fallback_ladder(runner)` and `next_fallback_model(runner, current_model, *, is_available=None)` reading `RunnerSpec.quota_fallback_ladder` after normalising `current_model` with `normalise_model_and_effort`, returning the next available rung or `None` when none remains while keeping `tier_ladder`, `next_tier`, and `start_tier` unchanged. (3) In apps/sandbox-executor/src/sandbox_executor/preflight_cooldown.py, extract `_read_marker_at` and add model-scoped cooldown helpers (`model_marker_path`, `record_model_cooldown`, `read_active_model_cooldown`, `clear_model_cooldown`) stored as `<provider>--<model>.json` (normalising model aliases) without changing provider-level `marker_path` or `record_cooldown`; `active_cooldown_result` checks provider cooldown then model cooldown, and `sync_cooldown_for_result` clears model cooldown on `ok`. (4) In apps/sandbox-executor/src/sandbox_executor/quota_park.py, add `PLAN_STAGE = "plan"`, `park_plan`, and `review_quota_stop` (shared with `park_review`) while keeping `quota_park.py` free of `flow`, `cli`, and `entrypoint` imports. (5) Add apps/sandbox-executor/src/sandbox_executor/quota_step_down.py (new), importing only standard library, `model_tiers`, `preflight_cooldown`, and `quota_park`, providing `step_down_for_quota` to record the exhausted model's cooldown, skip any ladder model already in active model cooldown, advance `context.model`, log the exhausted runner/model, reset hint, and replacement model, and return a step-down record dict (or `None` when exhausted). (6) In apps/sandbox-executor/src/sandbox_executor/entrypoint/planner.py, classify failed non-usable planner turns with `rendered_quota_cause` before `_api_error_of` so quota and monthly spend-limit exits fail via `_fail_plan_attempt` with `"the planner agent exited with code <n> (<cause>)"` while keeping 400/401 API errors, budget breaches, and usable plans unchanged. (7) In apps/sandbox-executor/src/sandbox_executor/flow/stages/plan.py, wrap `dispatch_planner` inside `PlanStage.produce()` with intra-ladder step-down on `read_quota_stop(failure.error)` (updating `context.model`, recomputing `preferred_suffix`, refreshing `existing_plans`, recording `model_step_downs` in the stage payload when non-empty), and call `park_plan` when the ladder is exhausted, keeping `dispatch_planner()` single-attempt for direct callers. (8) In apps/sandbox-executor/src/sandbox_executor/flow/stages/execute.py, inside `ExecuteStage.run()` within its 430-line budget, step down on a failed stage result whose `summary_row` carries a quota stop, preserve any `partial_head` via `resume_partial`, reset `ExecuteState` keeping `start_time`, retry `_run_steps()`, record `model_step_downs` when non-empty, and call `park_execution` only when the ladder is exhausted. (9) In apps/sandbox-executor/src/sandbox_executor/flow/stages/review.py, inside `_run_review_stage_body()` within its 350-line budget, when the loop fails without `is_dirty`, `MISSING_REF`, `loop_res.get("error")`, or `budget_breach` and `review_quota_stop(reviewers)` finds a quota-failed reviewer matching `context.agent` with iterations remaining, step down `context.model` and re-run `_run_engine_review_loop(context, github=github)`, recording `model_step_downs` when non-empty, and call `park_review` only when the ladder is exhausted; resolver-turn classification in the review-loop container entrypoint is outside this slice. (10) Document Stage 2 quota classification, model-scoped cooldowns, and intra-ladder step-down in docs/budgets.md. (11) Add hermetic tests in apps/sandbox-executor/tests/test_quota_step_down.py (new), apps/sandbox-executor/tests/test_planner_quota.py (new), and apps/sandbox-executor/tests/flow/stages/test_plan_quota_step_down.py (new), and extend apps/sandbox-executor/tests/test_quota_park.py, apps/sandbox-executor/tests/test_preflight_cooldown.py, apps/sandbox-executor/tests/test_runner_specs.py, apps/sandbox-executor/tests/flow/stages/test_execute_steps.py, and apps/sandbox-executor/tests/flow/stages/test_review.py without touching tests/test_planner.py or tests/test_review_loop.py. Never modify holon-config/hygiene/module_budgets.json and keep every module within its existing budget. Never reference harness-specific directories or task-tracker ids in code, tests or documents. Code is self-explaining: no docstrings and no comments except '# why:' comments that record a reason the code cannot show.
Generated by Holon Intent Agent at 2026-12-01T13:00:33Z
…-intra-ladder-step-down/P-1796130057-CLA-CO5.5/_
thomashan
commented
Dec 1, 2026
thomashan
left a comment
Collaborator
Author
There was a problem hiding this comment.
✅ Ensemble Consensus Review — APPROVED (3/3)
Reviewed quota-intra-ladder-step-down at ce400bc6 against main: 0 critical, 0 important and 0 nit findings; CI passing; mergeability UNMEASURED.
Role reviews:
| Role (activated) | Verdict | Review |
|---|---|---|
| Engineering | PASS | Step-down loops in plan, execute and review are bounded by the ladder, park only on exhaustion, and stay within module budgets. |
| Testing | PASS | New hermetic tests cover each stage's step-down, exhaustion park, skipped cooldown rungs, non-quota paths and import boundaries; targeted suites pass. |
| Documentation | PASS | docs/budgets.md documents planner quota classification, ladders, model cooldown files and TTLs, consistent with the code constants. |
Verified:
- Stage 2 retries on the next rung and never adopts the salvage branch —
apps/sandbox-executor/tests/flow/stages/test_plan_quota_step_down.py - Stage 3 re-dispatches on the next rung with the partial head and parks on the last rung —
apps/sandbox-executor/tests/flow/stages/test_execute_steps.py - Stage 4 steps down only when the review can be retried —
apps/sandbox-executor/tests/flow/stages/test_review.py - Planner quota and spend-limit exits are classified ahead of API errors without changing budget-breach or usable-plan outcomes —
apps/sandbox-executor/tests/test_planner_quota.py - Model cooldowns share one file across aliases and block only their own model —
apps/sandbox-executor/tests/test_preflight_cooldown.py - quota_step_down imports only the standard library and its three neighbours —
apps/sandbox-executor/tests/test_quota_step_down.py - Module budgets and the self-explaining check pass without budget config changes —
scripts/check_module_budgets.py - Ladder exhaustion parks the stage with step-down records —
apps/sandbox-executor/tests/flow/stages/test_execute_steps.py - Plan retry adopts only the new model's branch, never the salvage branch —
apps/sandbox-executor/tests/flow/stages/test_plan_quota_step_down.py - quota_step_down imports only stdlib and its three neighbours —
apps/sandbox-executor/tests/test_quota_step_down.py - Planner quota exits are classified ahead of API errors without breaking usable plans —
apps/sandbox-executor/tests/test_planner_quota.py - Execute and review stage modules stay within their line budgets —
apps/sandbox-executor/src/sandbox_executor/flow/stages/execute.py - Full sandbox-executor suite passes in default order (11265 passed) —
apps/sandbox-executor/tests - Every reviewer uses context.model, so a review step-down moves the whole ensemble —
apps/sandbox-executor/src/sandbox_executor/flow/review/ensemble.py - quota_step_down imports only stdlib and its three neighbour modules —
apps/sandbox-executor/tests/test_quota_step_down.py - Salvage branch of a quota-stopped planner attempt is never adopted —
apps/sandbox-executor/tests/flow/stages/test_plan_quota_step_down.py - Review step-down is suppressed on dirty, missing ref, loop error, budget breach and spent iterations —
apps/sandbox-executor/tests/flow/stages/test_review.py - Module budgets unchanged and respected —
scripts/check_module_budgets.py
Checks: Mergeability UNMEASURED · CI 16/16 passed, 0 failing, 0 pending (source: ci_head)
Covers head ce400bc; change fingerprint pf2:28e88a0eac7b; CI at that commit: 16 of 16 checks passed.
🗳️ Ensemble Review Breakdown
- Reviewer 1 (
claude-agent / claude-opus-5-5):APPROVED(critical: 0, important: 0, nit: 0) - Reviewer 2 (
claude-agent / claude-opus-5-5):APPROVED(critical: 0, important: 0, nit: 0) - Reviewer 3 (
claude-agent / claude-opus-5-5):APPROVED(critical: 0, important: 0, nit: 0) - Ensemble Consensus Verdict:
APPROVED
Reviewed by claude-agent (3-Agent Ensemble) · Model claude-opus-5-5
Stage 5 calibration will be added to this PR before merge. Merging remains with the human maintainer.
Action-Origin: pr_review Review-Iteration: 1
thomashan
deleted the
I-1796130017-quota-intra-ladder-step-down/P-1796130057-CLA-CO5.5/E-1796130374-CLA-CO5.5/_
branch
December 2, 2026 22:47
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.
Summary
When an agent hits quota or a spend limit, Stage 2 misreports the stop as an empty or invalid plan instead of a quota cause, and Stages 2, 3, and 4 halt immediately instead of stepping down the runner's configured model fallback ladder while persisting a per-model cooldown marker.
Goal:
Classify Stage 2 planner quota stops and automatically step down intra-ladder models on quota exits in Stages 2, 3, and 4, persisting per-model cooldown markers and halting cleanly at the checkpoint only when the entire ladder is exhausted. (1) In apps/sandbox-executor/src/sandbox_executor/runners/spec.py, add
quota_fallback_ladder: tuple[str, ...] = ()toRunnerSpec; declare("gemini-4-neon", "gemini-4-argon", "gemini-4-hydrogen", "gemini-3.8-flash")onSPECin runners/antigravity.py and("claude-fable-5-2", "claude-opus-5-5", "claude-sonnet-4-6", "claude-haiku-4-5")onSPECin runners/claude.py without alteringmodel_capabilities,RUNNER_CAPABILITIES,DEFAULT_MODELS, orholon models. (2) In apps/sandbox-executor/src/sandbox_executor/model_tiers.py, addfallback_ladder(runner)andnext_fallback_model(runner, current_model, *, is_available=None)readingRunnerSpec.quota_fallback_ladderafter normalisingcurrent_modelwithnormalise_model_and_effort, returning the next available rung orNonewhen none remains while keepingtier_ladder,next_tier, andstart_tierunchanged. (3) In apps/sandbox-executor/src/sandbox_executor/preflight_cooldown.py, extract_read_marker_atand add model-scoped cooldown helpers (model_marker_path,record_model_cooldown,read_active_model_cooldown,clear_model_cooldown) stored as<provider>--<model>.json(normalising model aliases) without changing provider-levelmarker_pathorrecord_cooldown;active_cooldown_resultchecks provider cooldown then model cooldown, andsync_cooldown_for_resultclears model cooldown onok. (4) In apps/sandbox-executor/src/sandbox_executor/quota_park.py, addPLAN_STAGE = "plan",park_plan, andreview_quota_stop(shared withpark_review) while keepingquota_park.pyfree offlow,cli, andentrypointimports. (5) Add apps/sandbox-executor/src/sandbox_executor/quota_step_down.py (new), importing only standard library,model_tiers,preflight_cooldown, andquota_park, providingstep_down_for_quotato record the exhausted model's cooldown, skip any ladder model already in active model cooldown, advancecontext.model, log the exhausted runner/model, reset hint, and replacement model, and return a step-down record dict (orNonewhen exhausted). (6) In apps/sandbox-executor/src/sandbox_executor/entrypoint/planner.py, classify failed non-usable planner turns withrendered_quota_causebefore_api_error_ofso quota and monthly spend-limit exits fail via_fail_plan_attemptwith"the planner agent exited with code <n> (<cause>)"while keeping 400/401 API errors, budget breaches, and usable plans unchanged. (7) In apps/sandbox-executor/src/sandbox_executor/flow/stages/plan.py, wrapdispatch_plannerinsidePlanStage.produce()with intra-ladder step-down onread_quota_stop(failure.error)(updatingcontext.model, recomputingpreferred_suffix, refreshingexisting_plans, recordingmodel_step_downsin the stage payload when non-empty), and callpark_planwhen the ladder is exhausted, keepingdispatch_planner()single-attempt for direct callers. (8) In apps/sandbox-executor/src/sandbox_executor/flow/stages/execute.py, insideExecuteStage.run()within its 430-line budget, step down on a failed stage result whosesummary_rowcarries a quota stop, preserve anypartial_headviaresume_partial, resetExecuteStatekeepingstart_time, retry_run_steps(), recordmodel_step_downswhen non-empty, and callpark_executiononly when the ladder is exhausted. (9) In apps/sandbox-executor/src/sandbox_executor/flow/stages/review.py, inside_run_review_stage_body()within its 350-line budget, when the loop fails withoutis_dirty,MISSING_REF,loop_res.get("error"), orbudget_breachandreview_quota_stop(reviewers)finds a quota-failed reviewer matchingcontext.agentwith iterations remaining, step downcontext.modeland re-run_run_engine_review_loop(context, github=github), recordingmodel_step_downswhen non-empty, and callpark_reviewonly when the ladder is exhausted; resolver-turn classification in the review-loop container entrypoint is outside this slice. (10) Document Stage 2 quota classification, model-scoped cooldowns, and intra-ladder step-down in docs/budgets.md. (11) Add hermetic tests in apps/sandbox-executor/tests/test_quota_step_down.py (new), apps/sandbox-executor/tests/test_planner_quota.py (new), and apps/sandbox-executor/tests/flow/stages/test_plan_quota_step_down.py (new), and extend apps/sandbox-executor/tests/test_quota_park.py, apps/sandbox-executor/tests/test_preflight_cooldown.py, apps/sandbox-executor/tests/test_runner_specs.py, apps/sandbox-executor/tests/flow/stages/test_execute_steps.py, and apps/sandbox-executor/tests/flow/stages/test_review.py without touching tests/test_planner.py or tests/test_review_loop.py. Never modify holon-config/hygiene/module_budgets.json and keep every module within its existing budget. Never reference harness-specific directories or task-tracker ids in code, tests or documents. Code is self-explaining: no docstrings and no comments except '# why:' comments that record a reason the code cannot show.Key Changes
References
None
Plan & Validation Metadata
P-1796130057-CLA-CO5.532.20claude-agentclaude-opus-5-5