Skip to content

fix: prevent responseListeners memory leak in CoreMessenger#11901

Merged
Patrick-Erichsen merged 1 commit intomainfrom
fix/response-listener-memory-leak
Mar 26, 2026
Merged

fix: prevent responseListeners memory leak in CoreMessenger#11901
Patrick-Erichsen merged 1 commit intomainfrom
fix/response-listener-memory-leak

Conversation

@RomneyDa
Copy link
Collaborator

@RomneyDa RomneyDa commented Mar 26, 2026

Summary

  • Fixes a memory leak in CoreMessenger.responseListeners where callback entries were never removed for non-streaming messages
  • Response listeners were only cleaned up when data contained "done": true, but most message types (files/changed, files/opened, autocomplete, nextEdit/*, etc.) return responses without a done field — leaking every callback permanently
  • Over a long session with heavy autocomplete and file navigation, this can accumulate hundreds of thousands of entries (estimated 40-100+ MB)
  • Fix: invert the removal logic — remove the listener by default, only retain it when done == false (streaming still in progress). This is safe for all message types:
    • Streaming responses (done: falsedone: true): listener kept during streaming, removed on completion — same as before
    • Non-streaming responses (no done field): listener removed immediately after callback — this is the fix
    • Fire-and-forget ({ _ -> } / {}): listener removed on first response — this is the fix

Related: #8085 (sidebar freezes), which identified memory pressure as a contributing factor

Test plan

  • Stream a long LLM response in the sidebar — verify it streams correctly and completes
  • Navigate between files, open/close tabs — verify no regressions
  • Use autocomplete heavily — verify suggestions still work
  • Monitor JVM heap over a long session — confirm responseListeners map stays small

Summary by cubic

Fixes a memory leak in CoreMessenger by removing response listeners by default and only keeping them during streaming (done == false). This prevents responseListeners from growing unbounded during autocomplete and file events.

  • Bug Fixes
    • Invert cleanup: remove listener when done != false; keep only while streaming.
    • Non-streaming responses (no done) and fire-and-forget calls now clean up after the first callback; streaming completion still removes on done: true.

Written for commit cf67e4d. Summary will update on new commits.

Response listeners were only removed when data contained `"done": true`,
but most message types (file events, autocomplete, nextEdit, etc.)
return responses without a `done` field. This caused every fire-and-forget
request to leak its callback lambda permanently in the map.

Over a long session with heavy autocomplete and file navigation, this
could accumulate hundreds of thousands of entries (40-100+ MB).

Fix: invert the removal logic — remove the listener by default, and
only keep it when `done == false` (i.e., a streaming response is still
in progress). This preserves existing streaming behavior while ensuring
all non-streaming responses are cleaned up immediately.
@RomneyDa RomneyDa requested a review from a team as a code owner March 26, 2026 20:52
@RomneyDa RomneyDa requested review from Patrick-Erichsen and removed request for a team March 26, 2026 20:52
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 26, 2026
@continue
Copy link
Contributor

continue bot commented Mar 26, 2026

Docs Review

No documentation updates needed for this PR.

Reason: This is an internal bug fix that addresses a memory leak in the IntelliJ extension's CoreMessenger response listener cleanup logic. The change is purely an implementation detail that doesn't affect:

  • User-facing behavior or features
  • Configuration options or settings
  • API contracts or extension points
  • Installation or setup procedures

The fix improves memory management under the hood without changing how developers interact with Continue.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 26, 2026
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Mar 26, 2026
@Patrick-Erichsen Patrick-Erichsen merged commit afb6b21 into main Mar 26, 2026
66 of 67 checks passed
@Patrick-Erichsen Patrick-Erichsen deleted the fix/response-listener-memory-leak branch March 26, 2026 21:59
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Mar 26, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants