Repository navigation
Description
Summary
Make subscription auto-switch (SUB-003) more aggressive by default: trigger on a single call failure (not 2 consecutive), broaden the trigger surface from rate-limit (429) only to any subscription/auth error, and flip the system setting default from off to on.
Context
Today's behavior in services/subscription_auto_switch.py + subscription-auto-switch.md:
- Opt-in via
auto_switch_subscriptionssetting, default"false" - Triggers only on HTTP 429 from the agent's chat endpoint
- Requires 2+ consecutive rate-limit events on the same (agent, subscription) before switching
In practice agents fail for reasons beyond 429 — expired OAuth tokens, revoked credentials, account credit-balance issues, 401/403 auth errors — and the current design leaves them stuck on a broken subscription until a human notices. The scheduler already classifies these as [AUTH_ERROR] using a well-defined indicator list (src/scheduler/service.py:677-717); the auto-switch service should hook into the same signal.
We also want auto-switch to be the default: a single failure should rotate to a healthy subscription if one is available, so agents self-heal without configuration.
Acceptance Criteria
- Threshold drops from 2 consecutive failures to 1: a single qualifying failure is enough to trigger a switch (given other preconditions hold)
- Trigger surface broadens beyond 429: any failure matching the auth-indicator list (
credit balance,unauthorized,authentication,credentials,forbidden,401,403,oauth,token expired,not authenticated) routes intohandle_rate_limit_error(rename if appropriate — e.g.handle_subscription_failure) -
auto_switch_subscriptionssystem setting default flips from"false"to"true" - Existing guards still hold: agent must have a subscription (not API key), alternative must exist, subscriptions with events in last 2h are excluded from candidate selection (prevents thrashing)
- Activity log + notification text reflect the actual trigger reason (rate limit vs auth failure) instead of hardcoded "consecutive rate-limit errors"
- All three 429 interception points are updated to also forward non-429 auth failures:
task_execution_service.py:532,chat.py:431, and the background task handler - Feature flow
docs/memory/feature-flows/subscription-auto-switch.mdupdated: preconditions, flow diagram, selection strategy, setting default - Requirements doc
docs/requirements/SUB-003-subscription-auto-switch.mdupdated to match - Smoke test added/updated in
tests/test_subscription_auto_switch.pycovering the single-failure and auth-error paths
Technical Notes
- The auth-indicator list already lives in
src/scheduler/service.py— extract into a shared helper (e.g.services/subscription_auto_switch.py::is_subscription_failure(error_message)) and reuse from both sites to keep a single source of truth - Be careful at
task_execution_service.py:532andchat.py:431: auth failures typically surface as 500/502 with the indicator text in the body, not as a specific status code — the branch currently gated onagent_status_code == 429needs widening (e.g.agent_status_code == 429 or is_subscription_failure(error_msg)) - The "2-consecutive" guard in
subscription_auto_switch.py:52is what prevented flip-flopping; with threshold=1 the only remaining safeguard isselect_best_alternative_subscriptionexcluding subs with events in the last 2h. Confirm that window is sufficient, or consider a per-agent cooldown on auto-switches themselves - Flipping the default to on is a behavior change for existing installs — mention in release notes / CHANGELOG if one exists
- Related:
subscription-credential-health.mddescribes the auth-error classification the scheduler already does; this issue extends the same signal into the auto-switch pipeline
Activity
vybe commentedon Apr 21, 2026
Deferred pending Tier 2.5 simplification (#428)
Picked this up via
/sprinton 2026-04-21, ran plan review, and decided to defer. Capturing the reasoning + a scope reframe so it's not lost when we come back.Why defer
Per
docs/planning/ORCHESTRATION_RELIABILITY_2026-04.md, current focus is Tier 2.5 — Simplification: #306 just landed (PRs #438, #439), now in a 2-week soak window before #428 (CAPACITY-CONSOLIDATE) opens. Both interception points this issue touches —task_execution_service.py:532andchat.py:431— sit inside the surface #428 is meant to collapse. The plan's additive-first principle calls out this exact pattern:This issue is P2, no active incident, and operators can manually switch. Papercut, not fire. Right time to land it is when #428 opens those files anyway.
Scope reframe for when we pick it back up
Detection for auth failures is already solved by #285 (shipped PR #322):
TaskExecutionServicehas a stderr scanner that classifies auth failures and setsTaskExecutionErrorCode.AUTHon the result (task_execution_service.py:542-544for 503s + the stderr pattern matcher). The right implementation is to consume that signal, not add a parallel substring matcher at the HTTP layer.Revised plan:
src/scheduler/service.py:778-784and:1031-1037) — those lists are log classification only, and the scheduler consolidates laterhandle_rate_limit_errorcan stay until refactor: consolidate ExecutionQueue + SlotService + BacklogService into CapacityManager #428 is restructuring the fileFindings from plan review worth preserving
Why not the substring matcher as originally specified:
"401","oauth","forbidden"appear in agent tool output (e.g. "got 403 from GitHub",/oauth/authorizeURLs in help text)Why a per-agent cooldown even with perfect detection:
Deferred as a separate follow-up (not blocking this issue):
Action
vybe commentedon Jun 15, 2026
Grooming triage: verified shipped —
src/backend/services/subscription_auto_switch.pyimplements 429 + auth-class triggers, default-on (opt-out), #441 threshold. Closing as done.