fix: prevent memory leak in KiloSessionPromptQueue.cancel for sessions without active tails - #10109
Conversation
…ssions without active tails The cancel() function was always incrementing and storing a version in the versions map, even for sessions with no queued prompts. Since cleanup only happens in enqueue's release phase, sessions without active tails left permanent map entries. Now cancel() checks if the session has an active tail before modifying state. If no tail exists, it cleans up any existing versions/targets/latest/activeSince entries instead of creating new ones.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Resolved Issues✅ Previously flagged (round 1): Missing test for the memory-leak scenario — resolved: dedicated test added in ✅ Previously flagged (round 2): Logic ReviewAll three aspects of the fix are correct:
Files Reviewed (3 files)
Reviewed by claude-sonnet-4.6 · 172,820 tokens |
|
Hey @IamCoder18, could you provide details about how the issue was reproduced and fix tested? Also, please consider adding a unit test to prevent the issue from happening again. |
Adds a test that verifies cancel() on a session with no active tail does not leave stale entries in the internal maps (versions, targets, latest, activeSince). Also adds _hasInternalState() debug helper to verify map cleanup.
|
Hey @johnnyeric, added the test as requested. The test verifies that calling The test:
Without the fix, step 3 fails (I've ran it and test this) because |
…queue-memory-leak fix: prevent memory leak in KiloSessionPromptQueue.cancel for sessions without active tails
Context
Fix a memory leak in
KiloSessionPromptQueue.cancel()where calling cancel on a session with no queued prompts would leave permanent entries in the module-levelversions,targets,latest, andactiveSincemaps. This occurred becausecancel()always incremented and stored a version, but cleanup only happens inenqueue's release phase.Closes #9211
Implementation
Modified
cancel()to check if the session has an active tail before modifying state. Iftails.has(sessionID)is false, the function now cleans up any existing entries inversions,targets,latest, andactiveSincemaps instead of creating new ones.Get in Touch
Discord: @IamCoder18