From b0d7b942defd75f7b83c4f7ecefb202c92881ed4 Mon Sep 17 00:00:00 2001 From: graehl Date: Wed, 5 Aug 2026 09:08:20 +0000 Subject: [PATCH] fix: disable Bun idle timeout that cut long generations Bun.serve defaults idleTimeout to 10s of socket silence. Copilot /v1/messages sends no bytes while a tool_use input is generated (all input_json deltas arrive in one burst at the end), so any tool call taking >10s to produce - e.g. a large Claude Code Edit - was cut mid-stream, surfacing client-side as "API Error: Connection closed mid-response". Long time-to-first-byte responses hit the same limit. Observed a 41s silent gap before an ~1900-delta burst on a large tool input; with the timeout disabled the stream completes cleanly. --- src/start.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/start.ts b/src/start.ts index 14abbbdff..e429a2e10 100644 --- a/src/start.ts +++ b/src/start.ts @@ -117,6 +117,13 @@ export async function runServer(options: RunServerOptions): Promise { serve({ fetch: server.fetch as ServerHandler, port: options.port, + // Bun.serve defaults idleTimeout to 10s, which kills any connection with + // no socket activity for 10s. Copilot's /v1/messages holds the response + // (headers and/or mid-stream) for the length of upstream generation, so + // large completions (e.g. a big Claude Code Edit) routinely exceed 10s of + // silence and get cut, surfacing in clients as "Connection closed + // mid-response". 0 disables the timeout entirely. + bun: { idleTimeout: 0 }, }) }