Skip to content

fix(provider): surface the HTTP error body, Retry-After and code-only transient classification - #490

Merged
ajianaz merged 2 commits into
developfrom
fix/provider-error-body
Nov 3, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/provider-error-body

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What (description of the change)

The chat-completions request now uses a dedicated agent built with http_status_as_error(false), so a 4xx/5xx arrives as a response and complete()'s existing non-2xx branch can read the body. The error line becomes http status: 400 Bad Request — <scrubbed 200-char snippet>, with (retry-after: N) inserted after the reason when the header is present. build_agent (the /models probes) is untouched, so fetch_model_ids_with_timeout and fetch_context_window keep their Err-on-non-2xx behavior, now pinned by explicit tests. is_transient_provider_error is pub(crate) so the new equivalence tests can call it. CHANGELOG entry under [Unreleased].

Why (the problem you're solving)

Closes #474. ureq 3 defaults to http_status_as_error(true), so a 4xx/5xx came back as Err(StatusCode(code)) carrying only the code: quota exhausted, rate-limit detail, invalid model, context overflow and billing failures were all invisible to the operator (http status: 400, nothing else). The same defect class was already fixed in the gitea (#233) and systemone (#328) clients.

Testing (how you verified this works)

  • RED against develop: 5 of the 6 new tests failed — the error was a bare http status: 400/429/500 with no body and no Retry-After. The 6th (fetch_* pinning) passed before and after, as intended.
  • GREEN: 6/6 http_error_tests cover a 400 JSON body (streaming and non-streaming, exact text), a 429 with Retry-After (stays transient + failover), a 503 HTML body (API key scrubbed, snippet exactly 200 chars), an unreadable body (… — <unreadable body>), the 400/422/401 body-text cases that must NOT become transient (classification equivalence with and without the body, per the issue's Classification section — the code-only rule itself already landed with fix(core): classify provider http-status errors by code, not by substring #486, so no classification code was added), and fetch_model_ids / fetch_context_window unchanged on 401/404.
  • Live check (the issue's acceptance item, run by the orchestrator against the freshly built debug binary with a mock serving the issue's exact 400 body): tole: provider failed: http status: 400 Bad Request — {"error": {"message": "This model's maximum context length is 131072 tokens. However, your messages resulted in 142900 tokens.", "code": "context_length_exceeded"}} (resume with: …), rc 4.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace --no-fail-fast (907 passed / 0 failed), cargo test -p tole-core --no-default-features (339 passed / 0 failed), cargo build -p tole-cli --no-default-features: all pass. One flaky timing test (perf_threshold::single_turn_tool_chain_under_budget) failed once under parallel load and passed alone and in the clean full re-run; it was not changed.
  • cora review --staged at commit time: "No issues found".

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 36b89e6 into develop Nov 3, 2026
16 checks passed
@ajianaz
ajianaz deleted the fix/provider-error-body branch November 3, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant