Repository navigation
Description
opencode version: 1.17.11 (bun-compiled binary)
OS: Ubuntu 22.04, Linux x86_64
Deployment: systemd service, MemoryMax=8G
Description
The opencode web server has a severe memory leak. RSS grows from ~127MB to ~4.9GB in ~20 minutes of active use. The process becomes unresponsive, health check latency increases from <5ms to >2s, and eventually it must be force-killed.
Root cause
The leak originates in the AI SDK Effect runtime bundled inside the opencode binary. Each LLM call creates a new set of event listeners on a shared EventTarget ([vY]) that are never removed after the call completes.
The MaxListenersExceededWarning fires 27+ times per session:
MaxListenersExceededWarning: Possible EventTarget memory leak detected.
11 event listeners added to [vY]. MaxListeners is undefined.
Use events.setMaxListeners() to increase limit
at overflowWarning (node:events:185:19)
at addListener (node:events:158:22)
at ~effect/Effect/evaluate (/$bunfs/root/chunk-624361m2.js:25:4492)
at runLoop (/$bunfs/root/chunk-624361m2.js:25:2045)
at evaluate (/$bunfs/root/chunk-624361m2.js:25:1435)
at runTasks (/$bunfs/root/chunk-624361m2.js:11:12793)
at afterScheduled (/$bunfs/root/chunk-624361m2.js:11:12680)
Every LLM call goes through this runtime:
llm runtime selected llm.runtime=ai-sdk llm.provider=opencode llm.model=big-pickle
Memory growth (measured)
| Time | RSS | Health check latency |
|---|---|---|
| Fresh start | 127 MB | ~5ms |
| ~10 min (moderate use) | 439 MB | ~50ms |
| ~20 min (active use) | 4,900 MB | 971ms→2.85s |
Growth rate: ~20 MB/min under moderate load, faster under heavy use (subagent parallelism).
Plugin verification
All 4 installed plugins were audited — none use EventTarget or EventEmitter:
oc-plugin-karpathy-guidelines(0.2.1) — only injects system prompt textopencode-codegraph(0.1.37) — only scenario routing + tool definitionsomf— model fallback configrtk.ts— local plugin
The leak reproduces identically regardless of plugins.
Impact
- Process becomes unresponsive after 20-40 min of active use
- Cannot gracefully shutdown (stuck in
stop-sigtermstate) - Requires SIGKILL to recover
- Memory limit (MemoryMax=8G) prevents system OOM but does not fix the leak
- All users running
opencode webfor extended periods are affected
Suggested fix location
The bundled file chunk-624361m2.js (inside the binary at /$bunfs/root/chunk-624361m2.js) contains the ~effect/Effect/evaluate function that registers listeners on the [vY] EventTarget. Each call to this function should clean up its listeners after the evaluation completes.
Activity
github-actions commentedon Jun 30, 2026
This issue might be a duplicate of existing issues. Please check:
MaxListenersExceededWarningstack trace from~effect/Effect/evaluate, same server mode context, same GB-scale memory growth patternMaxListenersExceededWarningafter web interface startsMaxListenersExceededWarningbug reportshashb27 commentedon Aug 20, 2026
Triage: linked PR does not address this issue
Cross-checking the PR linked to this issue, PR #38939 does not fix the AI-SDK Effect
EventTargetleak described here:PR #38939 — targets a different leak
fix(core): prevent allBounded listener leak via PubSub subscriptionallBoundedleak inpackages/opencode/src/server/routes/instance/httpapi/handlers/event.tsandpackages/opencode/src/share/share-next.ts), not the AI-SDK Effect runtimeEventTarget([vY]in bundledchunk-624361m2.js:25:4492) described in this issue.Net status
No open or closed PR addresses #34574. The leak is in a bundled/vendored AI SDK artifact (
chunk-624361m2.js), so a fix likely needs either:Suggested next step
A maintainer should confirm whether #34574 and #36677 are considered duplicates (same symptom, different root cause) or distinct. If distinct, #34574 still needs a dedicated fix.
(Context: I hit this while investigating memory bloat in my own opencode sessions — reported in capsule oxmiq/capsule#1762. The AI-SDK EventTarget listener leak is one of the two strongest matches for "many LLM calls = RSS growth" among the open upstream issues, alongside #35107.)
nicekit37 commentedon Sep 16, 2026
Confirming this also affects normal interactive TUI sessions on Windows — not just
opencode webon Linux.subagent_depth: 2)The warning renders as a large multi-screen error block inside the TUI conversation, which is very noisy even though the session keeps working.
Same Effect runtime frames as reported here (
~effect/Utils/internal→~effect/Effect/evaluate→runLoop), reached viagetPrompt→request→send. The dumped emitter state before the trace differs slightly from the[vY]EventTarget in the original report — it shows a stream emitter withtype: "drain", count: 11, so in the TUI path the listeners appear to accumulate on a Writable stream'sdrainevent:(The
B:/~BUN/root/...paths are the same/$bunfs/root/...virtual filesystem as in the original report — Windows renders the bundled drive asB:.)Still reproduces on 1.18.31, which is the current
latestrelease.thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊