Skip to content

fix(core): classify provider http-status errors by code, not by substring - #486

Merged
ajianaz merged 1 commit into
developfrom
fix/retry-classify-http-status
Nov 3, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/retry-classify-http-status

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

What

is_transient_provider_error now classifies provider errors that start with http 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 says resulted in 142900 tokens, a 422 saying invalid timeout value or a 401 saying token timeout would 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_error already parses the code and is not touched.

Changes

Testing

  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets -- -D warnings passes
  • cargo test --workspace passes (895 passed, 0 failed)
  • cora review --staged: no issues found
  • New test is RED against the old function (http status: 400 ... 142900 tokens classified 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

  • Branch name follows convention (fix/)
  • Branch is from develop
  • Commit message follows Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR

…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
@github-actions

github-actions Bot commented Nov 2, 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 f536524 into develop Nov 3, 2026
16 checks passed
@ajianaz
ajianaz deleted the fix/retry-classify-http-status branch November 3, 2026 01:46
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]>
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.

1 participant