Repository navigation
Description
Bug Description
When two or more extensions each register a large number of .chatAgent.md and .chatSkill.md prompt files (e.g. 49 agents + 17 skills total), VS Code enters a sustained CPU active state (does not idle) that never recovers. The Problems panel also flickers continuously with validation warnings appearing and disappearing.
Root Cause
An infinite feedback loop forms between MainThreadChatAgents2 (VS Code core) and the extension host:
PromptsServicefiresonDidChangeCustomAgentsMainThreadChatAgents2._pushCustomAgents()serializes agent DTOs and callsthis._proxy.$acceptCustomAgents(dtos)to the extension host- The extension (e.g. GitHub Copilot Chat) receives the agents, re-parses all prompt files, and fires its provider's
onDidChangeCustomAgentsevent - The extension host forwards this back to the main thread via
$onDidChangePromptFiles(handle) PromptsServiceinvalidates its cache and firesonDidChangeCustomAgentsagain- GOTO 1 — infinite ping-pong loop
The same cycle applies to _pushInstructions() and _pushSkills().
Each iteration involves full IPC serialization of all agent/skill/instruction DTOs, causing sustained CPU usage that never subsides.
Reproduction Steps
- Install two VS Code extensions that each contribute many
.chatAgent.mdfiles via thechatAgentsFolderpackage.json contribution point (e.g. one extension with ~39 agents + 11 skills, another with ~10 agents + 6 skills) - Open a workspace with both extensions enabled:
- Observe: CPU usage is high when vscode loads, never seems to be able to idle after startup.
- The Problems panel flickers continuously as prompt validation runs repeatedly
Notes:
- Either extension in the gif above can be disabled and vs code will act as normal.
- If the disabled extension is re-enabled then vs code also works as normal until reload. Seems that the issue is only if window startup contains many agents/skills being loaded at once. Once its out of the loop it is fine.
Expected Behavior
CPU should return to idle after extensions finish registering their prompt files. The push cycle should terminate once the extension host already has the current set of agents/skills/instructions.
Environment
- VS Code: Insiders (latest)
- OS: Windows 11
- Extensions: Any two+ extensions contributing many chatAgent/chatSkill prompt files
Proposed Fix
Add URI-set deduplication to _pushCustomAgents(), _pushInstructions(), and _pushSkills() in MainThreadChatAgents2. Before pushing to the extension host, compute a sorted string key from the current URIs and compare to the last-pushed key. If unchanged, suppress the push. This breaks the loop after at most 2 iterations (initial push + one bounce-back that matches).

Activity
aeschli commentedon Mar 25, 2026
Thanks for the report.
Are you sure about
I don't see that. Don Jayamanne (@DonJayamanne) The CLI is the only consumer of the
chat.onDidChangeCustomAgentsso far. It is not a ChatCustomAgentProvider itselfe, so I don't see that loop.But I have a suspicion on what the problem could be. The problem is that there is only a maximum of 50 TextDocuments that the extension host will keep. We listen to this TextDocuments dispose.
Wolfe1 commentedon Mar 25, 2026
Martin Aeschlimann (@aeschli) I am not to be entirely honest but it does seem to be based on some sort of threshold like you are suggesting.
While generating the issue it seems that I duplicated it from copilot so I have closed the duplicate, updated this issue description, and attached a potential fix. Of course its probably more of a band-aid rather than a full fix for the real underlying issue here.
Wolfe1 commentedon Mar 25, 2026
Had copilot dig into it a bit based on your comment, does this track?
The correct step 3 (replacing the issue's incorrect claim about the provider re-firing) is:
ChatCustomAgentsServicelistens tovscode.chat.onDidChangeCustomAgentsand callsvscode.workspace.openTextDocument(uri)for every agent URI to parse them. With 50+ prompt files, this exceeds theBoundModelReferenceCollection._maxSizeof 50, causing the oldest model references to be evicted/disposed.The key distinction: it's not the provider re-firing
onDidChangeCustomAgentsthat causes the bounce-back. It's the model eviction from opening too many text documents. The evicted models triggeronModelRemoved→ModelChangeTrackerfires a prompt-type change event →cachedCustomAgentsinvalidates →PromptsService.onDidChangeCustomAgentsfires → loop restarts.So the full corrected loop is:
PromptsService.onDidChangeCustomAgentsfires_pushCustomAgents()sends$acceptCustomAgents(dtos)to ext hostvscode.chat.onDidChangeCustomAgentsAPI eventopenTextDocument(), exceeding the 50-model cap → old models get evictedModelChangeTrackerdetects evicted agent-type models → invalidatescachedCustomAgentsPromptsService.onDidChangeCustomAgentsfires again and the loop restartsfix: stop model removal from invalidating prompt caches
Wolfe1 commentedon Mar 27, 2026
Martin Aeschlimann (@aeschli) Not sure if this is helpful feedback or not but regrading microsoft/vscode-copilot-chat#4733 (I saw it was marked as a temporary fix for this issue), it has resolved my issue but only on the stable 0.41.2 github copilot chat release. If I switch to the pre-release (0.42.2026032701 at the time) then the high cpu / no idle behavior persists.
I assume this is because you said this change would be reverted for vscode 1.114 anyway so thats why it was only merged to the release branch?
aeschli commentedon Mar 29, 2026
Fixed by #305662