fix: a request the upstream refuses no longer fails over or trips breakers - #38
Merged
Merged
Conversation
…akers `check_status` reported every non-2xx other than 429/401/403 as `ProviderError`, and failover treated `ProviderError` as retryable. A caller's bad request (400) therefore walked every route of the model, and each hop was recorded as a breaker failure: one caller's malformed requests could shut every route of a model for everyone. An upstream status is now kept in `ProviderHttpError`, and `is_upstream_failure` draws the line the desktop gateway draws. 5xx, 408, 429, timeouts, broken connections, unreadable bodies and a refused gateway credential (401/403) move on to the next route and count against the route. Any other 4xx goes straight back to the caller and counts as the upstream working. Streams apply the same rule when their outcome is recorded. Timeouts are reported as `ProviderTimeout`. With the status structured, the relearn and probe classifiers no longer read it back out of the message text. The probe also treats a 5xx as inconclusive: an outage is about the moment, not the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
check_statuswrapped every upstream non-2xx except 429/401/403 asProviderError, andis_retryabletreatedProviderErroras retryable. A client's bad request (400) walked every route of the model, and every hop recorded a breaker failure, so one caller could open the breakers of all routes of a model.ProviderHttpErrorandProviderTimeoutwere never constructed in production.check_statusreturnsProviderHttpError { status, .. }; reqwest timeouts becomeProviderTimeout(send and whole-body read).routing::is_upstream_failuredecides failover and breaker accounting:UpstreamAuthError: the gateway's own credential for that route was refused, which another route may not share);record_outcome(from the recorded error tag and status). A tool-inspection cut (PolicyBlocked) no longer counts against the route either, matching the buffered path.protocol_relearnno longer scrapes the status out of the message text. The probe'sis_inconclusivedoes the same, and treats 5xx/408 as inconclusive.transport.rsandrouting.rsrewritten to match.A 5xx now reaches the caller with the upstream's status rather than a blanket 502.
Test plan
gateway_failover.rs:a_refused_request_goes_back_without_trying_another_route: two routes that both answer 400; the caller gets the 400 and its reason; only one upstream is hit;refused_requests_do_not_open_the_breaker: four 400s (buffered and streamed) withmin_samples = 2; the fifth request still reaches the upstream;server_errors_open_the_breaker: two 500s open it, and the third request does not reach the upstream.--ignored --test-threads=1)--all-targets -D warningsand--lib, workspace unit tests🤖 Generated with Claude Code