Skip to content

Agent Host session load causes child-chat subscription storm and memory spike #332501

Description

Summary

Loading and reopening a large Agent Host session can generate thousands of duplicate child-chat subscriptions, causing a sharp renderer/transport memory spike and hundreds of MB of AHP traffic.

Reproduction

Using the session Agent Host session migration (39 subagent chats):

  1. Open the session and wait for history/Changes to settle.
  2. Open another session.
  3. Reopen the original session.

Controlled runs with isolated copies of the same profile:

Build AHP bytes Child-chat snapshots
43c9cf468f20 (good Insiders) 42.3 MB 78
fc62850c022b (bad Insiders) 343.2+ MB 1,005 retained after rotation

Bisect and root cause

A source-level bisect identified commit 38220eab177286ceaf47098a843396d351464247 (#331079):

Source revision AHP bytes Child-chat snapshots
Parent 30ad9a507bd 42.9 MB 85
38220eab177 367.7 MB 864

The triggering change is the new synchronous external-changes scope check in AgentFeedbackService._isFileInSessionScope:

if (session.externalChanges?.get().some(file => isEqual(file.uri, resourceUri))) {
    return true;
}

externalChanges is subscription-backed. Calling .get() while it is unobserved recomputes its dependencies for each visible changed-file editor, transiently acquiring and releasing all child-chat subscriptions. The target session has 39 child chats, so repeated file scope checks create a large overlapping subscribe/unsubscribe storm.

Line-level verification on 38220eab177:

  • Removing only the new externalChanges.get() check: 43.0 MB / 87 child snapshots (baseline restored).
  • Removing the separate new subagent annotation-restore await instead: 375.1 MB / 866 child snapshots (still reproduces).

Confidence in this causal attribution is very high; the immediate-parent, child, and single-expression A/B tests were all run against the same profile and automated scenario.

Metadata

Metadata

Labels

agents-windowbugIssue identified by VS Code Team member as probable bugfreeze-slow-crash-leakVS Code crashing, performance, freeze and memory leak issuesregressionSomething that used to work is now broken

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions