Skip to content

fix: consolidate memory leak fixes from #14650 and #8953#15435

Open
tda1017 wants to merge 5 commits intoanomalyco:devfrom
tda1017:fix/memory-leaks-consolidated
Open

fix: consolidate memory leak fixes from #14650 and #8953#15435
tda1017 wants to merge 5 commits intoanomalyco:devfrom
tda1017:fix/memory-leaks-consolidated

Conversation

@tda1017
Copy link

@tda1017 tda1017 commented Feb 28, 2026

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:

  1. Subagent session deallocation (tool/task.ts) — Calls Session.remove() after task completion. Previously subagent sessions were never cleaned up, causing GB-scale memory growth.

  2. Delta string cap (event-reducer.ts) — Caps accumulated part field strings at 1MB with FIFO eviction.

  3. Bash output streaming (tool/bash.ts) — Streams command output to tmpfile when >50KB, preventing O(n²) memory growth for large outputs.

  4. SSE buffer guard (serverSentEvents.gen.ts) — 10MB limit prevents unbounded growth during stalled streams.

  5. MCP OAuth transport TTL (mcp/index.ts) — 5-minute auto-eviction for stale OAuth entries.

  6. TUI event listener cleanup (app.tsx, session/index.tsx, prompt/index.tsx) — Properly unsubscribes 8 event listeners on component unmount.

  7. LSP diagnostics cap (lsp/client.ts) — 2,000-file cap with FIFO eviction.

  8. 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 kryptobaseddev@users.noreply.github.com
Co-authored-by: Colin Walters walters@verbum.org

kryptobaseddev and others added 3 commits February 28, 2026 15:14
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>
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 28, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak

3 participants