language_models: Add stream idle timeout for ChatGPT subscription requests - #59123
Closed
rtfeldman wants to merge 1 commit into
Closed
language_models: Add stream idle timeout for ChatGPT subscription requests#59123rtfeldman wants to merge 1 commit into
rtfeldman wants to merge 1 commit into
Conversation
…uests The Codex backend sometimes accepts a connection but never sends response headers, or goes silent mid-stream, leaving the agent stuck on a spinner forever since Zed has no read timeout. Add an activity-based 5-minute idle timeout (matching the Codex CLI's stream_idle_timeout default) that resets on every stream event and surfaces as a retryable HttpSend error. Also bound the OAuth token refresh request, which had the same unbounded-hang problem.
rtfeldman
deleted the
richard/ai-317-agent-gets-stuck-loading-for-chatgpt-subscriptions
branch
June 11, 2026 19:10
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.
ChatGPT subscription (Codex backend) requests can stall — the server accepts the connection but never sends response headers, or goes silent mid-stream — and Zed would wait forever, leaving the agent stuck on a loading spinner with no error and no retry, since Zed's HTTP client only has a connect timeout. This adds an activity-based idle timeout to those requests: a timer covers the window from sending the request until response headers arrive, and is then reset every time a stream event arrives. If nothing happens for 5 minutes, the request fails with a retryable
HttpSenderror so the agent's existing backoff/retry logic takes over. The OAuth token refresh request gets a similar (60s) bound, since it could hang a turn the same way before the completion request even started.This has some history: #57891 attempted to fix the same stall with a 10-second response-header timeout, and was reverted in #58035 after reports of GPT models abruptly stopping mid-turn. The problem was that the Codex backend doesn't send response headers until the model starts producing output, so at high reasoning effort healthy requests routinely take longer than 10 seconds to first byte, and the timeout was killing them on every attempt. (OpenCode shipped the same 10s default around the same time and hit the same regression: anomalyco/opencode#29548.) An idle timeout sidesteps that failure mode because it only needs to bound silence rather than time-to-first-byte plus thinking time, so it can be generous. The 5-minute value matches the
stream_idle_timeout_msdefault that OpenAI's own Codex CLI uses against this same backend (codex-rs/core/src/model_provider_info.rs), and is also the defaultheadersTimeoutthat Node's undici applies (300s) — i.e. the bound OpenCode effectively ran with before their regression (see anomalyco/opencode#15555). Notably, the complaints about the Codex CLI's 5-minute default run in the too slow direction (openai/codex#17003), not the false-positive direction, which is good evidence this won't cut off healthy long thinks.The timeout is only wired up for the ChatGPT subscription provider for now, since that's where the stalls have been reported (#57636).
Closes AI-317
Release Notes: