fix: prevent responseListeners memory leak in CoreMessenger (#11901)
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.
This commit is contained in:
parent
581980e31e
commit
afb6b2111c
1 changed files with 3 additions and 2 deletions
|
|
@ -65,9 +65,10 @@ class CoreMessenger(
|
|||
responseListeners[messageId]?.let { listener ->
|
||||
listener(data)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val done = (data as? Map<String, Boolean>)?.get("done")
|
||||
val done = (data as? Map<String, Any>)?.get("done") as? Boolean
|
||||
|
||||
if (done == true) {
|
||||
// Remove unless explicitly streaming (done == false)
|
||||
if (done != false) {
|
||||
responseListeners.remove(messageId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue