Skip to content

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

Open

Description

@vs-code-engineering

Error Message

unhandlederror-Response stream has been closed

Stack Trace

    at <REDACTED: user-file-path> VS <REDACTED: (../src/extension/chatSessions/common/externalEditTracker.ts:66:32)
    at wse.trackEdit (../src/extension/chatSessions/common/externalEditTracker.ts:54:9)
    at NQt (../src/extension/chatSessions/copilotcli/node/permissionHelpers.ts:344:21)
    at trackEditIfNeeded (../src/extension/chatSessions/copilotcli/node/permissionHelpers.ts:175:9)
    at async <REDACTED: user-file-path> VS <REDACTED: (../src/extension/chatSessions/copilotcli/node/copilotcliSession.ts:1186:17)

Raw Stack Trace (minified)
Error: Response stream has been closed 	at <REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:2470:12357 	at new Promise (<anonymous>) 	at wse.trackEdit (<REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:2470:12236) 	at NQt (<REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:2538:809) 	at sHn (<REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:2533:11317) 	at async <REDACTED: user-file-path> VS <REDACTED: user-file-path>/resources\app\extensions\copilot\dist\extension.js:2544:4532

Details

Property Value
Bucket ID a5972ab5-388b-819b-ca49-0c714b627571
Extension Version 0.48.0
Last Seen Wed May 13 2026 23:49:38 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 May 14, 2026
  2. vs-code-engineering commented on May 14, 2026

    @vs-code-engineering
    ContributorAuthor

    Stable Release Anomaly Details

    • Anomaly type: spike
    • Spike factor: 3x increase
    • Previous stable: 0.47.1
    • Current stable: 0.48.0

    Deminified Stack

    Frame Source Function
    1 externalEditTracker.ts:66 (anonymous)
    2 externalEditTracker.ts:54 trackEdit
    3 permissionHelpers.ts:344 (anonymous)
    4 permissionHelpers.ts:175 trackEditIfNeeded
    5 copilotcliSession.ts:1186 (anonymous)

    Note: An existing issue #312810 tracks the same error message from extension v0.45.1, but with a completely different code path (stream push/progress). This spiked bucket in v0.48.0 originates from the externalEditTracker / permissionHelpers code path — a distinct occurrence.


    Stable release anomaly scan: GitHub.copilot-chat 0.48.0 vs 0.47.1

    Generated by errors-stable-scan · ● 12.9M · ◷

  3. added
    ai-analyzed
    and removed
    *fix
    on May 14, 2026
  4. vs-code-engineering commented on May 14, 2026

    @vs-code-engineering
    ContributorAuthor

    🔧 Error Fix Analysis

    Summary

    Error: unhandlederror-Response stream has been closed in GitHub.copilot-chat extension v0.48.0 (3x spike vs v0.47.1).

    When the chat response stream is closed (e.g., user cancels or session ends) while handleWritePermission is resolving permission checks, the subsequent call to trackEditIfNeeded → trackEdit → stream.externalEdit() throws "Response stream has been closed" because the stream is already invalid. The trackEditIfNeeded function was not forwarding the token parameter to editTracker.trackEdit(), so trackEdit's built-in cancellation guard at externalEditTracker.ts:50 (if token?.isCancellationRequested return) never fired.

    Culprit Commit

    3b2b5e06 by @DonJayamanne — "Update GitHub Copilot npm and permission handling (#313364)" (2026-04-30). This commit updated permission handling and introduced trackEditIfNeeded call sites that don't forward the cancellation token.

    Code Flow

    graph TD
        A["copilotcliSession.ts:1186 - permission.requested handler"] --> B["handleWritePermission - permissionHelpers.ts:112"]
        B --> C["trackEditIfNeeded - permissionHelpers.ts:341"]
        C --> D["editTracker.trackEdit(id, uris, stream) — NO token passed"]
        D --> E["trackEdit checks token?.isCancellationRequested → undefined, skips guard"]
        E --> F["stream.externalEdit() → throws 'Response stream has been closed'"]
    
    Loading

    Affected Files

    File Role
    extensions/copilot/src/extension/chatSessions/copilotcli/node/permissionHelpers.ts Producer of the bug — trackEditIfNeeded omits token param
    extensions/copilot/src/extension/chatSessions/common/externalEditTracker.ts Crash site — stream.externalEdit() throws when stream is closed

    Repro Steps

    1. Start a Copilot CLI session in VS Code
    2. Trigger a file edit that goes through permission handling
    3. Cancel the session or close the chat response while the permission check is still resolving
    4. The trackEditIfNeeded call proceeds after the stream is closed, calling stream.externalEdit() which throws

    Fix Proposal

    Bypass identified: Missing token forwarding at permissionHelpers.ts:341-344 — trackEditIfNeeded does not pass the token parameter to editTracker.trackEdit().

    Why it fails: trackEdit in externalEditTracker.ts accepts an optional token parameter and guards against cancelled tokens at line 50, but since trackEditIfNeeded never passes a token, this guard is dead code. When the stream is closed due to cancellation, stream.externalEdit() at line 66 throws.

    Fix location: permissionHelpers.ts → trackEditIfNeeded() and its 3 call sites in handleWritePermission()

    Approach:

    1. Add token?: CancellationToken parameter to trackEditIfNeeded
    2. Forward token to editTracker.trackEdit() call
    3. Pass token from all 3 call sites in handleWritePermission (lines 151, 175, 181)
    -async function trackEditIfNeeded(editTracker, toolCall, editFile, stream, logService): Promise<void> {
    +async function trackEditIfNeeded(editTracker, toolCall, editFile, stream, logService, token?: CancellationToken): Promise<void> {
       if (toolCall && stream) {
         try {
    -      await editTracker.trackEdit(toolCall.toolCallId, [editFile], stream);
    +      await editTracker.trackEdit(toolCall.toolCallId, [editFile], stream, token);
         } catch (error) { ... }
       }
     }

    And at each call site:

    -await trackEditIfNeeded(editTracker, toolCall, editFile, stream, logService);
    +await trackEditIfNeeded(editTracker, toolCall, editFile, stream, logService, token);

    Note: PR creation failed due to the vscode checkout being in a subdirectory. The fix has been committed locally on branch fix/copilot-stream-closed-316444 in the vscode-repo checkout.

    Recommended Owner

    @DonJayamanne — author of the permission handling code and all recent commits to permissionHelpers.ts.

    Generated by errors-fix · ● 85M · ◷

  5. vs-code-engineering commented on Oct 9, 2026

    @vs-code-engineering
    ContributorAuthor

    Regression Details

    • Product: VSCode (extension GitHub.copilot-chat)
    • Regression type: new (bucket-ID drift — same logical error continuing)

    An automated extension regression scan (GitHub.copilot-chat v0.69.0 vs previous stable minor v0.68.0) shows the Response stream has been closed error continuing on v0.69.0 under new bucket IDs (bucket IDs drift across builds as minification changes).

    The signature spans 10 buckets on v0.69.0, affecting ~297 users total. These buckets have been linked to this issue:

    Bucket Users Platform
    af0d0aba 156 win32
    d1b27967 58 win32
    73367850 48 win32
    6e77f0cc 37 win32
    0e676107 27 win32
    efcb18d4 24 win32
    9997786f 22 win32
    61b38c73 22 win32
    4f5d1462 22 linux
    90c6e70d 21 win32

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

    Generated by errors-regression-scan · copilot · opus48 · 283.6 AIC · ⌖ 29.3 AIC · ⊞ 8.8K · ◷

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