Repository navigation
fix(provider): retry attempts that outlive the backoff budget - #114
Merged
Merged
Conversation
The attempt ledger measured its 30 s budget from the first send, so any attempt that failed after more than 30 s could never be retried. The header deadline is 300 s (reqwest arms read_timeout at send and resets it only on a body read), so a gateway that accepted a request and never answered failed after five minutes with "timed out waiting for response headers" on attempt 1 and was never resent, losing the whole run. Charge only granted backoff sleeps to the budget. Each attempt is already bounded by its own connect/header/read deadlines. Name the deadline in the header-timeout message like the connect and body variants do. Regression: exchange_retries_a_header_timeout_longer_than_the_budget fails on the previous ledger and passes now; ledger_charges_only_granted_backoff_ to_the_budget and stalled_headers_transport_error_names_the_deadline cover the ledger arithmetic and the rendered message.
lg2m
added a commit
that referenced
this pull request
Sep 22, 2026
… (RR5) (#118) Two gaps in the pre-stream retry policy ended real runs that a short wait would have saved. Anthropic answers overloaded_error with HTTP 529, which is not one of http's named statuses and so was never in is_retryable_status: five audited runs "gave up after 8 attempts" on it. And a Retry-After above max_delay was clamped to 8 s, so the retry went out before the server said it would accept one and earned the same rejection again. 529 is retryable. Retry-After is a floor: parsed in delta-seconds and HTTP-date form (httpdate, already in the lock through hyper), never jittered down, and slept in full above the exponential cap up to 60 s. The ledger charges a server-directed wait at the exponential rate, so honouring the server cannot by itself exhaust the 30 s budget that bounds QQ's own guessing. Compatible with #114, which stopped charging attempt wall time. Tests: HTTP-date past and future, 529, the 60 s cap, ledger charging; the Retry-After exchange test no longer relies on max_delay clamping. Both provider profiles 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.
Problem
A run on
litellm/us.anthropic.claude-fable-5-1(124 model turns, ~305k tokens of context) failed with:exactly 300 s after its last tool call, on attempt 1, with no retry. All six
provider_transportfailures in the reporting session store share this signature (the four older ones rendered aserror sending requestbefore #106).Two things combined:
read_timeoutwhen the request is sent and resets it only on a body read, soREAD_TIMEOUT(300 s) also bounds the wait for response headers. A gateway that accepts a request and never answers fails after five minutes.AttemptLedgermeasured its 30 s budget as wall time since the first send. After a 300 s stall,elapsedwas ten times the budget, sonext_delayreturnedNoneand the exchange gave up. Any attempt that failed after >30 s was therefore unretryable — precisely the failure mode retries exist for.Change
AttemptLedgercharges only the backoff it grants (slept) to the budget, not attempt duration. Each attempt is already bounded by the client's connect (30 s), header (300 s), and read (300 s) deadlines, so the worst case stays bounded: at most four attempts plus ≤30 s of backoff.timed out waiting for response headers (none within 300s).docs/design/providers.mddocuments that the budget bounds backoff sleeps, and thatREAD_TIMEOUTis also the header deadline.exchange.rs:next_delaynow takes&mut self(guard becomesmut).No wire, schema, or configuration change. Default policy values are unchanged.
Verification
exchange_retries_a_header_timeout_longer_than_the_budget— loopback server stalls the first connection past the budget, then serves 200. Fails on the previous ledger (verified by temporarily restoring the wall-clock check), passes now; stable over 5 reruns.ledger_charges_only_granted_backoff_to_the_budget— budget arithmetic with deterministic jitter.stalled_headers_transport_error_names_the_deadline— rendered message.cargo fmt --all -- --check✅cargo clippy --workspace --all-targets --all-features -- -D warnings✅cargo test --workspace✅ (one unrelated flaky observation:headless::tests::turn_budget_cancels_before_a_silent_over_budget_turn_can_hangfailed once under full-workspace load on a 1 s wall-clock bound, passed 3/3 in isolation and in the other full run)cargo test -p qq-provider --no-default-features --features test-support✅ (166 + 17)Performance impact
None on the hot path: the ledger is touched only on failure. The successful-first-attempt path is unchanged.
Tracking
Linear issue not yet linked — the Linear connection needed reauthorization when this was opened. Will link once available.