Skip to content

High CPU usage when multiple extensions register many chatAgent/chatSkill prompt files simultaneously #304857

Closed

Description

@Wolfe1

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:

  1. PromptsService fires onDidChangeCustomAgents
  2. MainThreadChatAgents2._pushCustomAgents() serializes agent DTOs and calls this._proxy.$acceptCustomAgents(dtos) to the extension host
  3. The extension (e.g. GitHub Copilot Chat) receives the agents, re-parses all prompt files, and fires its provider's onDidChangeCustomAgents event
  4. The extension host forwards this back to the main thread via $onDidChangePromptFiles(handle)
  5. PromptsService invalidates its cache and fires onDidChangeCustomAgents again
  6. 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

  1. Install two VS Code extensions that each contribute many .chatAgent.md files via the chatAgentsFolder package.json contribution point (e.g. one extension with ~39 agents + 11 skills, another with ~10 agents + 6 skills)
  2. Open a workspace with both extensions enabled:

Image

  1. Observe: CPU usage is high when vscode loads, never seems to be able to idle after startup.
  2. 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

  1. aeschli commented on Mar 25, 2026

    @aeschli
    Contributor

    Thanks for the report.
    Are you sure about

    The extension (e.g. GitHub Copilot Chat) receives the agents, re-parses all prompt files, and fires its provider's onDidChangeCustomAgents event

    I don't see that. Don Jayamanne (@DonJayamanne) The CLI is the only consumer of the chat.onDidChangeCustomAgents so 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.

  2. Wolfe1 commented on Mar 25, 2026

    @Wolfe1
    Author

    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.

  3. Wolfe1 commented on Mar 25, 2026

    @Wolfe1
    Author

    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:

    1. Copilot Chat's ChatCustomAgentsService listens to vscode.chat.onDidChangeCustomAgents and calls vscode.workspace.openTextDocument(uri) for every agent URI to parse them. With 50+ prompt files, this exceeds the BoundModelReferenceCollection._maxSize of 50, causing the oldest model references to be evicted/disposed.

    The key distinction: it's not the provider re-firing onDidChangeCustomAgents that causes the bounce-back. It's the model eviction from opening too many text documents. The evicted models trigger onModelRemoved → ModelChangeTracker fires a prompt-type change event → cachedCustomAgents invalidates → PromptsService.onDidChangeCustomAgents fires → loop restarts.

    So the full corrected loop is:

    1. PromptsService.onDidChangeCustomAgents fires
    2. _pushCustomAgents() sends $acceptCustomAgents(dtos) to ext host
    3. Ext host fires vscode.chat.onDidChangeCustomAgents API event
    4. Copilot Chat parses all agent URIs via openTextDocument(), exceeding the 50-model cap → old models get evicted
    5. ModelChangeTracker detects evicted agent-type models → invalidates cachedCustomAgents
    6. PromptsService.onDidChangeCustomAgents fires again and the loop restarts
  4. added a commit that references this issue on Mar 26, 2026
    52f3534
  5. Wolfe1 commented on Mar 27, 2026

    @Wolfe1
    Author

    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?

  6. aeschli commented on Mar 29, 2026

    @aeschli
    Contributor

    Fixed by #305662

  7. added
    chat-customizations
    on Mar 29, 2026
  8. locked and limited conversation to collaborators on May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

chat-customizationson-testplanperf

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions