OpenAI transport drops the 429 `Retry-After` header, so the retry policy can never honour it
Summary
On the OpenAI-compatible transport — which is the path our managed backend uses — a 429's Retry-After header is discarded before the retry layer ever sees it. ProviderError.retry_after_ms is hardcoded None. The Anthropic transport populates it correctly from the same header, so this is an asymmetry between two providers rather than a design decision.
Split out of #6413, where the schedule length is being fixed separately (PR pending). That fix stands on its own; this one is the reason a server-supplied wait can never be honoured on our main path.
Evidence
The retry layer is ready to use it. RetryPolicy::backoff_for_error returns computed.max(clamped_retry_after), bounded by max_retry_after_ms, and retry_after_hint prefers the structured field, falling back to parsing the message text:
// tinyagents-harness/src/retry/mod.rs:328-339
TinyAgentsError::Provider(provider_error) => {
if let Some(ms) = provider_error.retry_after_ms { return Some(Duration::from_millis(ms)); }
provider_error.message.as_str()
}
Anthropic populates it — tinyinference-llm/src/providers/anthropic/mod.rs:388:
retry_after_ms: tinyinference_core::parse_retry_after_ms(retry_after),
OpenAI cannot. provider_error() takes (message, status, code, raw) — no headers parameter at all — and hardcodes the field (providers/openai/transport.rs:1611):
retry_after_ms: None,
And the header is gone one line before the error is built (transport.rs:1499-1503):
let status = response.status();
if !status.is_success() {
let text = response.text().await.unwrap_or_default(); // <- consumes the response; headers lost
let error = self.parse_error_body(status.as_u16(), &text);
return Err(Error::Provider(Box::new(error)));
}
response.headers() is available on the line above. The fix is to read Retry-After there and thread it into parse_error_body / provider_error.
The text fallback does not rescue it in practice: the managed 429 reads Upstream rate limit exceeded for model '...'. Please retry shortly. — no number, so parse_retry_after_ms returns None.
Why it matters
A 429 usually tells you how long to wait. Honouring that beats any backoff curve we invent, and it is the one input we cannot guess. Today every 429 on the managed path, and on OpenRouter/OpenAI-direct BYOK, falls back to a fixed curve.
Open question — needs an owner outside the fleet
Does the managed backend actually forward the upstream's Retry-After on a 429? I did not verify this and deliberately did not run a throttled request against production to find out. If it does not forward the header, this fix buys nothing for the managed path specifically (it still fixes OpenAI-direct and OpenRouter BYOK, which do send it).
Whoever owns opencompany#2391 (managed default model rate-limited / substituted) can settle this cheaply — it is a question about the backend's 429 response, not about this code.
Where the change belongs
vendor/tinyagents/vendor/tinyinference owns provider wire behaviour, so this is an upstream PR in that repo plus a gitlink bump here — two pieces of work, not one. Filed rather than built for that reason.
Acceptance criteria
- [ ] A 429 response carrying
Retry-Afteryields a populatedProviderError.retry_after_mson the OpenAI transport. - [ ] Asserted at the transport boundary (a 429 with the header in, a populated field out). Asserting it in the host would only re-test
backoff_for_error's arithmetic, which already works. - [ ] Both header forms handled: delay-seconds (
Retry-After: 30) and an HTTP-date. - [ ] The existing
max_retry_after_msclamp still applies, so a hostile or mistaken header cannot park a run.
Related
- #6413 — schedule length (separate, lands first)
- opencompany#2391 — managed default model rate-limited
- #6412 is the opposite failure in the same family (MCP 401 retried with no ceiling,
vendor/tinymcp) — a different crate and loop; nothing here loosens a ceiling.
OpenAI transport drops the Retry-After header on 429 responses, so server-supplied wait times are never honoured; Anthropic transport handles it correctly. Affects managed backend, OpenRouter BYOK, and OpenAI-direct BYOK. Retry layer is ready to use the field but recieves None.
Labelled priority: p1.
The fix lives in the vendored crate rather than here: parse_error_body / provider_error are in tinyinference-llm (vendor/tinyagents/vendor/tinyinference). Opened tinyhumansai/tinyinference#28, which reads Retry-After before text() consumes the response and sets retry_after_ms through the same parse_retry_after_ms the Anthropic transport uses. Transport failures and mid-stream error events still get None, since there are no headers to read.
This issue needs a tinyagents → tinyinference pointer bump after that merges before the managed path picks it up, so leaving it open.
Resolved by tinyhumansai/tinyinference#28 (merged 9c5b411ef). It is delivered to openhuman main 7d8a4c83e: vendor/tinyagents → 8a58b7e59, whose vendor/tinyinference → c29d5118e, and GitHub compare 9c5b411ef...c29d5118e = ahead 28 / behind 0.
Evidence at the pinned c29d5118e, checked against the acceptance criteria:
- Populated field:
crates/tinyinference-llm/src/providers/openai/transport.rs:1508-1515readsRetry-Afterbeforetext()consumes the response and passes it toparse_error_body.:1625setsretry_after_ms: parse_retry_after_ms(retry_after). - Asserted in the transport crate, not the host:
crates/tinyinference-llm/src/providers/openai/test.rs:604parse_error_body_carries_retry_after_into_the_structured_error. A 429 withRetry-After: 7givesSome(7_000); with no header, and with an unparseable one, it givesNone. - Both header forms: the shared
parse_retry_after_ms(crates/tinyinference-core/src/retry_after.rs:12-25) parses delay-seconds and HTTP-dates (testsparses_delta_seconds_and_caps,parses_http_dates). - Clamp still applies: the harness retry policy keeps
max_retry_after_ms(tinyagents-harness/src/retry/mod.rs:96-98at8a58b7e59).
Not covered by this close: the separate question of whether the managed backend forwards an upstream Retry-After on a 429. That is backend behaviour, not this transport defect, and this issue already routes it to opencompany#2391.