fix: resolve OOM crashes from memory leaks in renderer process#12975
Draft
fix: resolve OOM crashes from memory leaks in renderer process#12975
Conversation
Clean up three memory leak sources during active agent/tool usage: 1. Clear globalActiveToolCalls static map on stream end/abort 2. Remove abortMap entries after normal stream completion 3. Evict inactive topic caches to free message/block entities Fixes #12925
Collaborator
Author
|
Note This comment was translated by Claude. A simple fix that needs to be tested. Original Contenta simple fix and need to be tested |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Fixes #12925: Resolves three memory leak sources causing out-of-memory crashes during active agent/tool usage in the renderer process.
Before: Global maps and Redux caches accumulated entries indefinitely, causing heap growth until OOM termination.
After: Stream completion and topic switching now properly clean up resources, stabilizing heap memory.
Why we need it and why it was done in this way
Root causes identified:
globalActiveToolCalls(static Map): Entries added on tool-input-start but only removed on tool-result/error. Aborted streams left orphaned entries forever.abortMap: Entries added per message but only removed on user abort. Normal stream completion never cleaned up entries.messageIdsByTopicandentitiesgrew unbounded as users viewed topics.Fixes applied:
ToolCallChunkHandler.clearAll()static method, called inAiSdkToChunkAdapter.readFullStream()finally block.cleanupAbortController(id)utility, called in bothfetchAndProcessAgentResponseImplandfetchAndProcessAssistantResponseImplfinally blocks.evictTopicCachereducer and eviction logic inloadTopicMessagesThunkto keep only 5 most-recently-accessed topics in memory.Why this approach:
Breaking changes
None. All changes are internal cleanup; no public APIs modified.
Checklist