GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — fix: resolve memory leak issues across multiple subsystems by kryptobaseddev · Pull Request #14650 · anomalyco/opencode ConversationIssue for this PRCloses #9385 Type of change
What does this PR do?Fixes 10 of the 15 memory leak sources tracked across issues #9385, #7046, #9151, and PR #14635. The two dominant drivers of unbounded RSS growth were subagent sessions never being deallocated (I-9385-A) and message delta strings accumulating without any cap (event-reducer). Together these caused observed GB-scale growth in long-running sessions. Changes by file: Subagent 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 ( AbortSignal listener ( How did you verify your code works?Built a standalone binary ( Results:
The previous behavior (per issue reports) showed continuous unbounded growth toward 25+ GB RSS under similar workloads. Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Addresses 6 of the 10 open issues from the memory-leak work plan
(L-01, L-02, L-03, L-04, I-7046-B, I-7046-D).
L-01 (CRITICAL) — event-reducer.ts: cap accumulated delta string at 1 MB
per part field; drops oldest bytes on overflow rather than growing the
V8 heap without bound. Primary driver of observed 25 GB RSS growth.
L-02 (CRITICAL) — serverSentEvents.gen.ts (v1 + v2): guard the SSE
read loop with a 10 MB MAX_BUFFER_SIZE; throws BufferOverflowError
before the string can grow unbounded during stalled or large streams.
L-03 (HIGH) — mcp/index.ts: replace bare pendingOAuthTransports.set/
delete with helper functions that attach a 5-minute TTL timer per
entry. Stale transports from abandoned or failed OAuth flows are now
automatically evicted. Timer state is cleared on state teardown.
L-04 (LOW) — sdk/js server.ts (v1 + v2): pass { once: true } to the
AbortSignal "abort" listener added during server startup. The listener
is now auto-removed after firing, eliminating long-lived accumulation
on signals that outlive the startup promise.
I-7046-B (HIGH) — lsp/client.ts: enforce a 2 000-file cap on the
diagnostics Map and a 1 000-file cap on the open-files tracking
object. Oldest entries are evicted (FIFO) on overflow; evicted files
re-open cleanly on next access.
I-7046-D (MEDIUM) — permission/next.ts + session/index.ts: add
PermissionNext.clearSession(sessionID) which rejects and removes all
pending permission requests keyed to a session. Session.remove() now
calls clearSession() before the DB delete, so short-lived subagent
sessions no longer leave dangling permission entries.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… leaks Addresses the 4 remaining high-priority memory leak issues from the work plan (I-9385-A, I-7046-A, PR-14635, I-7046-C partial). I-9385-A (CRITICAL, Priority anomalyco#1) — tool/task.ts: call Session.remove() after extracting subagent task output. This fires the session.deleted event, which triggers cleanupSessionCaches() in the event-reducer — freeing all in-memory messages, parts, diffs, permissions, and status for the subagent session. The task_id in the output becomes a dead reference; if the LLM tries to resume, Session.get() fails gracefully and a fresh session is created. Validated: the cleanup infrastructure already existed but was never invoked for subagent sessions. I-7046-A (CRITICAL, Priority anomalyco#3) — session/compaction.ts: clear part.state.output and part.state.attachments when pruning compacted tool parts. Previously, prune() set time.compacted but left the full output string in both the DB row and the in-memory store. toModelMessages already substituted "[Old tool result content cleared]" for compacted parts — this change aligns stored data with that behavior, freeing the large strings from memory and disk. PR-14635 (HIGH, Priority anomalyco#4) — TUI event listener cleanup: - app.tsx: save the unsubscribe functions returned by all 6 sdk.event.on() calls; call them in a single onCleanup() handler. Previously, onCleanup was not even imported. - routes/session/index.tsx: save and clean up the message.part.updated listener. This component mounts/unmounts during session navigation, so each navigation previously added a duplicate listener. - component/prompt/index.tsx: save and clean up the PromptAppend listener. Same mount/unmount pattern as the session component. I-7046-C (partial) — the TUI event listener fixes above cover the most impactful instances of the missing-dispose pattern. A full audit of all subscribe() call sites remains as follow-up work. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
This was referenced
Closed
Closed
Closed
3 of 6 tasks
3 of 6 tasks
tda1017
pushed a commit
to tda1017/opencode
that referenced
this pull request
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]>
3 of 6 tasks
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
This was referenced
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
3 of 6 tasks
brendandebeasi
pushed a commit
to brendandebeasi/opencode
that referenced
this pull request
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, - 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 <[email protected]>
binarydoubling
added a commit
to binarydoubling/opencode
that referenced
this pull request
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, - 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 <[email protected]>
3 of 6 tasks
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
3 tasks done
rubend056
pushed a commit
to rubend056/opencode
that referenced
this pull request
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, - 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 <[email protected]>
3 tasks done
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Memory leakUh 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. | |||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |