#8331·pi

Agent loop hangs forever when a provider stream stalls mid-response

Author: panbergcoCreated Aug 18, 2026Updated Sep 17, 2026

What happened?

During a provider incident (Anthropic 529 overload window), four long-running sessions froze mid-turn. In each case the SSE stream stopped delivering events but never closed, so the for await in streamAssistantResponse (packages/agent/src/agent-loop.ts) awaited forever: spinner kept animating, Escape did not cancel, queued follow-up messages never injected because no turn boundary ever came. Sessions sat frozen 25-109 minutes until killed by hand.

For comparison, every turn that did complete in the same period finished in under 8 minutes, including ones on 700k+ contexts. The failure is a stalled stream, not a slow turn.

Steps to reproduce

Hard to trigger on demand; it needs the provider to stall an open stream. Simulating it works: start a long streaming turn, then blackhole the connection mid-stream (drop packets to the API host without closing the socket, e.g. with iptables). The turn never ends and the agent is stuck.

Expected behavior

Silence on an open stream past a threshold should end the turn as a retryable provider error, like other stream errors do. I patched this locally with a per-event inactivity timer (default 180s, env-tunable, 0 disables) that throws into the existing error path; it is about 60 lines, no new deps. Happy to implement - the auto-closed #8330 carries the change if useful.

Version

0.84.1


Disclosure per CONTRIBUTING: drafted with AI assistance from a real debugging session's notes; the incident, timings and fix are from that session and I stand behind them.