[PR #12420] fix: add stream idle timeout to prevent sessions from hanging indefinitely #14206

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

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

State: closed
Merged: No


Problem

When network issues occur mid-stream (TCP half-open connections, stalled LLM providers, proxy timeouts), the streaming loop hangs forever waiting for the next chunk. Users report sessions getting stuck for hours.

Related issues: #8383, #2512, #2819, #4255

Solution

Add a configurable idle timeout that detects when no data has been received for a period (default 60 seconds) and triggers automatic 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

Configuration

# opencode.yaml (optional - defaults to 60 seconds)
experimental:
  stream_idle_timeout: 60

Testing

Tested locally by simulating network interruptions mid-stream. Sessions now automatically retry instead of hanging indefinitely.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12420 **State:** closed **Merged:** No --- ## Problem When network issues occur mid-stream (TCP half-open connections, stalled LLM providers, proxy timeouts), the streaming loop hangs forever waiting for the next chunk. Users report sessions getting stuck for hours. Related issues: #8383, #2512, #2819, #4255 ## Solution Add a configurable idle timeout that detects when no data has been received for a period (default 60 seconds) and triggers automatic 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 ## Configuration ```yaml # opencode.yaml (optional - defaults to 60 seconds) experimental: stream_idle_timeout: 60 ``` ## Testing Tested locally by simulating network interruptions mid-stream. Sessions now automatically retry instead of hanging indefinitely.
yindo added the pull-request label 2026-02-16 18:19:01 -05:00
yindo closed this issue 2026-02-16 18:19:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14206