Skip to content

fix(chat): cache language selection to prevent listener leak in chat editing snapshots (#309905)#310721

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-309905-chat-editing-listener-leak
Open

fix(chat): cache language selection to prevent listener leak in chat editing snapshots (#309905)#310721
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-309905-chat-editing-listener-leak

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

What

Prevents a listener leak triggered by ChatEditingSession.getSnapshotModel during long agent sessions.

Why

getSnapshotModel passed a fresh ILanguageSelection (from LanguageService.createByFilepathOrFirstLine) into IModelService.createModel for every snapshot. Each resulting TextModel internally subscribed (via the selection's observableFromEvent + Event.fromObservable) to the shared LanguageService.onDidChange. In long-running agent sessions the 200-listener threshold was crossed, producing the [Unhandled Error] potential listener LEAK detected telemetry reported in #309905.

How

Resolve the languageId eagerly and pass a static { languageId, onDidChange: Event.None } selection into createModel — the language of a snapshot doesn't change, so there's nothing to subscribe to. This mirrors the pattern already used elsewhere in the codebase (chatTextEditContentPart, terminal.environmentChanges, aiCustomizationManagementEditor).

Test plan

  • Added regression test getSnapshotModel does not leak LanguageService.onDidChange listeners, #309905 in src/vs/workbench/contrib/chat/test/browser/chatEditing/chatEditingService.test.ts. The test spies languageService.onDidChange, creates 25 snapshot models, and asserts that new subscriptions are fewer than the number of snapshots (previously it was 1:1).
  • npm run compile-check-ts-native passes cleanly for the changed files.

Fixes #309905

@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@jrieken

Matched files:

  • src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Unhandled Error] potential listener LEAK detected, popular

3 participants