Skip to content

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 into
mainfrom
I-1796130017-quota-intra-ladder-step-down/P-1796130057-CLA-CO5.5/E-1796130374-CLA-CO5.5/_
Dec 2, 2026
Merged

thomashan merged 17 commits into
mainfrom
I-1796130017-quota-intra-ladder-step-down/P-1796130057-CLA-CO5.5/E-1796130374-CLA-CO5.5/_

Conversation

@thomashan

Copy link
Copy Markdown
Collaborator

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, ...] = () 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.

Key Changes

  • Implement 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.

References

None

Plan & Validation Metadata

  • Plan ID: P-1796130057-CLA-CO5.5
  • Expected Value (EV): 32.20
  • Agent: claude-agent
  • Model: claude-opus-5-5

Holon Intent Agent and others added 14 commits December 1, 2026 13:00
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 thomashan left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

@thomashan
thomashan added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit c176d4a Dec 2, 2026
20 of 22 checks passed
@thomashan
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
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