[PR #11658] fix: add stream idle timeout to prevent sessions from hanging indefin… #13880

Closed
opened 2026-02-16 18:18:42 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11658

State: closed
Merged: No


…itely

When network issues occur mid-stream (TCP half-open connections, stalled LLM providers, proxy timeouts), the streaming loop would hang forever waiting for the next chunk. This fix adds an idle timeout that detects when no data has been received for a configurable period (default 60 seconds) and triggers a retry with exponential backoff.

Changes:

  • Add StreamIdleTimeoutError class to message-v2.ts
  • Add withIdleTimeout() async generator wrapper in processor.ts
  • Wrap stream.fullStream with idle timeout in the process loop
  • Mark StreamIdleTimeoutError as retryable so sessions recover automatically
  • Add stream_idle_timeout config option under experimental settings
  • Add additional network error types (ETIMEDOUT, ENOTFOUND, etc) as retryable

Fixes issues where sessions get stuck for hours on LLM requests. Related: #8383, #2512, #2819, #4255

What does this PR do?

Please provide a description of the issue (if there is one), the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the pr.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11658 **State:** closed **Merged:** No --- …itely When network issues occur mid-stream (TCP half-open connections, stalled LLM providers, proxy timeouts), the streaming loop would hang forever waiting for the next chunk. This fix adds an idle timeout that detects when no data has been received for a configurable period (default 60 seconds) and triggers a retry with exponential backoff. Changes: - Add StreamIdleTimeoutError class to message-v2.ts - Add withIdleTimeout() async generator wrapper in processor.ts - Wrap stream.fullStream with idle timeout in the process loop - Mark StreamIdleTimeoutError as retryable so sessions recover automatically - Add stream_idle_timeout config option under experimental settings - Add additional network error types (ETIMEDOUT, ENOTFOUND, etc) as retryable Fixes issues where sessions get stuck for hours on LLM requests. Related: #8383, #2512, #2819, #4255 ### What does this PR do? Please provide a description of the issue (if there is one), the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the pr. **If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!** ### How did you verify your code works?
yindo added the pull-request label 2026-02-16 18:18:42 -05:00
yindo closed this issue 2026-02-16 18:18:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13880