Description
Two separate memory leaks keep OpenCode RSS growing without bound:
-
ACP session manager never frees entries. ACPSessionManager (packages/opencode/src/acp/session.ts:9-72) pushes every new ACP session into a private Map and there is no delete or lifecycle hook tied to cancel. Each ACP IDE reconnect adds another entry plus async subscriptions from setupEventSubscriptions (acp/agent.ts:62-335). The repro script packages/opencode/script/memory/acp-session-leak.ts shows RSS climbing from ~80 MB to ~96 MB after 20k synthetic sessions even with forced GC; heap snapshots (logs/acp-session-leak-*.heapsnapshot) retain all session objects.
-
Tool compaction does not clear payloads. SessionCompaction.prune only stamps part.state.time.compacted, but the underlying state.output / attachments stay in storage. Every SessionPrompt.prompt reloads the full tool history via MessageV2.stream()/toModelMessage, so sessions with thousands of big tool outputs are re-materialized on every turn. Users report >10 GB RSS after a day because "cleared" tool results are still parsed into JS objects.
Both leaks are captured in spec/memory-leaks.md (benchmark table + repro steps). We need lifecycle cleanup for ACP sessions/subscriptions and real data eviction when compaction marks tool outputs as old.
OpenCode version
v1.0.65
Steps to reproduce
- ACP leak:
NODE_OPTIONS=--expose-gc npx tsx packages/opencode/script/memory/acp-session-leak.ts → observe RSS + session map size continuing to grow; inspect logs/acp-session-leak-*.heapsnapshot in Chrome DevTools.
- Tool-output leak: run a long chat session that repeatedly invokes
read/edit/bash on large files (or script fake tool parts) and watch process.memoryUsage() / heap snapshots. Even after compaction UI shows "Old tool result content cleared", the backing JSON still contains every output string which gets reloaded on each prompt.
Screenshot and/or share link
N/A
Operating System
Linux (container)
Terminal
tmux + bash inside Codex CLI
Description
Two separate memory leaks keep OpenCode RSS growing without bound:
ACP session manager never frees entries.
ACPSessionManager(packages/opencode/src/acp/session.ts:9-72) pushes every new ACP session into a privateMapand there is nodeleteor lifecycle hook tied tocancel. Each ACP IDE reconnect adds another entry plus async subscriptions fromsetupEventSubscriptions(acp/agent.ts:62-335). The repro scriptpackages/opencode/script/memory/acp-session-leak.tsshows RSS climbing from ~80 MB to ~96 MB after 20k synthetic sessions even with forced GC; heap snapshots (logs/acp-session-leak-*.heapsnapshot) retain all session objects.Tool compaction does not clear payloads.
SessionCompaction.pruneonly stampspart.state.time.compacted, but the underlyingstate.output/ attachments stay in storage. EverySessionPrompt.promptreloads the full tool history viaMessageV2.stream()/toModelMessage, so sessions with thousands of big tool outputs are re-materialized on every turn. Users report >10 GB RSS after a day because "cleared" tool results are still parsed into JS objects.Both leaks are captured in
spec/memory-leaks.md(benchmark table + repro steps). We need lifecycle cleanup for ACP sessions/subscriptions and real data eviction when compaction marks tool outputs as old.OpenCode version
v1.0.65
Steps to reproduce
NODE_OPTIONS=--expose-gc npx tsx packages/opencode/script/memory/acp-session-leak.ts→ observe RSS + session map size continuing to grow; inspectlogs/acp-session-leak-*.heapsnapshotin Chrome DevTools.read/edit/bashon large files (or script fake tool parts) and watchprocess.memoryUsage()/ heap snapshots. Even after compaction UI shows "Old tool result content cleared", the backing JSON still contains every output string which gets reloaded on each prompt.Screenshot and/or share link
N/A
Operating System
Linux (container)
Terminal
tmux + bash inside Codex CLI