fix(opencode): memory leaks in session handling#10392
fix(opencode): memory leaks in session handling#10392ztripez wants to merge 1 commit intoanomalyco:devfrom
Conversation
- add LRU eviction to provider caches - remove deep clone in prompt loop - add session cleanup for FileTime and ACP - fix bus subscriptions to use Instance.state disposal - delete tool output on compaction instead of just marking - add timeout to pending permission/question requests - clear processor maps on error - use array accumulation instead of string concat for streaming
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs FoundHere are PRs that may be related to or duplicate aspects of PR #10392:
These PRs may contain overlapping solutions or address the same underlying issues. You may want to review them to ensure no duplicate effort or check if this PR should incorporate/reference those fixes. |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
any hope for this? |
Addresses the remaining memory leaks identified in anomalyco#16697 by consolidating the best fixes from 23+ open community PRs into a single coherent changeset. Fixes consolidated from PRs: anomalyco#16695, anomalyco#16346, anomalyco#14650, anomalyco#15646, anomalyco#13186, anomalyco#10392, anomalyco#7914, anomalyco#9145, anomalyco#9146, anomalyco#7049, anomalyco#16616, anomalyco#16241 - Plugin subscriber stacking: unsub before re-subscribing in init() - Subagent deallocation: Session.remove() after task completion - SSE stream cleanup: centralized cleanup with done guard (3 endpoints) - Compaction data trimming: clear output/attachments on prune - Process exit cleanup: Instance.disposeAll() with 5s timeout - Serve cmd: graceful shutdown instead of blocking forever - Bash tool: ring buffer with 10MB cap instead of O(n²) concat - LSP index teardown: clear clients/broken/spawning on dispose - LSP open-files cap: evict oldest when >1000 tracked files - Format subscription: store and cleanup unsub handle - Permission/Question clearSession: reject pending on session delete - Session.remove() cleanup chain: FileTime, Permission, Question - ShareNext subscription cleanup: store unsub handles, cleanup on dispose - OAuth transport: close existing before replacing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Fixes #5363
What does this PR do?
Fixes memory leaks in session handling that cause unbounded memory growth during long conversations.
Key fixes:
Instance.state()disposal pattern to prevent listener leaks+=for streaming text/reasoning/bash output to avoid creating intermediate string objectsHow did you verify your code works?
join()only when needed for updatesTesting recommendations: