Agent FixboardAgentFixboard

Coding agent CLI: "API Error: Connection closed mid-response"

The reply stops with API Error: Connection closed mid-response. The response above may be incomplete. The same report writes 'API Error: Connection closed mid-response. The response above may be incomplete.' Tokens are used, and often nothing usable is left.

From GitHub

Coding agent CLI

Difficulty
Moderate
Time
~15 min
Steps
4
Fixed in
—
Last checked

Not fixed upstream yet: the issue is open. Source: issue open. Last checked 2026-10-25.

Symptom

The reply stops with API Error: Connection closed mid-response. The response above may be incomplete. The same report writes 'API Error: Connection closed mid-response. The response above may be incomplete.' Tokens are used, and often nothing usable is left.

Evidence what you'll see

  • Issue #100353 logs [DEBUG] Stale connection — disabling keep-alive for retry and then [ERROR] Streaming idle timeout (byte-level): stream idle: no bytes for 60000ms, aborting stream.
  • The same log then says Stream idle timeout - no chunks received and a 400 whose message is The requested previous_message_id has already been continued.
  • The 2.1.214 changelog line quoted in #100353 says keep-alive pooling was changed to disable after a stale-connection error, so a retry would open a fresh socket.

Why it happens

Issue #100353 says the intended behavior is one retry on a fresh socket. The code instead sets keepAliveDisabled = true on shared client state, and the only reset function named there is _resetKeepAliveForTesting. After that, every request in the process is sent with keepalive: false and opens a new connection, for as long as the process lives. From 2.1.213 the flag gate is gone, so the switch always fires. A stream can still start (message_start arrives) and then go quiet until the byte-level idle watchdog aborts it. The retry reuses previous_message_id, the server rejects it, and the client resends the conversation. Separate comments on #69336 describe two other cuts: one large tool write, and a gateway whose reverse proxy times out at 60 seconds.

Affected versions

Issue #69336 reports version 2.1.173 on Ubuntu/Debian, in the VS Code integrated terminal. Issue #70217 reports version 2.1.186 on darwin, in Apple Terminal. Issue #100353 says this latch is a regression from 2.1.213 (2026-07-17), measured on 2.1.292 on Linux, and still present in 2.1.293. A comment also sees it on Windows in the VS Code terminal on 2.1.216 through 2.1.218.

Fix steps

0 of 4 done

Your check marks stay in this browser only.

How to check it worked

  • Run the same multi-step task. The reply finishes without API Error: Connection closed mid-response. The response above may be incomplete.
  • With --debug-file <path>, a single connection error no longer leaves every later request opening a new connection. Issue #100353's check is a proxy that resets one connection: the patched build reuses one connection afterward, and the stock build opens a new one each time.

If it still fails

  • Issues #69336, #70217, and #100353 are open. The linked issue does not name a merged pull request.
  • One comment says downgrading to 2.1.220 made the error stop for them. Another comment still saw it on 2.1.216 through 2.1.218.
  • One comment found unrelated sessions failing on the same second of a 300-second cycle, matching WAN drops in the router log. That comment's check prints each stream error's second inside the cycle from the local project transcripts.
  • Another comment added a project-instruction rule to call CronCreate for a recurring self-ping of about 15 minutes, and CronDelete when nothing is left to watch. The comment says this only keeps the session alive.

Sources and credit

Summarized in our own words from these public reports. Credit goes to their authors.

Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change

Hit an error we don't cover? Submit it