Skip to content

[Error] [GitHub.copilot-chat] unhandlederror-Response stream has been closed #322760

Closed as not planned

Description

@vs-code-engineering

Error Message

unhandlederror-Response stream has been closed

Stack Trace

    at _2 (../src/extension/intents/node/hookResultProcessor.ts:132:16)
    at processHookResults (../src/extension/chat/vscode-node/chatHookService.ts:513:2)
    at process.processTicksAndRejections (node:<REDACTED: user-file-path>:104:5) [not deminified]
    at async PQi (../src/extension/prompts/node/panel/toolCalling.tsx:621:24)

Raw Stack Trace (minified)
Error: Response stream has been closed 	at _2 (c:\Program <REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:1749:6) 	at Qye.executePostToolUseHook (c:\Program <REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:6826:706) 	at process.processTicksAndRejections (node:<REDACTED: user-file-path>:104:5) 	at async PQi (c:\Program <REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:1693:106)

Details

Property Value
Bucket ID 65455ee7-1699-28e0-8d2a-d531039ee775
Extension Version 0.53.1
Last Seen Tue Jun 23 2026 23:49:46 GMT+0000 (Coordinated Universal Time)
Platforms win32
Product VSCode

This issue was automatically created from the VS Code Errors Dashboard

Activity

  1. added
    bug
    error-telemetry
    ai-generated
    *fix
    on Jun 24, 2026
  2. vs-code-engineering commented on Jun 24, 2026

    @vs-code-engineering
    Author
  3. vs-code-engineering commented on Jun 24, 2026

    @vs-code-engineering
    ContributorAuthor

    No fix proposed — already fixed in main by #321959 (commit 3d575eec); the shipped 0.53.1 bundle predates that fix. Its bundle lacks the exact 10-line cancellation re-check guard that PR added — confirmed by the deminified call-site offset (chatHookService.ts:513 in 0.53.1 vs :523 in fixed source, a 10-line delta that matches PR #321959's +10 diff).

    Summary

    The agent-mode PostToolUse hook path throws an unhandled Response stream has been closed. When a chat request is cancelled while a PostToolUse hook is still running (it spawns external, user-configured commands and can take arbitrarily long), the response stream is already closed by the time the hook resolves; processHookResults then writes hook progress/warnings to the now-closed stream, and core's extHostChatAgents2.ts throws. This is a recurrence of the already-fixed #321951 / #319003 on a pre-fix build — extension 0.53.1 (win32, 54 users) does not contain the re-check guard merged to main on 2026-06-19, so no new code change is warranted.

    Culprit Commit

    This bucket is not a new regression — it is a pre-fix build of a bug already fixed in main. There is no new culprit commit; the reference fix is:

    Field Value
    Fix commit 3d575ee
    Fix PR #321959 (merged 2026-06-19, +10 lines to chatHookService.ts)
    Fixes #321951 (0.53.0 regression tracker) · original #319003
    Why pre-fix The deminified call site chatHookService.ts:513 in 0.53.1 is exactly 10 lines above the same processHookResults call in fixed source (:523); that 10-line delta equals PR #321959's +10 guard block, so 0.53.1 was built without the guard.

    The underlying race long predates these trackers (it has existed since hook execution moved into the extension); cdf17eb2 (#319011) added a pre-hook cancellation guard, and 3d575eec (#321959) closed the remaining during-hook window.

    Code Flow

    sequenceDiagram
        participant TC as toolCalling.tsx
        participant CHS as chatHookService.ts
        participant HRP as hookResultProcessor.ts
        participant Core as extHostChatAgents2.ts
    
        TC->>TC: appendHookContext() pre-hook guard isCancellationRequested? (false)
        TC->>CHS: executePostToolUseHook(stream, token)
        CHS->>CHS: await executeHook('PostToolUse') spawns external command (slow)
        Note over Core: user cancels; finally runs stream.close() sets _isClosed = true
        Note over CHS: 0.53.1 lacks the post-await re-check guard
        CHS->>HRP: processHookResults({ outputStream })
        HRP->>Core: outputStream.hookProgress(warning)
        Core-->>HRP: throwIfDone() throws "Response stream has been closed"
    
    Loading

    Affected Files

    File Role Evidence
    extensions/copilot/src/extension/intents/node/hookResultProcessor.ts crash site L132 (from stack): outputStream.hookProgress(hookType, undefined, formattedWarnings)
    extensions/copilot/src/extension/chat/vscode-node/chatHookService.ts root cause / already fixed L510-L512 in fixed source: if (token?.isCancellationRequested) { return undefined; } — absent in 0.53.1
    extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx trigger / caller L616-L621: pre-hook guard, then await executePostToolUseHook(...)
    src/vs/workbench/api/common/extHostChatAgents2.ts core producer (by design) L85 throws; L1070 stream?.close() runs in the finally of raceCancellationWithTimeout(1000, task, token)

    Repro Steps

    1. Configure a PostToolUse hook that runs a non-trivial external command (so it takes a moment to complete).
    2. Start an agent-mode chat turn that invokes a tool, triggering the PostToolUse hook.
    3. Cancel the request while the hook is executing (after the pre-hook guard in toolCalling.tsx has already passed).
    4. On a build without fix: re-check cancellation after postToolUse hook to avoid closed-stream write (fixes #321951) #321959 (e.g. 0.53.1): the hook resolves, processHookResults writes a warning to the now-closed stream, and Response stream has been closed is thrown to telemetry. On a build with fix: re-check cancellation after postToolUse hook to avoid closed-stream write (fixes #321951) #321959, the post-await guard returns early and no write occurs.

    Open Questions

    Why no fix proposal: the error is already fixed in main by #321959 (3d575eec); this bucket is a pre-fix 0.53.1 build, so there is no source change to make — per the errors-triage "Expected (pre-fix build)" rule, the fix simply needs to reach the 0.53.x stable line.

    Hypotheses to test (only relevant if the bucket persists on a build that does contain #321959):

    1. Residual non-cancellation close window — stream.close() at extHostChatAgents2.ts:1070 also runs in the finally when the agent task throws or times out, not only on cancellation. If a PostToolUse hook is still in flight at that moment and the token is not cancelled, the token-based re-check guard would not catch it. Disprove by confirming the tool-calling loop always awaits every in-flight hook before the task settles for non-cancellation reasons.
    2. Cherry-pick gap — disprove by checking whether 3d575eec was ported to the release/0.53 branch before 0.53.1 was cut; if not, every 0.53.1 user keeps hitting this until they move to a build that includes the fix.

    Instrumentation to add (so a true post-fix recurrence is distinguishable): the bucket ### Details already records the resolved extension version, which is sufficient to separate pre-fix 0.53.1 hits from any future post-fix hit. If it does recur at or above the fixed version, enrich the throw at extHostChatAgents2.ts throwIfDone() with the close reason (cancelled vs completed vs errored) so residual-gap occurrences can be told apart from pre-fix builds without source archaeology.

    Question for the area owner: was 3d575eec (#321959) cherry-picked into the release/0.53 stable branch, or will 0.53.x users only receive the fix when they upgrade to the next minor?

    Recommended Owner

    @pwang347 — owns Chat Hooks per triage/working-areas.md, authored/owned both prior fixes for this exact path (#319011, #321959), and is an active contributor (committed to chatHookService.ts on 2026-06-09, PR #320520). Team-membership (write access via merged PRs) and 90-day liveness checks both pass.

    Generated by errors-fix · 2.2K AIC · ⌖ 123 AIC · ⊞ 69.4K · ◷

  4. added
    ai-analyzed
    on Jun 24, 2026
  5. removed
    *fix
    on Jun 24, 2026
  6. vs-code-engineering commented on Jun 25, 2026

    @vs-code-engineering
    ContributorAuthor

    Regression Details — signature also on pre-fix stable 0.54.0

    The Response stream has been closed PostToolUse-hook error tracked here also appears on stable extension 0.54.0 (VS Code 1.126.0) under a new minification-drift bucket ID. Same throw site (hookResultProcessor.ts:129 → executePostToolUseHook → chatHookService.ts).

    Property Value
    Product VSCode · extension GitHub.copilot-chat
    Classification Expected (pre-fix build) — same as the 0.53.1 recurrence above
    Scan range 0.52.0 → 0.54.0 (stable)
    Representative bucket d098daa6 — win32, 86 users, 343 hits (linked in Kusto)

    0.54.0 (first seen 2026-05-29) predates fix #321959 (3d575eec, merged 2026-06-19), so it lacks the during-hook cancellation guard — consistent with the errors-fix analysis above. This is a data point for the open "when do stable users receive the fix" question: the 0.54.0 base build does not yet contain it. No reopen, no new issue — linked for continuity.

    Generated by errors-regression-scan · 2K AIC · ⌖ 55.9 AIC · ⊞ 48.1K · ◷

  7. vs-code-engineering commented on Jul 27, 2026

    @vs-code-engineering
    ContributorAuthor

    Stable Release Anomaly Details

    An automated stable-release anomaly scan (GitHub.copilot-chat v0.58.0 vs previous stable minor v0.57.0) shows this error continuing on v0.58.0.

    The Response stream has been closed signature spans 2 buckets on v0.58.0, affecting ~405 users total. Representative bucket ea9710dc (~272 users). Linked to this issue.

    Commit-range narrowing is skipped for extension-mode scans.

    Generated by errors-stable-scan · 1.6K AIC · ⌖ 42.1 AIC · ⊞ 53.2K · ◷

  8. pwang347 commented on Sep 17, 2026

    @pwang347
    Contributor

    Closing as this is on the chat extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ai-analyzedai-generatedbugerror-telemetryextensionrecent-regressionstable-anomaly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions