Stream silently terminates without error or retry in agentic loop
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
- Start a complex agentic task that involves heavy file I/O (reading/writing 20+ files, running builds, grep/glob across large codebases)
- Let it run for 2+ hours continuously
- 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_stopevent 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_stopevent - 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:
- Users cannot tell if the task completed successfully or was interrupted
- Long-running agent tasks (refactoring, multi-file edits, complex debugging) lose progress with no warning
- The user may not notice for minutes/hours that the agent stopped, especially in background tasks
- 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
- 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
- Incomplete response detection: Check that the final event was
message_stopbefore considering the response complete - Auto-retry with backoff: On detected stream interruption, retry the request (at least once) before giving up
- User notification: If retry also fails, clearly inform the user that the stream was interrupted
---
Labels: bug, agentic, streaming
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗