Description
Bug Description
Several memory leaks occur during long-running opencode sessions, causing RSS to grow continuously:
-
AsyncQueue never terminates (
util/queue.ts) -[Symbol.asyncIterator]loops forever with no close mechanism, preventing GC of consumers. -
Bash tool unbounded string concatenation (
tool/bash.ts:167-189) - stdout/stderr appended viaoutput += chunk.toString()with no size limit. Commands producing large output (e.g.,find /) cause unbounded memory growth. -
LSP diagnostics Map never cleared (
lsp/client.ts:51) -diagnosticsMap accumulates entries indefinitely.shutdown()disposes the connection but doesn't clear the map. -
Bus subscriptions Map not cleared on dispose (
bus/index.ts) - Instance dispose callback fires wildcard subscribers but never callssubscriptions.clear(). -
PTY buffer string concatenation (
pty/index.ts:136-150) -session.buffer += datathensession.buffer.slice(-BUFFER_LIMIT)causes repeated large string allocation and GC pressure. -
Instance.disposeAll() not called on process exit (
index.ts) - The mainfinallyblock callsprocess.exit()without disposing instances, leaking subprocess handles.
Reproduction
- Start opencode, run a command producing large output (
find / -name "*.ts") - Monitor with
top -pid <PID>- RSS grows without bound - Idle for 10+ minutes - memory does not decrease
Environment
- opencode v1.1.36
- macOS Darwin 24.6.0
- Bun 1.3.5
Activity
github-actions commentedon Jan 27, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
KaranjotVendal commentedon Feb 3, 2026
I believe I have encountered the same issue. Seems like the following PR #11717 and PR #10914 seems to be fixing the solution.
cdenneen commentedon Feb 18, 2026
Looks like people haven't gotten a fix working for all the memory issues. Anyone see improvement with this? My opencode serve is killing my server multiple times per day requiring hard reboot.
fix: address 6 memory leaks for long-running sessions
thdxr commentedon Apr 2, 2026
Closing in favor of #20695 where we're collecting all memory-related problems. Please follow that issue for updates.