feat: fall back for streamed requests that fail before their first token - #43
Merged
Merged
Conversation
Draw the first token before sending any byte, so an engine failure at the start gets a declared fallback or a real error status rather than a broken stream. A stream that has already sent a token never switches models. 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
Streamed requests now get the same declared fallback as buffered ones (§7.1, §16 "no silent routing or fallback changes"), and an engine that fails before producing anything returns a real error status instead of a
200with a broken stream.How
The gateway draws the first token before it sends any byte. Until then the status code and route headers are still open, so:
502/503JSON error, and the admission slot is released;Tests
Four new integration tests: fallback before the first token; no fallback gives a real status and frees the only slot; a failure after the first token does not switch models; an empty stream still ends cleanly.
Local: ruff and mypy clean, 483 tests pass, Playwright 9/9.
Limits
Time to first byte for a stream now includes the engine's time to first token, since nothing is sent before it. The role chunk used to go out immediately.
🤖 Generated with Claude Code