Repository navigation
Description
Summary
The provider's HTTP error body never reaches the operator or the model. complete() has a dedicated non-2xx branch (openai.rs, HTTP status FIRST (cora full-scan #46): status + scrubbed 200-char body snippet), but the ureq agent is built without .http_status_as_error(false) (OpenAiProvider::build_agent), and in ureq 3 the default is true: a 4xx/5xx comes back as Err(Error::StatusCode(code)), which carries only the code. The .send_json(...).map_err(...)? line returns first, so for 4xx/5xx the snippet branch is never reached.
The same defect class was already fixed in the two sibling clients: gitea (#233: "Error::StatusCode carries ONLY the code — the body is unreachable from it") and systemone (#328). The provider client, which is the one the whole product depends on, still has it. #119 (closed) added the branch; no test drives it: the http status: N — snippet strings in the turn.rs / failover.rs / turn_loop.rs tests are hand-written, and the one mock that serves a 500 (config_apply.rs) sends an empty body.
Live repro (develop @ 438ad0d, mock provider)
The mock answers HTTP 400 with {"error":{"message":"This model's maximum context length is 131072 tokens ...","code":"context_length_exceeded"}}.
- tole:
tole: provider failed: http status: 400 (resume with: ...), rc 4. Body not shown. - nca 0.5.5 prints the provider's message verbatim.
Same for 429 / 503: only http status: 429.
Impact
- Real provider failure modes become opaque: quota exhausted, rate limit detail, invalid model, context overflow, billing. For the fleet's own provider these are the common failures.
Retry-Afteris unreachable too (headers live on the response that ureq discards), which blocks the backoff work (provider: bounded retry with backoff + Retry-After for 429/5xx/empty completions (today: one immediate retry, 429/timeout only) #478) and the context-overflow handling (compaction: the fleet gateway reports no context window, so compaction is silently off; no overflow recovery #481).- The error-class matching in
failover.rs/turn.rsrelies on thehttp status: Nprefix. That prefix is produced today by ureq'sDisplay, so classification works; keep the exact prefix when the body is added.
Proposal
Scope the change to the chat-completions request only. Do not flip build_agent globally: fetch_model_ids_with_timeout and fetch_context_window call .call() and rely on Err for non-2xx; with the flag off they would feed an HTML/JSON error body into read_json and report a misleading parse error. Either use a dedicated agent (or per-request config) for complete(), or add explicit status checks to those two helpers in the same PR.
Result string stays http status: <code> <reason> — <scrubbed snippet>; scrub the API key; cap the snippet. Surface Retry-After when present.
Classification (found in review). is_transient_provider_error (turn.rs:951) does a substring match for timeout / 429 over the whole leading error, so appending the body snippet changes retry behaviour. Compiling the real functions from 438ad0d: a 400 whose body says resulted in 142900 tokens, a 422 whose body says invalid timeout value and a 401 whose body says token timeout all become transient (and get retried); today, with the body dropped, none of them do. is_failover_error is not affected (it parses the code after the http status: prefix). Fix in the same PR: for a message that starts with http status: , classify on the parsed code only (429); keep the substring rule for everything else. With that rule the four existing assertions in transient_tests still hold and the three cases above stay non-transient (503 retry is #478's scope).
Acceptance
- Mock-server tests drive the real branch: 400 with a JSON body, 429 with
Retry-After, 503 with an HTML body, an unreadable body; each asserts the exact error text, the scrubbed key, the cap, and thatis_failover_error/is_transient_provider_errorclassify a message exactly as they classify the same message WITHOUT the body (see Classification). -
fetch_model_ids*/fetch_context_windowbehavior unchanged for 401/404 (explicit tests). - Live check: the 400 repro above shows the provider message in
tole's error line.
Found by
Live measurement against develop @ 438ad0d while comparing error handling with nca 0.5.5; root cause confirmed in the ureq 3.4.2 sources (config.rs: http_status_as_error defaults to true) and the gitea/systemone fixes.
Activity
[-]provider: HTTP error body is discarded (ureq default) \u2014 4xx/5xx detail never reaches the operator[/-][+]provider: HTTP error body is discarded (ureq default) — 4xx/5xx detail never reaches the operator[/+]fix(core): classify provider http-status errors by code, not by subst…
feat(provider): bounded cancel-aware retry with backoff and Retry-Aft…