Repository navigation
Stop a stream that generates too slowly - #131
Merged
Merged
Conversation
A provider can set the slowest generation its streams may keep up: providers.min_speed_tokens_per_sec (1-1000, NULL = off) averaged over providers.min_speed_window_secs (5-120, default 20). Both columns are added on startup. From the first token on, a stream is judged once a second. When the text it streamed over the last window (answer, reasoning and tool arguments; four ASCII characters or one other character to a token, Gemini's running count when higher) comes to fewer tokens per second than the minimum, the stream ends with a 503 error frame in the client's format, the upstream connection is closed and the route is charged a failure. Pauses of 5 s or more are left out of the window; a window more than half pauses, and anything after the upstream's stop reason, is not judged. The session's affinity to the route is dropped, the answer so far is billed as for any stream cut short, and the log row carries UpstreamTooSlow and the speed at the cut (tokens_per_sec). Whole answers and Responses WebSocket turns are not measured. - GatewayError::UpstreamTooSlow (503), gateway_provider_too_slow_total - Provider create/PATCH take both fields (PATCH null turns it off); out-of-range values are a 400 - Edit provider dialog: "Stop when generation is slower than [ ] tokens/s for [20] s", checked as typed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
react-refresh/only-export-components: a module that exports components exports nothing else. 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
A provider can now set the slowest generation its streams may keep up. A stream that falls below it is cut with a 503 so the client can try again, and the route is charged a failure.
db/schema.sql):providers.min_speed_tokens_per_sec INT NULL(1–1000, NULL = off) andproviders.min_speed_window_secs INT NOT NULL DEFAULT 20(5–120), both with CHECK constraints.POST /api/admin/providersandPATCH /api/admin/providers/{id}takemin_speed_tokens_per_secandmin_speed_window_secs. On PATCH, a missing field is left unchanged andnullturns the check off. Values out of range get a 400. The provider responses include both fields.proxy/min_speed.rs, wired into the stream pump):tw_dialect::convert::error_frame(client, 503, …):overloaded_errorfor Anthropic,response.failedfor Responses,UNAVAILABLEfor Gemini, a Chaterrorchunk for Chat.UpstreamTooSlow/ 503, which counts against the route's breaker.tokens_per_sec, the warn log line carries the numbers, andgateway_provider_too_slow_total{provider}is incremented.[Unreleased]entry.Tests
crates/test-support/tests/gateway_min_speed.rs, run against paced SSE upstreams:overloaded_errormake precommitpasses. The new integration file and the related gateway, streaming, retry, console and OpenAPI suites pass locally.🤖 Generated with Claude Code