Repository navigation
feat(runtime)!: retry a turn after a transient provider fault and settle paused on exhaustion (RR4, ADR-0040) - #120
Merged
Conversation
…tle paused on exhaustion (RR4, ADR-0040) A provider fault after the provider's own retry ledger was spent ended the run as Failed, even when every turn so far was durable and the fault was the provider's moment rather than the request's. Twelve audited runs (4.5 h of completed turns) died this way on 529/503/500 and mid-stream transport loss; the operator's recovery was to re-prompt "continue" with worse context than the loop already had. Every reference harness retries the turn. The run loop now owns turn recovery (ADR-0040; the provider keeps ADR-0005's ownership of resends within one request). On ProviderUnavailable, ProviderRateLimited, or ProviderTransport, or a stream that ends after events without a terminal event, the loop commits the partial assistant turn, emits TurnRetrying, sleeps under TurnRecoveryPolicy (2 s doubling to 60 s; cancellation and the run deadline cut it short), and re-issues the turn with a continue notice after any partial text. The allowance is MAX_TURN_RETRIES (5) per turn and resets on a completed turn. Exhaustion settles RunOutcome::Paused: durable transcript, session accepts the next prompt with a notice naming the pause. Non-transient kinds still fail at once. PROTOCOL_VERSION 25 -> 26: run_turn_retrying event; paused outcome, status, and RunPause; v26 goldens and harbor traces. No store schema change; 'paused' joins every terminal-status list (two of which had also omitted 'budget_exhausted'). Client reducer warns per retry; TUI renders paused like budget_exhausted; headless maps paused to task_failed with the pause named; a paused child returns a tool error to its parent; a paused compaction step stops the fold. BREAKING: protocol bump; older clients reject the new event and outcome tags. Direct-runtime callers see the last fault as Failed with "paused after N turn retries" appended. Tests: transient_faults_retry_the_turn_and_exhaustion_pauses, the_turn_retry_allowance_resets_on_a_completed_turn, a_retry_sleep_yields_to_cancellation_and_the_deadline; session fixtures that asserted Failed for an offline provider now assert Paused and the extra sends. Replaces the_run_loop_never_resends_a_turn.
… ADR-0040 The perf fixture's faulting provider fails every stream before its first event and the gate asserted exactly one provider entry per failed run. With run-owned turn recovery the same run now sends 1 + MAX_TURN_RETRIES times and settles paused, which is the value the gate should protect: anything above it means a second retry owner above the loop. The fixture uses a 1 ms recovery policy so the benchmark measures sends, not sleeps.
lg2m
added a commit
that referenced
this pull request
Sep 22, 2026
…rotocol 27 Protocol 26 was claimed by #120 (turn recovery, ADR-0040) while #122 was open, so the effort pin moves to protocol 27. v26/ goldens are #120's; v27/ is regenerated from them plus command_set_session_effort and receipt_session_effort_set. Harbor trace fixtures bump 26 -> 27. Store schema stays 34 (main is on 33). MAX_TURN_RETRIES kept. Also picks up #126-#128 (RR6, RR7, onboarding); no overlap. Verified on the identical tree as a rebase: cargo test --workspace, fmt --check, clippy -D warnings all green.
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.
Stacked on #118 (RR5). RR4 of
docs/plans/run-reliability.md; audit finding R01. Protocol bump; independent review requested perworkflow.md§ 4 (touchessessions/).Behaviour
A provider fault after the provider's own retry ledger was spent ended the run as
Failed, even when every turn so far was durable and the fault was the provider's moment (529, 503, gateway 500, mid-stream connection loss) rather than the request's. Twelve audited runs — 4.5 h of completed turns — died this way; the operator's recovery was to re-prompt "continue" with worse context than the loop already had. Codex, OpenCode, Pi, and fx all retry the turn.Now the run loop owns turn recovery (ADR-0040; the provider keeps ADR-0005's ownership of resends within one request):
ProviderUnavailable/ProviderRateLimited/ProviderTransport, or a stream that ends after events without a terminal event: commit the partial assistant turn, emitTurnRetrying, sleep underTurnRecoveryPolicy(2 s → 60 s; cancellation and the run deadline cut it short), re-issue the turn with a continue notice after any partial text.MAX_TURN_RETRIES= 5 per turn, reset on a completed turn — a 3-hour run survives many isolated blips; a down provider pauses the run in ~2 min.RunOutcome::Paused, notFailed: transcript durable, next prompt continues with a notice naming the pause.Protocol 25 → 26
run_turn_retryingevent;pausedoutcome, status,RunPause.MAX_TURN_RETRIESlives inqq-protocolso clients render against the same bound.v26/goldens (event_run_turn_retrying,event_run_finished_paused); harbor traces bumped. No store schema change;'paused'joins every terminal-status SQL/match list (two of which had also omitted'budget_exhausted'— a latent bug, now fixed).Surfaces: client reducer warns per retry and on pause; TUI renders
pausedlikebudget_exhausted; headless mapspaused→task_failed(exit 1) with the pause named, so supervisors see no new code; a paused sub-agent returns a tool error to its parent; a paused compaction step stops the fold.Verification
transient_faults_retry_the_turn_and_exhaustion_pauses: three transient kinds × 6 sends → paused; auth fails once with no resend; mid-stream 529 ×2 then completion yieldspart0 part1 donewith the continue notice in the third request.the_turn_retry_allowance_resets_on_a_completed_turn: 9 faults across 9 turns, never a second attempt, run completes.a_retry_sleep_yields_to_cancellation_and_the_deadline(paused clock).Failedfor an offline provider now assertPausedandn + MAX_TURN_RETRIESsends;loaded_runtimeuses a 1 ms policy so the suite stays ~15 s. Replacesthe_run_loop_never_resends_a_turn.cargo test --workspace --exclude xtaskgreen (qq-core 690, qq 172, qq-tui 308, protocol 48+…); minimal provider profile green; clippy-D warningsand fmt clean.Docs
ADR-0040 accepted; ADR-0005 marked superseded in part;
architecture.md§ run loop and perf table;protocol.mdversion history, event table, outcomes;headless-contract.mdexit table; ledger and root rows.