Repository navigation
feat(reliability): retry triggering execution after SUB-003 auto-switch (#792) - #1364
Merged
Merged
Conversation
…ch (#792) When a subscription auto-switch fires mid-execution the triggering row was marked FAILED. Interactive chat retries client-side and recurring cron recovers on the next tick, but one-shot triggers (manual .../schedules/{id}/trigger, webhook, MCP trigger_agent_schedule) had no recovery. TaskExecutionService.execute_task now intercepts a returned 429/auth response pre-raise_for_status (mirroring the #678 reader-race retry, since agent_post_with_retry returns rather than raises) and, when SUB-003 reports a successful switch, re-issues the turn once with the same execution_id so the row lands SUCCESS instead of FAILED. - classify_switch_failure(): full switch surface (429 -> rate_limit; 503/401/403/402 or is_auth_failure body -> auth), not just status codes. - _extract_agent_error(): shared body->( msg, metadata) extractor, also used by the except httpx.HTTPError handler so both read the body identically. - _salvage_attempt_cost(): rolls first-attempt cost into previous_attempt_cost (#678 R2). - Dedicated subscription_switch_attempted one-shot guard (NOT retry_count, which #678 owns) that also gates the except-handler switch so a cascade never double-switches. - Retry is the readiness probe (short _SWITCH_RETRY_DELAY_S pre-delay only, no circuit-aware /health poll, no restart_result trust); retry timeout capped to the remaining original budget. Same execution_id => #1084 effect_guard dedups wired sinks. Out of scope: #1083 DISPATCH_ASYNC path and a concurrent switch-lock loser. Tests: tests/unit/test_792_subscription_retry.py (11 cases, all green). Closes #792 Co-Authored-By: Claude <[email protected]>
vybe
approved these changes
Jun 27, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Approved via /validate-pr: clean SUB-003 retry. Issue link+closing keyword ✓, no schema/config changes, security clean, named regression test (test_792_subscription_retry.py) covers the non-happy retry-after-switch path, SUB-003 stays inline-only (async #1083 bypass preserved), all 18 checks green.
This was referenced Jun 27, 2026
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
Extends SUB-003 subscription auto-switch so that when a switch fires
mid-execution, the triggering execution is retried once and lands
SUCCESSinstead of
FAILED.Today a switch mid-turn marks the row
FAILED. Three recovery patterns alreadyexist — interactive chat retries client-side (
routers/chat.py) and recurringcron recovers on the next tick — but one-shot triggers had no recovery:
POST …/schedules/{id}/triggertrigger_agent_scheduleThese produced a single dead
FAILEDexecution. This PR closes that gap.How it works
TaskExecutionService.execute_tasknow intercepts a returned 429/auth responsepre-
raise_for_status—agent_post_with_retryreturns the responserather than raising, so the interception sits adjacent to the #678 reader-race
502 block and falls through to the single shared success-parse path by
reassigning
response(no duplicated finalize logic). When SUB-003 reportsswitched=True, it re-issues the turn once with the sameexecution_id.New module helpers:
classify_switch_failure(response)— full SUB-003 surface (429→rate_limit;503/401/403/402oris_auth_failurebody→auth; elseNone), so "anyswitch-success retries" actually holds, not just status codes.
_extract_agent_error(response, fallback)— shared body→(msg, metadata)extractor, also adopted by the
except httpx.HTTPErrorhandler so both pathsread the body identically.
_salvage_attempt_cost(metadata)— rolls first-attempt cost intoprevious_attempt_cost(Async chat_with_agent: long execution silently fails with null response (reader-thread) #678 R2).Key decisions:
subscription_switch_attempted(NOTretry_count,which the Async chat_with_agent: long execution silently fails with null response (reader-thread) #678 retry owns) so the two retry reasons never suppress each other;
the same flag gates the
except-handler switch so a cascade (retry stillfailing) never double-switches.
_SWITCH_RETRY_DELAY_Spre-delayonly; no circuit-aware
/healthpoll (would poison the transport breaker oncold start) and no trust in
restart_result's string status. A still-failingretry writes
FAILED, as before.so a post-long-run 429 can't balloon wall-clock/slot time.
execution_id⇒ feat: effect-scoped idempotency keys for outbound side effects #1084effect_guarddedups wiredoutbound sinks; residual double-fire risk for arbitrary MCP tool calls is the
same the Async chat_with_agent: long execution silently fails with null response (reader-thread) #678 retry already accepts.
Out of scope / follow-ups
DISPATCH_ASYNC, default OFF) routes 429sthrough the result-callback, bypassing this sync path.
Nonefromhandle_subscription_failure)does not retry.
Testing
tests/unit/test_792_subscription_retry.py— 11 cases (incl. parametrized503/401/403/402 auth surface, #678↔#792 interplay, cascade single-switch,
bounded retry timeout). All green:
Docs
requirements.md§20 +docs/requirements/SUB-003-subscription-auto-switch.md(acceptance criteria + history)
architecture.mdservice catalog +feature-flows/task-execution-service.md/cso --diffreport committed underdocs/security-reports/— CLEAN, nofindings above the gate.
Closes #792
🤖 Generated with Claude Code