Repository navigation
Conversation
The request-level budget (retry.timeout_seconds) also bounded the whole downstream stream: handleInference built the upstream HTTP request from requestCtx, so when the budget expired mid-generation the upstream connection was torn down. A long thinking turn (xhigh/max reasoning, large context) legitimately runs for many minutes, and the client saw a truncated stream carrying the Go error text "context deadline exceeded" — which reads as a context-limit failure rather than a timeout. Measured on a live deployment: 15 stream errors, 11 of them within 40ms of exactly the 300s budget, plus 11 "successful" 200s also pinned at exactly 300s (truncated streams reported as success). retry.stream_timeout_seconds now bounds the stream phase only: - The attempt phase keeps its own bounds (attempt_timeout_seconds, ResponseHeaderTimeout, connect timeout), so a wedged upstream still cannot hold a connection open. - The upstream request carries the stream context, so the connection survives past the request budget. - The stream context derives from the CLIENT context, so a client disconnect still tears the stream down immediately. - 0 keeps the historical behavior: the request-level timeout also bounds the stream. Tests: a stream outlives the request budget when the budget is configured; the request budget still bounds the stream when it is not; a client disconnect still ends the stream immediately. Reverting the one-line change that carries the stream context fails the first test.
Suydev
added a commit
to Suydev/opencode2api
that referenced
this pull request
Nov 13, 2026
Suydev
added a commit
to Suydev/opencode2api
that referenced
this pull request
Nov 13, 2026
…nd stream budget
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
retry.timeout_secondsbounded the whole downstream stream, not just the request.handleInferencebuilt the upstream HTTP request fromrequestCtx, so when the budget expired mid-generation the upstream connection was torn down.A long thinking turn (xhigh/max reasoning, large context) legitimately runs for many minutes. The client saw a truncated stream carrying the Go error text
context deadline exceeded— which reads as a context-limit failure rather than a timeout, and is why this went unreported for so long.New
retry.stream_timeout_secondsbounds the stream phase only.Why the split is safe
attempt_timeout_seconds(dial + write + headers + first event),ResponseHeaderTimeout, and the connect timeout. A wedged upstream still cannot hold a connection open.requestCtx, so a client disconnect still tears the stream down immediately.0keeps the historical behavior: the request-level timeout also bounds the stream.Evidence
Measured on a live deployment with
retry.timeout_seconds: 300:stream_erroroutcomes, 11 of them within 40ms of exactly 300s, all onminimax-m3.1-flash-free(1M context, xhigh/max effort).duration_mspinned at exactly 300s — truncated streams that looked successful.Upstream silence during the thinking phase is short (measured 8-56s), so the 300s wall was pure budget, not a slow model.
Tests
internal/gateway/stream_budget_test.go:Reverting the one-line change that carries the stream context into the upstream request fails the first test.
Config
{ "retry": { "max_attempts": 6, "timeout_seconds": 300, "stream_timeout_seconds": 1800 } }stream_timeout_secondsis opt-in: omit it and nothing changes.