Repository navigation
Description
Summary
When a Claude Max subscription hits its monthly usage cap, the SUB-003 auto-switch mechanism does not activate — even when alternative subscriptions are registered and have remaining capacity. Agents assigned to the exhausted subscription keep failing with 429s on every scheduled task until the cap resets, with no automatic remediation.
Component
Backend / Subscription Management (SUB-003)
Priority
P2 — feature impaired, manual workaround available (reassign agents to a different subscription via Settings)
Error
WARNING: Claude Code error detected: type=rate_limit,
message=You're out of extra usage · resets Apr 23, 3pm (America/New_York)
ERROR: [Headless Task] Rate limit: Subscription usage limit:
You're out of extra usage · resets Apr 23, 3pm (America/New_York).
To resolve: (1) wait for the usage reset, (2) set an ANTHROPIC_API_KEY
on this agent for pay-per-use billing, or (3) assign a different
subscription token in Settings → Subscriptions.
Agent container returns 429 Too Many Requests to backend on POST /api/task.
Observed Behavior
- Subscription A hits monthly usage cap
- All agents on Subscription A begin failing in ~2s on every execution
- Two other subscriptions (B and C) are registered with remaining capacity
- No auto-switch fires; agents remain stuck on exhausted Subscription A
- No
subscription_rate_limit_eventsactivity visible — backend appears to not detect the 429s returned from agent containers as subscription rate-limit events
Expected Behavior
SUB-003 should detect repeated type=rate_limit failures from an agent's task endpoint, recognize the "out of extra usage" pattern as a usage-cap exhaustion, and either:
- Automatically reassign the agent to another registered subscription with capacity, or
- Surface the situation prominently (operator queue / notification) so it can be acted on immediately
Root Cause (Hypothesis)
The 429 response travels from the agent container back to the backend, not from the Anthropic API directly to the backend:
Scheduler → backend (/api/internal/execute-task)
→ agent (/api/task)
→ Claude Code subprocess → [rate_limit detected inside agent]
← agent returns 429 ←
← backend marks execution failed ←
SUB-003's rate-limit event tracking likely monitors Anthropic API errors at the point where the backend calls the Claude API directly. In the subscription-auth flow, Claude is invoked inside the agent container via CLAUDE_CODE_OAUTH_TOKEN. The backend never sees a direct Anthropic 429 — it only sees the agent container's 429, which may not be parsed to extract the subscription rate-limit signal and write to subscription_rate_limit_events.
Additionally, "out of extra usage" (monthly hard cap) is semantically distinct from "too many requests" (transient throttle). Even if the event IS detected, the auto-switch logic may only be designed to handle transient throttling, not hard-cap exhaustion.
Reproduction Steps
- Register two or more Claude Max subscriptions (Subscription A and Subscription B)
- Assign several agents to Subscription A
- Run heavy workloads on those agents until Subscription A exhausts its monthly usage cap
- Observe: all agents on Subscription A begin failing immediately on every execution
- Observe: SUB-003 does not reassign agents to Subscription B
- Check
subscription_rate_limit_eventstable — likely empty or not updated for these failures
Suggested Fix
Two complementary changes:
1. Detect agent-container 429s as subscription rate-limit events
In the backend's task execution handler, when an agent returns 429, parse the response body for type=rate_limit and write to subscription_rate_limit_events with the subscription ID of the agent's current subscription.
2. Distinguish usage exhaustion from transient throttling
The "out of extra usage · resets [date]" message is a hard cap, not a transient throttle. For this case, auto-switch should trigger immediately (after 1–2 failures) rather than waiting for the repeated-429 threshold used for transient throttles. A transient throttle may self-resolve; a monthly cap will not.
# Rough sketch — in task execution error handler:
if response.status_code == 429:
body = response.json()
if body.get("type") == "rate_limit":
message = body.get("message", "")
is_hard_cap = "out of extra usage" in message or "resets" in message
record_subscription_rate_limit_event(
subscription_id=agent.subscription_id,
error_type="usage_exhaustion" if is_hard_cap else "transient",
)
if is_hard_cap:
trigger_auto_switch(agent) # don't wait for thresholdEnvironment
- Trinity version:
0027b8b - OS: Ubuntu 22.04
Related
- SUB-003 feature: subscription auto-switch on rate limits
subscription_rate_limit_eventstablesrc/backend/services/task_execution_service.py— where agent 429s are handled- Related feature: SUB-002 subscription assignment
Activity
vybe commentedon Apr 21, 2026
Validation — symptoms real, hypothesis partially wrong
Confirmed the bug via code walkthrough. The observed behavior (empty
subscription_rate_limit_events, no auto-switch) is accurate, but the root-cause hypothesis needs correction.What the issue gets wrong
This path is already wired:
"out of extra usage"and"resets ") and raisesHTTPException(status_code=429)—docker/base-image/agent_server/services/claude_code.py:716-729(_is_rate_limit_message), used at lines 659-665 and 1179-1186.src/backend/services/task_execution_service.py:530-537.So the suggested fix sketch (parse response body for
type=rate_limit) is unnecessary — that detection already works.Actual root cause (two real bugs)
1. Events aren't recorded when auto-switch is disabled.
services/subscription_auto_switch.py:36-38early-returns on theauto_switch_subscriptionssetting beforerecord_rate_limit_event()runs. Setting defaults to"false":This explains the empty
subscription_rate_limit_eventstable exactly: the feature is off, so nothing gets recorded — not even for visibility or operator notifications.2. No hard-cap fast path.
handle_rate_limit_errorrequires 2+ events in 2 hours before switching (subscription_auto_switch.py:52-57)."Out of extra usage · resets [date]"is a monthly hard cap — it will not self-resolve. Current code treats it like a transient throttle. Issue's suggestion to fast-path this case is correct.Bonus issue (not in report)
select_best_alternative_subscription(db/subscriptions.py:572-606) only excludes alternatives that have been rate-limited in the last 2h — it doesn't consultget_subscription_usage(SUB-004). A switch could land on another near-exhausted subscription.Refined scope for the fix
record_rate_limit_event()before theenabledchecksubscription_auto_switch.py:36out of extra usage,resets) and fast-path switch after 1 eventsubscription_auto_switch.py:52subscription_auto_switch.pyget_subscription_usagewhen picking alternativedb/subscriptions.py:572Proceeding with this scope.
vybe commentedon Apr 21, 2026
Closing as invalid — feature flag was disabled
After the code walkthrough in the prior comment, confirmed with the reporter that the
auto_switch_subscriptionsplatform setting was off. With the flag disabled,handle_rate_limit_errorreturns atservices/subscription_auto_switch.py:36-38before any event is recorded or switch is attempted — which exactly matches the symptoms (emptysubscription_rate_limit_events, no auto-switch, agents stuck on exhausted subscription).Enabling the setting via Settings → Subscriptions (or the admin endpoint
PUT /api/subscriptions/auto-switch) restores the intended behavior.The two observations that could still be valid product improvements (record events for visibility even when flag is off; fast-path hard-cap exhaustion without waiting for 2 events) are intentional scope for a future refinement if desired — not a bug. Closing this issue as
invalid.test(a2a): compare the parsed host, not a substring (ent#885)
refactor(a2a): every inbound A2A call needs a credential — drop the k…