Skip to content

provider: HTTP error body is discarded (ureq default) — 4xx/5xx detail never reaches the operator #474

Closed

Description

@ajianaz

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

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 that is_failover_error / is_transient_provider_error classify a message exactly as they classify the same message WITHOUT the body (see Classification).
  • fetch_model_ids* / fetch_context_window behavior 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

  1. added
    bug
    reliability
    on Nov 2, 2026
  2. changed the title [-]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[/+] on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreliability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions