Repository navigation
fix(core): classify provider http-status errors by code, not by substring - #486
Merged
Merged
Conversation
…ring is_transient_provider_error matched "timeout"/"429" anywhere in the leading error. Once #474 appends the provider body to `http status: N ...`, a 400 mentioning "142900 tokens" or a 401 saying "token timeout" would be retried. Messages starting with `http status: ` are now classified on the parsed code only (transient iff 429), mirroring is_failover_error; all other messages keep the substring rule. 5xx stays non-transient (#478). Evidence: new test RED before the change (400 "142900 tokens" -> true), GREEN after; existing failover test unchanged; fmt, clippy -D warnings and cargo test --workspace pass; cora review --staged: no issues found. Part of #474
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
ajianaz
added a commit
that referenced
this pull request
Nov 3, 2026
… transient classification (#490) ## 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 #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". Co-authored-by: ajianaz <[email protected]>
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.
What
is_transient_provider_errornow classifies provider errors that start withhttp status:by the parsed status code only (transient iff 429). Every other message keeps the existing substring rule.Why
Part of #474. Today the provider's HTTP error body is dropped, so the message is just
http status: 400. #474 appends the body (http status: 400 Bad Request — <snippet>). With the current substring rule that would flip retry behaviour: a 400 whose body saysresulted in 142900 tokens, a 422 sayinginvalid timeout valueor a 401 sayingtoken timeoutwould be retried automatically. This PR removes the hazard first. With today's body-less messages nothing changes, so it is safe to land on its own.is_failover_erroralready parses the code and is not touched.Changes
crates/tole-core/src/turn.rs: afterfailover::leading_error, ahttp status: <code>message is transient iff<code> == 429; other messages use the oldtimeout/429substring rule. 503 and other 5xx stay non-transient (bounded retry is provider: bounded retry with backoff + Retry-After for 429/5xx/empty completions (today: one immediate retry, 429/timeout only) #478).gpt-4290, code4290, 503, plaintimeout, stream timeout, two failover compositions). The existingonly_the_last_failover_error_decides_a_retrytest is unchanged and passes.Testing
cargo fmt --all -- --checkpassescargo clippy --workspace --all-targets -- -D warningspassescargo test --workspacepasses (895 passed, 0 failed)cora review --staged: no issues foundhttp status: 400 ... 142900 tokensclassified transient), GREEN with the change. Checked by running the new test against the pre-change function body.Related Issues
Part of #474 (the body fix itself follows in a separate PR).
Checklist
fix/)develop