microsoft / microsoft/vscode

Copilot Chat: custom agents vanish from the dropdown after "renderer closed the MessagePort" (InstantiationService has been disposed)

Open
#333,132 0 comments 0 reactions 1 assignee Claimed by @roblourens View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Type: Bug

- VS Code Insiders: 1.136.0-insider (commit b7f76c1a31)
- OS: Windows 11 Pro 10.0.26200
- Extension: `github.copilot-chat` 0.35.2025120504
- Single profile (`__default__profile__`), user-level agents in `~/.copilot/agents`

### Summary

After an extension host is torn down with **`renderer closed the MessagePort`**, the Copilot Chat extension keeps handling an in-flight agent request and throws `InstantiationService has been disposed`. In that window the custom agents dropdown then only offers the built-in `Agent` — other windows in the same session, with their own extension hosts, keep working normally. `Developer: Reload Window` restores it.

This looks related to #320759 and #317276, but those reports do not include the disposal trace, so filing the log evidence separately.

### Log evidence

`~/AppData/Roaming/Code - Insiders/logs/20260828T064146/window1/exthost/exthost.log`:

```
2026-08-28 12:03:10.601 [info] Extension host terminating: renderer closed the MessagePort
2026-08-28 12:03:10.675 [error] Error: InstantiationService has been disposed
at t._throwIfDisposed (…/extensions/copilot/dist/extension.js:29:574)
at t.createInstance (…/extensions/copilot/dist/extension.js:29:1228)
at m_.getChatEndpoint (…/extensions/copilot/dist/extension.js:6729:16599)
at RQ.getResult (…/extensions/copilot/dist/extension.js:2823:9223)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async Mk._requestHandler (…/extensions/copilot/dist/extension.js:6725:1838)
at async r.$invokeAgent (…/vs/workbench/api/node/extensionHostProcess.js)
2026-08-28 12:03:10.678 [error] Error: InstantiationService has been disposed
(identical stack)
```

Immediately **before** the termination, the TypeScript language feature's server process exits in the same window:

```
at ChildProcess. (…/extensions/typescript-language-features/dist/extension.js)
at ChildProcess.emit (node:events:509:28)
at emit (node:internal/child_process:972:14)
2026-08-28 12:03:10.601 [info] Extension host terminating: renderer closed the MessagePort
```

Possibly coincidental, but the ordering was consistent in the one occurrence captured.

### This is not a normal shutdown

I checked every `exthost.log` from the last six days to rule out ordinary window closes:

| Termination reason | Count | `disposed` errors |
|---|---|---|
| `received terminate message from renderer` (normal) | 25 | 0 |
| **`renderer closed the MessagePort`** | **1** | **2** |

Only the abnormal MessagePort closure produces the error, so the correlation is clean rather than incidental noise.

### Steps to reproduce

Not deterministic. Conditions when observed:

1. Many windows open concurrently (26 `Code - Insiders.exe` processes), several with large TypeScript monorepos.
2. Chat is mid-request when the renderer drops the MessagePort.
3. That window's agents dropdown afterwards shows only `Agent`; user-level agents from `~/.copilot/agents` are gone.
4. Other windows are unaffected.
5. `Developer: Reload Window` fixes the affected window.

### Expected

Either the extension host tears down without a pending `$invokeAgent` reaching a disposed `InstantiationService`, or the request is cancelled cleanly and agent discovery re-initialises when the window recovers — rather than the window being left with no custom agents until a manual reload.

### Ruled out

- Profile mismatch — all 47 workspaces map to `__default__profile__`.
- Workspace-level overrides — no `.github/agents` or `.claude/agents`, no chat settings in `.vscode/settings.json`.
- Malformed agent files — all 9 have valid frontmatter, a `name`, no BOM, no duplicate names.
- Extension version skew — a single `copilot-chat` version installed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.