Skip to content

Commit 11c5b82

Browse files
dimakisclaude
andcommitted
fix(chat): catch ProcessTransport errors on interrupt
When the SDK child process has already exited, calling interrupt() throws "ProcessTransport is not ready for writing" as an unhandled rejection, crashing the server. Wrap the call in try/catch — if the transport is dead the interrupt is moot anyway. Also add .catch() to the fire-and-forget interruptChat() call in ws-handler-v2 to prevent any future unhandled rejections from that path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5709b06 commit 11c5b82

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

server/chat.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,16 @@ export async function interruptChat(
12731273
);
12741274
await Promise.allSettled(stops);
12751275
}
1276-
await session.queryInstance.interrupt();
1276+
try {
1277+
await session.queryInstance.interrupt();
1278+
} catch (err: unknown) {
1279+
// ProcessTransport may already be dead (process exited) — the interrupt
1280+
// is moot in that case. Swallow rather than crashing the server.
1281+
log.warn('interrupt() failed (transport likely dead)', {
1282+
clientId,
1283+
err: err instanceof Error ? err.message : String(err),
1284+
});
1285+
}
12771286
// Only push to inputQueue on first delivery — a retried interrupt should
12781287
// still call interrupt() (to halt the agent) but not double-queue the prompt.
12791288
if (!isDup) {

server/ws-handler-v2.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,12 @@ export function handleInterruptV2(
733733
msg.contextBlocks,
734734
msg.clientMsgId,
735735
msg.model,
736+
).catch((err: unknown) =>
737+
log.error('interruptChat failed', {
738+
connectionId,
739+
sessionId: msg.sessionId,
740+
err: err instanceof Error ? err.message : String(err),
741+
}),
736742
);
737743
log.info('interrupt', { connectionId, sessionId: msg.sessionId });
738744
return;

0 commit comments

Comments
 (0)