Skip to content

feat: fall back for streamed requests that fail before their first token - #43

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/30-streamed-fallback
Oct 4, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/30-streamed-fallback

Conversation

@Yash-Chindam

Copy link
Copy Markdown
Owner

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 200 with 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:

  • if the local engine fails at that point and the request is entitled to the external provider, it falls back; the headers, every chunk, the metrics and the trace name the model that actually answered;
  • if there is no fallback, the caller gets the ordinary 502/503 JSON error, and the admission slot is released;
  • once a token has been sent there is no fallback: one model's output is never continued by another.

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

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>
@github-actions github-actions Bot added documentation Improvements or additions to documentation area/api area/tests labels Oct 4, 2026
@github-actions
github-actions Bot merged commit a9e33f3 into main Oct 4, 2026
6 checks passed
@github-actions
github-actions Bot deleted the feat/30-streamed-fallback branch October 4, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api area/tests documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant