Repository navigation
Fail over on errors at the start of a stream; pause upstreams by the reason they give - #239
Merged
Merged
Conversation
fylorn
force-pushed
the
feat/stream-start-failover
branch
from
September 29, 2026 15:28
d8ca9ff to
77d577c
Compare
…streams by the reason they give A streamed answer is now held until its first content arrives (at most failover.stream_start_wait_secs, 1 MiB). An error the upstream reports in the stream before that point (Anthropic overloaded_error, Codex response.failed, Bedrock throttlingException, Chat/Gemini error chunks) moves the request to the next candidate, the same as an error status. The bytes read while waiting are handed on unchanged. Failures are classified by what the upstream says (new `failure` module): - 401/403 (credentials), 402 (balance) and 404 (no such model) now fail over; 400/422 only when the body names a balance, a used-up quota or an unavailable model. Other 4xx still go straight to the client. - An insufficient balance, a used-up quota (until the reset time from the body, the quota headers or the GLM 429) and a rate limit with Retry-After set the upstream aside at once for that long. Failures without a reason keep the consecutive-failure breaker, with the pause doubling on each re-open up to a ceiling and resetting on success. - The last candidate's own 4xx reaches the client as the upstream wrote it. All durations are configurable in a new `failover` section (defaults are not written to the file), exposed as Overview.failover (CONTROL_API_VERSION 29) and documented in docs/config*.md. New message codes: config.failover_range, gw.upstream.stream_opening_error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gateway holds a stream until its first content; a mock that stops right after message_start never reaches the client at all, which is not what the cancellation check is about. Real upstreams send the thinking block's start right away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn
force-pushed
the
feat/stream-start-failover
branch
from
September 29, 2026 15:51
77d577c to
e9cafcc
Compare
Merged
fylorn
added a commit
that referenced
this pull request
Sep 29, 2026
- Bump the workspace version to 0.56.0 - release-notes/0.56.0.md Includes #237 (conversation affinity, route held per turn), #238 (local token counts, resend without sealed reasoning) and #239 (fail over at the start of a stream, pause upstreams by the reason they give). The control-plane protocol goes from 28 to 30; the request store schema (22) is unchanged. groups[].session_affinity is removed. 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.
What
Errors at the start of a stream fail over. A streamed answer is held until its first content arrives (at most
failover.stream_start_wait_secs, default 15 s, and 1 MiB). An error reported in the stream before that point moves the request to the next candidate, just like an error status would:event: error(overloaded_error→ 529,rate_limit_error→ 429, …);message_start/pingare preambleresponse.failed,error;response.created/in_progress/codex.*are preambleerror; a role-only first chunk is preambleerror(its HTTP code)throttlingException→ 429, …)The bytes read while waiting are replayed in front of the rest of the stream, so a served answer reaches the client byte for byte. Anything unrecognised counts as content (never withhold a good answer). The last candidate is not held.
Failures are classified by the reason the upstream gives (
tw_gateway::failure):no_balance_pause_secs(1800). Used-up quota → paused until the reset time (from the bodyresets_at/resets_in_seconds, the quota headers, or the GLM 429), elsequota_pause_secs(3600). Rate limit withRetry-After(or GeminiretryDelay) → that long, at mostrate_limit_max_pause_secs(3600). A missing model moves on without counting against the upstream.failures_to_pause, 3); the pause starts atpause_secs(60) and doubles on each re-open up tomax_pause_secs(600), back to the start after a success.invalid x-api-key) instead of our paraphrase. 5xx/429 on the last candidate are unchanged.The two hard rules in
healthstill hold: a single candidate bypasses pausing, and when every candidate is paused they are all tried (fail-open).Config / API
failoversection inconfig.yaml; defaults stay out of the file, out-of-range values are refused (config.failover_range). Documented indocs/config.md/docs/config.zh-CN.md(generated tables).Overview.failover(FailoverView) — CONTROL_API_VERSION 30 (shared with Estimate count_tokens locally; resend without reasoning sealed by another account #238, same release). Lite edits it withPATCH /configlikeretention.config.failover_range,gw.upstream.stream_opening_error.tw-breakeris untouched: the per-upstream cooldown is passed as aPolicyper call.Tests
Unit tests for classification, the stream-opening judge (per format, split chunks, byte-for-byte replay) and the pause policy (doubling, ceiling, reset, stated reasons, settings from config); end-to-end tests for overloaded-at-start failover, no retry once content has started, 402 pausing the upstream at once, and the last upstream's 401 reaching the client; control-plane test for the overview and PATCH.
🤖 Generated with Claude Code