Repository navigation
feat(fallback): first_token_timeout fails over a stalled stream early - #66
Merged
Merged
Conversation
A provider that accepts a streaming request but never sends a token used to hold the request for the full provider timeout before failover. fallback.first_token_timeout arms a second timer for streaming calls that is reset by content or reasoning chunks; when it fires, the router moves to the next provider. Off by default in code; the example config sets 10s. - peekStream gains a progress hook; reasoning-only chunks keep the timer alive - timeout errors name which timer fired - FAILOVER_BENCH_FIRST_TOKEN knob for make bench-failover - docs/first-token-timeout.md with tradeoffs and a real-board test plan Measured (Mac, 2s provider timeout, 500ms first-token): stalled-provider cold p50 2028 -> 528 ms; healthy and 429 rows unchanged; buffered chat benchmark stays at 151 allocs/op. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
A provider that accepts a streaming request and then never sends a token held the request for the full provider
timeout(90s by default) before failover. Both external reviews still held this against the router.Change
fallback.first_token_timeout. For streaming calls shorter than the provider timeout, a second timer starts. Content or reasoning chunks reset it. When it fires, the call is cancelled and the router moves to the next provider.configs/config.example.yamlsets10s.peekStreamtakes aprogresshook. Reasoning-only chunks (reasoning_content/reasoning) keep a thinking model alive, and role-only chunks do not.no first token within …vsprovider timeout …).FAILOVER_BENCH_FIRST_TOKENknob formake bench-failover.docs/first-token-timeout.md: when to use it, tradeoffs, value guide, and a real-board test plan (results still to come).Measured (Mac, 200 req/row, 16 conc, provider timeout 2s)
first_token_timeout: 500msBenchmarkChatCompletions_Bufferedstays at 151 allocs/op, the same as main.Tests
pkg/proxy/first_token_test.go: StallFallsBackEarly, OffKeepsProviderTimeout, ReasoningKeepsAlive (fails without the progress hook, checked by mutation), BufferedUnaffected.go vetandgo test -race ./...are green.🤖 Generated with Claude Code