Stream silently terminates without error or retry in agentic loop

Resolved 💬 3 comments Opened Mar 5, 2026 by jitlabs-sg Closed Mar 9, 2026

Summary

During long-running agentic tasks (2+ hours), the streaming response silently terminates mid-output. No error is raised, no retry is attempted, and the agent task silently stops — leaving the user unable to distinguish between task completion and an abnormal termination.

Environment

  • OS: macOS 15.3, Apple M3 16GB
  • Claude Code: latest (installed via npm)
  • Node: v25.x
  • Network: residential broadband (not enterprise/datacenter)

Reproduction

  1. Start a complex agentic task that involves heavy file I/O (reading/writing 20+ files, running builds, grep/glob across large codebases)
  2. Let it run for 2+ hours continuously
  3. At some point the streaming output stops mid-sentence or mid-tool-call

Frequency: Happens roughly 1 in 3-4 long sessions. More likely when the agent is doing parallel tool calls or processing large context windows.

Observed behavior

  • SSE stream stops mid-way (no message_stop event received)
  • No error message displayed to the user
  • No automatic retry attempted
  • The agentic loop silently terminates as if the task completed normally
  • Terminal returns to the input prompt without any indication of failure
  • No relevant error in Claude Code's debug logs — the stream just... ends

Expected behavior

  • Claude Code should detect that the stream terminated without a proper message_stop event
  • It should either:
  • Automatically retry the interrupted request (with the conversation context intact), or
  • Surface a clear error to the user: "Stream interrupted — press Enter to retry" (or similar)
  • The agent task should NOT silently terminate

Impact

This is a silent failure — significantly worse than a visible error because:

  1. Users cannot tell if the task completed successfully or was interrupted
  2. Long-running agent tasks (refactoring, multi-file edits, complex debugging) lose progress with no warning
  3. The user may not notice for minutes/hours that the agent stopped, especially in background tasks
  4. There is no way to resume from where the stream was interrupted

Analysis

From running a local proxy (gac-router) that logs all upstream traffic, the pattern appears to be:

  • The TCP connection stays alive (no RST/FIN observed)
  • The SSE stream simply stops sending chunks
  • No heartbeat/ping mechanism detects the stall
  • The client-side idle timeout (if any) does not trigger, or is set too high

This is likely an edge case in the API's streaming infrastructure that surfaces under:

  • High memory pressure (16GB machine running multiple tools)
  • Long-lived connections (2+ hours)
  • Large request/response payloads (200KB+ context)

Datacenter test environments with stable networks and ample resources would be unlikely to reproduce this naturally.

Suggested fix

  1. Client-side idle timeout: If no SSE chunk is received for N seconds (e.g., 120s for thinking models, 30s for non-thinking), treat the stream as interrupted
  2. Incomplete response detection: Check that the final event was message_stop before considering the response complete
  3. Auto-retry with backoff: On detected stream interruption, retry the request (at least once) before giving up
  4. User notification: If retry also fails, clearly inform the user that the stream was interrupted

---

Labels: bug, agentic, streaming

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗