fix: consolidate memory leak fixes from #14650 and #8953#15435
Open
tda1017 wants to merge 5 commits intoanomalyco:devfrom
Open
fix: consolidate memory leak fixes from #14650 and #8953#15435tda1017 wants to merge 5 commits intoanomalyco:devfrom
tda1017 wants to merge 5 commits intoanomalyco:devfrom
Conversation
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 <kryptobaseddev@users.noreply.github.com>
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 <walters@verbum.org>
…down disposal Additional memory leak fixes for queue termination, event bus cleanup, PTY output chunking, and proper shutdown disposal. Co-authored-by: Keaton Hoskins <kryptobaseddev@users.noreply.github.com> Co-authored-by: Colin Walters <walters@verbum.org>
This was referenced Feb 28, 2026
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Related PRs FoundThe 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. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
6 tasks
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.
Issue for this PR
Closes #9385
Relates to #7046, #9151
Type of change
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) — CallsSession.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
Co-authored-by: Keaton Hoskins kryptobaseddev@users.noreply.github.com
Co-authored-by: Colin Walters walters@verbum.org