GeezerVison is showing github.com — fix: consolidate memory leak fixes from #14650 and #8953 by tda1017 · Pull Request #15435 · anomalyco/opencode
Conversation
tda1017
commented
Feb 28, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #9385
Relates to #7046, #9151
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
This PR consolidates memory leak fixes from two existing PRs that have been open for a while:
All credit goes to the original authors. I'm submitting this to help move these fixes forward.
Key fixes included:
-
Subagent session deallocation (tool/task.ts) — Calls Session.remove() after task completion. Previously subagent sessions were never cleaned up, causing GB-scale memory growth.
-
Delta string cap (event-reducer.ts) — Caps accumulated part field strings at 1MB with FIFO eviction.
-
Bash output streaming (tool/bash.ts) — Streams command output to tmpfile when >50KB, preventing O(n²) memory growth for large outputs.
-
SSE buffer guard (serverSentEvents.gen.ts) — 10MB limit prevents unbounded growth during stalled streams.
-
MCP OAuth transport TTL (mcp/index.ts) — 5-minute auto-eviction for stale OAuth entries.
-
TUI event listener cleanup (app.tsx, session/index.tsx, prompt/index.tsx) — Properly unsubscribes 8 event listeners on component unmount.
-
LSP diagnostics cap (lsp/client.ts) — 2,000-file cap with FIFO eviction.
-
Additional — AsyncQueue termination, bus cleanup, PTY chunking, shutdown disposal.
How did you verify your code works?
Built locally and ran extended sessions. The original PRs (#14650, #8953) contain detailed testing methodology — @kryptobaseddev ran 2.5 hour stress tests showing RSS stabilized at ~2.5GB vs previous 25GB+ growth.
Screenshots / recordings
N/A - backend memory fixes, no UI changes.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Co-authored-by: Keaton Hoskins [email protected]
Co-authored-by: Colin Walters [email protected]
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
syunaht, Piping, and zzzzz1111139 reacted with thumbs up emoji
Fixes subagent session deallocation, delta string cap, tool output on compact,
SSE buffer guard, MCP OAuth transport TTL, pending permissions cleanup,
TUI event listener cleanup, LSP diagnostics cap, and AbortSignal listener.
Original work from PR anomalyco#14650 by @kryptobaseddev
Co-authored-by: Keaton Hoskins <[email protected]>
Stream command output directly to a temp file when it exceeds threshold,
avoiding memory bloat for commands with huge output. Adds output_filter
param for regex-based line filtering.
Original work from PR anomalyco#8953 by @cgwalters
Co-authored-by: Colin Walters <[email protected]>
…down disposal
Additional memory leak fixes for queue termination, event bus cleanup,
PTY output chunking, and proper shutdown disposal.
Co-authored-by: Keaton Hoskins <[email protected]>
Co-authored-by: Colin Walters <[email protected]>
This was referenced Feb 28, 2026
|
The following comment was made by an LLM, it may be inaccurate:
Related PRs Found
The current PR (#15435) is a consolidation of two existing PRs that address specific memory leak issues:
Primary Sources (being consolidated):
Related Memory Leak Fixes (addressing similar issues):
These related PRs address similar memory management concerns across different subsystems (MCP servers, LSP diagnostics, permissions cleanup, subscriptions). While #15435 is specifically consolidating #14650 and #8953, the other PRs represent parallel memory leak fix efforts that may warrant review for consistency or potential interaction effects.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task_id resumability is currently broken: we delete subagent sessions immediately after completion (Session.remove(session.id)), but the tool contract/output still say the same task_id resumes the session. Could we preserve resumability instead of deleting the session right away?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
could you also please fix the merge conflicts
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@nexxeln Merge conflicts resolved! The branch is now up to date with upstream/dev. Please take another look when you have a chance. Thanks!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
really need this feature and previous work merged into tools!! current opencode eats all memory of my machine!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Memory leak
Uh oh!
There was an error while loading. Please reload this page.
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.
|