fix(agent): stop retrying on usage_limit_reached, surface reset time - #6
Merged
Merged
Conversation
A scheduled plan/subscription usage cap (e.g. GPT-5.5 / openai-codex "usage_limit_reached", HTTP 429 with resets_in_seconds) was classified as a transient rate_limit and retried 3x with backoff — pointless, since the cap resets on a clock, not within the retry window. Context Rotation V0-A (harness-side, first slice): - Add FailoverReason.usage_limit_reached. Classify the cap as non-retryable before the 429/402 handlers, keyed on the structured error type/code (with a narrow explicit-phrase fallback). should_rotate_credential=False so the same provider's pool (shared plan) isn't rotated; should_fallback=True. - Retry loop: on usage_limit_reached, try the configured fallback chain exactly once (no fallback-loop — _try_activate_fallback advances the chain), else hard-stop and report the reset time. No backoff, no sleeps, no retry against the capped provider. - Parse numeric resets_in_seconds in extract_api_error_context. Existing transient "usage limit, try again" 429/402 behavior and bare "usage limit reached" billing classification are preserved (regression-tested). No full context rotation, no checkpoints, no auto-rotation. Default behavior otherwise unchanged. Tests: classifier (429/402 body type, prose hard-cap vs transient), reset-time extraction, and loop behavior (one attempt + no backoff, fallback-once, fallback-also-capped hard-stop). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:2933: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
✅ Fixed issues (1):
| Rule | Count |
|---|---|
invalid-assignment |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
Unchanged: 5727 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
The kanban circuit-breaker special-case mapped only failure_reason rate_limit/billing to KANBAN_RATE_LIMIT_EXIT_CODE so a scheduled quota window requeues the task without incrementing the failure counter. The new usage_limit_reached reason (a multi-hour plan cap) was missing, so a kanban task hitting a plan cap exited 1 and could trip the circuit breaker and permanently block the card — the exact case this branch exists to prevent. Add "usage_limit_reached" to the tuple. Follow-up to PR #6 review finding #1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Context Rotation V0-A (harness-side, first slice). Fixes the bug where a scheduled plan/subscription usage cap (e.g. GPT-5.5 / openai-codex
usage_limit_reached, returned as HTTP 429 withresets_in_seconds) was classified as a transientrate_limitand retried 3× with backoff — pointless, since the cap resets on a clock, not within the retry window.This does not implement full context rotation, checkpoints, fresh threads, or auto-rotation.
Behavior (per decision: fallback-then-stop)
should_rotate_credential=False, so the same provider's credential pool (shared plan) isn't rotated._try_activate_fallbackadvances the chain index).usage_limit_reached.Changes
agent/error_classifier.py— addFailoverReason.usage_limit_reached; detect the hard cap before the 429/402 handlers, keyed on the structured errortype/code(usage_limit_reached/gousagelimit) with a narrow explicit-phrase prose fallback. Returnsretryable=False,should_rotate_credential=False,should_fallback=True.agent/conversation_loop.py— dedicated handler: fallback-once-then-hard-stop, with a reset-time-aware user message andfailure_reason="usage_limit_reached"in the result. Added_format_usage_limit_message/_format_reset_deltahelpers (handle epoch and ISO-8601 reset timestamps).agent/agent_runtime_helpers.py— parse numericresets_in_seconds(andreset_in_seconds) intoreset_atinextract_api_error_context.Preserved (regression-tested)
rate_limit.billing.Tests
type=usage_limit_reached, 402 +code, prose hard-cap vs transient.extract_api_error_contextparsesresets_in_seconds.jittered_backoffasserted not called); fallback-once-then-continue; fallback-also-capped hard-stop withfailure_reason.Scope / safety
Docs-plan reference:
docs/CONTEXT_ROTATION_HARNESS_V0_PLAN.md(PR #5). No provider config, secrets/.env, or services touched. No auto-rotation. Reversible by removing the single classification branch.🤖 Generated with Claude Code