Symptom
Mid-turn, the agent appears to be working, then the reply stops with a connection error and little or nothing usable. More common in long sessions with many tool calls, after compaction, or when one tool call writes a very large payload.
Evidence what you'll see
- Error:
API Error: Connection closed mid-response. The response above may be incomplete. - Related:
API Error: Stream idle timeout - no chunks received - Debug line tied to one lead:
Stale connection — disabling keep-alive for retry
Cause
Several separate leads, none confirmed by a maintainer: issue #100353 reports that since 2.1.213 one connection error turns off keep-alive for the rest of the process; others link it to oversized single tool writes, network idle drops, or gateway timeouts.
Fix steps
0 of 4 done
Your check marks stay in this browser only.
Verify the fix worked
- Rerun a multi-step task that failed before; replies complete without the error.
- With
--debug-file <path>, check whether the keep-alive line appears after a connection blip.
Sources and credit
Summarized in our own words from these public reports. Credit goes to their authors.
Provided as is, without warranty. Test in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change