Skip to content

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

Open

Description

@vs-code-engineering

Error Message

unhandlederror-Response stream has been closed

Stack Trace

Error: Response stream has been closed 	at t._push (<REDACTED: user-file-path>/.vscode\extensions\github.copilot-chat-0.45.1\dist\extension.js:1726:24933) 	at t.push (<REDACTED: user-file-path>/.vscode\extensions\github.copilot-chat-0.45.1\dist\extension.js:1726:26055) 	at t._push (<REDACTED: user-file-path>/.vscode\extensions\github.copilot-chat-0.45.1\dist\extension.js:1726:24694) 	at t.progress (<REDACTED: user-file-path>/.vscode\extensions\github.copilot-chat-0.45.1\dist\extension.js:1726:25869) 	at <REDACTED: user-file-path>/.vscode\extensions\github.copilot-chat-0.45.1\dist\extension.js:6879:30682

Details

Property Value
Bucket ID 60c003f2-03fc-c1f8-dd72-d6e6c0660070
Extension Version 0.45.1
Last Seen Sun Apr 26 2026 23:55:04 GMT+0000 (Coordinated Universal Time)
Platforms win32, darwin, linux
Product VSCode

This issue was automatically created from the VS Code Errors Dashboard

Activity

  1. added
    bug
    error-telemetry
    on Apr 27, 2026
  2. vs-code-engineering commented on Apr 27, 2026

    @vs-code-engineering
    Author
  3. vs-code-engineering commented on Apr 27, 2026

    @vs-code-engineering
    ContributorAuthor

    🔍 Error Investigation

    Summary

    The GitHub.copilot-chat extension encounters "Response stream has been closed" when it attempts to push data (via progress(), push(), or other stream methods) to a ChatAgentResponseStream that has already been closed. This is a race condition between the extension's asynchronous response generation and the stream lifecycle managed by VS Code's extension host. The error has been present across many extension versions (0.38.x through 0.45.1) with 56,900 total hits affecting 23,368 users, and is flagged as a stable-channel anomaly indicating a recent spike.

    Culprit Commit

    No commit range was provided in the issue or comments (the issue was just created with no regression scan follow-up yet). The error is a long-standing race condition present across many extension versions — it is not attributable to a single commit. The hit count has been growing steadily:

    Extension Version Hits Users
    0.39.x ~4,500 ~2,600
    0.42.x ~13,900 ~4,900
    0.43.0 10,563 4,161
    0.44.x ~18,400 ~10,100
    0.45.1 3,360 (still accumulating) 1,928

    Code Flow

    sequenceDiagram
        participant Ext as Copilot Chat Extension
        participant API as ChatAgentResponseStream (extHostChatAgents2.ts)
        participant Host as $invokeAgent
    
        Host->>Ext: agent.invoke(request, context, stream, token)
        Ext->>API: stream.progress(value) / stream.push(part)
        Note over API: ✅ Stream open, data forwarded
    
        Note over Host: ⚠️ CancellationToken fires<br/>(user stops, navigates away, etc.)
        Host->>Host: raceCancellationWithTimeout(1000ms)
        Note over Host: Wait 1000ms grace period...
        Host->>API: finally { stream.close() }
        Note over API: _isClosed = true
    
        Ext->>API: stream.progress(value) [async continuation]
        Note over API: 💥 throwIfDone() →<br/>"Response stream has been closed"
    
    Loading

    Affected Files

    File Role
    src/vs/workbench/api/common/extHostChatAgents2.ts:85 Crash site — throwIfDone() throws "Response stream has been closed"
    src/vs/workbench/api/common/extHostChatAgents2.ts:998 Race origin — raceCancellationWithTimeout(1000, ...) races task against cancellation
    src/vs/workbench/api/common/extHostChatAgents2.ts:1046 Stream close — finally { stream?.close() } sets _isClosed = true
    github.copilot-chat/dist/extension.js Extension code — async handler continues writing after close

    Repro Steps

    1. Open VS Code with Copilot Chat extension (any version 0.38+)
    2. Start a Copilot Chat conversation that triggers a long streaming response (e.g., complex code generation)
    3. Cancel the request while the response is still streaming — either by clicking the stop button, starting a new message, or navigating away from the chat
    4. The cancellation token fires, but the extension's async LLM token processing may still have pending microtasks or promises that attempt to call stream.progress() after the 1000ms grace period expires
    5. The error is non-deterministic and depends on timing — it's more likely with slower network responses or during tool invocations that produce multiple async progress updates

    Fix Proposal

    Two complementary approaches, ideally both:

    1. VS Code core — graceful close (primary fix)
    Fix location: src/vs/workbench/api/common/extHostChatAgents2.ts → throwIfDone()
    Approach: Instead of throwing an error when the stream is closed, silently ignore the write (or log a warning). The throwIfDone pattern at line 83-88 throws an Error that gets caught by the extension host error telemetry, generating noise. Since the stream closure is an expected lifecycle event (cancellation), writes after close should be a no-op, not a thrown error. This would eliminate all hits for this bucket without any behavior change — the data would simply be discarded since the response is already being abandoned.

    2. Copilot Chat extension — check cancellation before writes
    Fix location: github.copilot-chat extension's stream wrapper (the _push/push/progress methods seen in the stack trace)
    Approach: Before calling VS Code's stream.progress() or stream.push(), check token.isCancellationRequested and return early. This is a defensive check that prevents the extension from hitting the VS Code error path entirely.

    Recommended Owner

    @roblourens — owns both the Chat Participant API in VS Code (extHostChatAgents2.ts) and the copilot-chat extension's agentic loop, making them the ideal owner to address both sides of this race condition.

    Generated by errors-investigate · ● 8.2M · ◷

  4. added
    ai-generated
    ai-analyzed
    on Apr 28, 2026
  5. vs-code-engineering commented on May 8, 2026

    @vs-code-engineering
    ContributorAuthor

    Related Error Buckets

    These additional error buckets are tracked by this issue (v0.47.2026050401):

    Bucket ID Error Message Version
    0c0358ec unhandlederror-Response stream has been closed 0.47.2026050401

    Same error pattern as bucket 60c003f2 tracked in this issue — "Response stream has been closed" in chatResponseStreamImpl.ts. This bucket originates from the Agents product stream (16 users on darwin).

    Generated by errors-triage · ● 4.2M · ◷

  6. vs-code-engineering commented on May 11, 2026

    @vs-code-engineering
    ContributorAuthor

    Related Error Buckets

    These additional error buckets are tracked by this issue (v0.48.2026050506):

    Bucket ID Error Message Version
    0cf8b951 unhandlederror-Response stream has been closed 0.48.2026050506

    Same error pattern — "Response stream has been closed" in trackEdit/gQt/UGn code path within the Copilot extension. This bucket affects 16 users on win32 (v0.48.2026050506) and is increasing across recent versions. Related to bucket 0c0358ec (same code path, darwin platform).

    Trend: Increasing since v0.46.2026042303 (1 → 16 users across 6 extension versions).

    Generated by errors-triage · ● 4.6M · ◷

  7. vs-code-engineering commented on Oct 1, 2026

    @vs-code-engineering
    Author
  8. vs-code-engineering commented on Oct 2, 2026

    @vs-code-engineering
    Author
  9. vs-code-engineering commented on Oct 7, 2026

    @vs-code-engineering
    ContributorAuthor

    Related Error Buckets

    The stable-anomaly scan comparing extension GitHub.copilot-chat 0.67.0 → 0.68.0 surfaced one additional Response stream has been closed bucket that matches this issue's existing _push/push/progress stream-write race. It has been linked to this issue (not filed as a new issue) and is distinct from the buckets noted in the prior 0.68.0 comments (24105cfa/62b55893/a58b9aea and 25b8e9d8/69d9bfbc).

    These additional error buckets are tracked by this issue (v0.68.0):

    Bucket ID Users Platform Version
    25b99b55 182 linux, darwin 0.68.0

    Same root cause as this issue — content pushed to an already-closed response stream (t._push/t.push/t.progress). Flagged new in 0.68.0 due to bucket-ID drift from minification changes, not a genuinely new defect. No separate issue was filed.

    Generated by errors-stable-scan · copilot · opus48 · 190.3 AIC · ⌖ 34.5 AIC · ⊞ 12.6K · ◷

  10. vs-code-engineering commented on Oct 19, 2026

    @vs-code-engineering
    ContributorAuthor

    Regression Details

    • Product: VSCode (extension GitHub.copilot-chat)
    • Regression type: new bucket IDs for a continuing error family
    • Baseline: 0.67.0
    • Current: 0.70.0

    These additional error buckets are tracked by this issue (v0.70.0):

    Bucket Users Path
    2fd85354 192 executePostToolUseHook
    376d6042 83 executePostToolUseHook
    42ef7b48 35 executePostToolUseHook
    cc36c158 86 _push / push / progress
    09c2e9d8 69 _push / push / progress
    99055981 68 _push / push / progress
    3907558c 61 _push / push / progress
    83ee61bc 48 _push / push / progress
    43febc43 42 _push / push / progress
    787003de 30 _push / push / progress
    29769f52 30 _push / push / progress
    d8f71bd9 22 _push / push / progress

    The deminified frames match the existing chatResponseStreamImpl.ts stream-write race, including the already documented post-tool-use hook variant. These are bucket-ID drift, not a distinct defect.

    Generated by errors-regression-scan · copilot · gpt60 · 158.9 AIC · ⌖ 9.3 AIC · ⊞ 22.1K · ◷

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