From cdf17eb2abdf5fe7055a501a6de38b429a9c7da7 Mon Sep 17 00:00:00 2001 From: "vs-code-engineering[bot]" <122617954+vs-code-engineering[bot]@users.noreply.github.com> Date: Tue, 9 Jun 2026 20:46:23 +0000 Subject: [PATCH] fix: guard postToolUse hook against closed response stream (fixes #319003) (#319011) * fix: guard postToolUse hook against closed response stream (fixes #319003) When the user cancels a chat request while tools are executing, the response stream is closed. The postToolUse hook would then attempt to write warnings via hookProgress to the closed stream, causing an unhandled 'Response stream has been closed' error. Add a cancellation token check before executing the postToolUse hook. If the request is already cancelled, skip the hook entirely since the stream cannot accept further output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: replace unicode em-dash with ASCII hyphen in comment The Compile & Hygiene check failed due to a non-ASCII character (U+2014 em-dash) in a code comment. Replace with a standard hyphen. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: vs-code-engineering[bot] <122617954+vs-code-engineering[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../copilot/src/extension/prompts/node/panel/toolCalling.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx b/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx index 59b7fa47486..9582b3c8cd9 100644 --- a/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx +++ b/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx @@ -607,6 +607,11 @@ async function appendHookContext( return; } + // Skip postToolUse hook if the request was cancelled - the response stream is closed + if (props.token.isCancellationRequested) { + return; + } + // Execute postToolUse hook after successful tool execution const postHookResult = await chatHookService.executePostToolUseHook( props.toolCall.name,