Repository navigation
Description
Summary
Today a provider failure gets one automatic retry per turn (turn.rs, PROVIDER_TIMEOUT_RETRIES = 1), fired immediately, and only when the error text contains timeout or 429 (is_transient_provider_error). There is no backoff, Retry-After is never read, and 5xx or empty completions are not retried. Unattended callers (mission, serve, ACP, cron) then stop and wait for a manual resume. The one-retry design (#58) made sense while resume was the backstop; it is thin for unattended use.
Measured (develop @ 438ad0d vs nca 0.5.5; mock server fails the first N chat requests, then succeeds; Retry-After: 1 is sent)
- 429 x1: tole OK (retry fires after 0.02 s); nca OK (waits 1.0 s = Retry-After)
- 429 x2: tole FAIL rc 4; nca OK (two waits of about 1 s)
- 429 x3: tole FAIL rc 4; nca OK
- 503 x1: tole FAIL rc 4, no retry at all; nca OK (1.2 s)
- 503 x2: tole FAIL; nca OK (1.05 s, 2.1 s)
- 503 x3: tole FAIL; nca OK (1.05 s, 2.1 s, 4.2 s)
- empty completion once (stream): tole FAIL rc 4
malformed response: empty stream (no content, no tool calls); nca retries and succeeds - empty completion, non-stream: tole exits rc 0 with empty text while stream mode fails. The two modes disagree.
The single 429 retry lands 20 ms later, so against a real rate limiter it will usually be rejected again.
Dependency
Reading Retry-After needs the response headers, which are dropped today together with the error body (see the provider-error-body issue: #474). The retry work should land after, or together with, that fix.
Proposal
Bounded retry for the transient classes: 429, 5xx, connect/timeout, empty completion, stream cut before any output.
- Up to 3 retries, exponential backoff 1/2/4 s with jitter; honor
Retry-After(seconds form) capped at 30 s. nca uses 4 attempts and the same 30 s cap. - 4xx (auth, model, invalid request) stays fail-loud.
Constraints
- Sleeps must be cancel-aware (slice on the
CancelToken, as the ACP permission wait does). A--timeoutor Esc must not wait out a 30 s sleep. - Sleeps count against
--max-minutes/--timeout. - Every retry decision is written durably BEFORE it fires (existing contract, replay-visible).
ProviderErroris a public String newtype: carry the retry hint without breaking embedders (message-encodedretry-after=N, or an additive trait method).- Order versus provider failover chain — reserve provider for mission resilience #209 failover is an owner decision. Suggested: exhaust retries on the primary, then fail over to the reserve.
- Empty completion needs a decision first: the non-stream path returns
Finalwith empty text (rc 0,openai.rs:482-487) while the stream path errors withmalformed response: empty stream(openai.rs:621-625); say which side moves. Alsois_failover_errortreatsmalformed...as fail-loud (failover.rs:64), so a retried empty completion that keeps failing would not fail over: the order above does not cover it unless that classification changes.
Acceptance
- Mock-server E2E for each row above, including
Retry-Afterhonored and a durable record per retry. - Cancel during a backoff sleep returns promptly.
- Stream / non-stream parity for empty completions.
- Docs.
Found by
Competitor research 2026-11-02 (nca retry_delay / MAX_PROVIDER_ATTEMPTS; fx retries until success with visible waits), measured live against develop @ 438ad0d.
Activity
fix(core): classify provider http-status errors by code, not by subst…
feat(provider): interruptible in-flight calls via a cancel-aware comp…