-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
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
- ACP leak:
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. - Tool-output leak: run a long chat session that repeatedly invokes
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