You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory leak in AI SDK Effect runtime — EventTarget listeners never cleaned up #34574
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)
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 text
opencode-codegraph (0.1.37) — only scenario routing + tool definitions
omf — model fallback config
rtk.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-sigterm state)
Requires SIGKILL to recover
Memory limit (MemoryMax=8G) prevents system OOM but does not fix the leak
All users running opencode web for 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.
Title: fix(core): prevent allBounded listener leak via PubSub subscription
PR body footer says "Closes core: long-lived V2 server enters persistent allocation loop #36677" (V2 PubSub allBounded leak in packages/opencode/src/server/routes/instance/httpapi/handlers/event.ts and packages/opencode/src/share/share-next.ts), not the AI-SDK Effect runtime EventTarget ([vY] in bundled chunk-624361m2.js:25:4492) described in this issue.
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:
An upstream AI-SDK dependency bump (if the listener leak is fixed in a newer SDK version), or
A wrapper in opencode that removes listeners after each LLM evaluation completes.
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.)
Confirming this also affects normal interactive TUI sessions on Windows — not just opencode web on Linux.
opencode version: 1.18.31 (bun-compiled binary, installed via npm)
OS: Windows 11 x64, Windows Terminal
Context: TUI session with heavy subagent parallelism (multiple subagents spawned concurrently, 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 via getPrompt → request → send. The dumped emitter state before the trace differs slightly from the [vY] EventTarget in the original report — it shows a stream emitter with type: "drain", count: 11, so in the TUI path the listeners appear to accumulate on a Writable stream's drain event:
at overflowWarning (node:events:185:19)
at addListener (node:events:158:22)
at once (node:events:200:36)
at <anonymous> (B:/~BUN/root/chunk-k9zx24wq.js:69:2280)
at new Promise (1:11)
at send (B:/~BUN/root/chunk-k9zx24wq.js:69:2131)
at <anonymous> (B:/~BUN/root/chunk-k9zx24wq.js:67:14427)
at new Promise (1:11)
at request (B:/~BUN/root/chunk-k9zx24wq.js:67:12703)
at getPrompt (B:/~BUN/root/chunk-k9zx24wq.js:67:29206)
at ~effect/Utils/internal (B:/~BUN/root/chunk-nhtrqkcr.js:8:1579)
at <anonymous> (B:/~BUN/root/chunk-nhtrqkcr.js:25:5339)
at ~effect/Effect/evaluate (B:/~BUN/root/chunk-nhtrqkcr.js:25:5625)
at runLoop (B:/~BUN/root/chunk-nhtrqkcr.js:25:2045)
at evaluate (B:/~BUN/root/chunk-nhtrqkcr.js:25:1435)
...
at ~effect/Effect/successCont (B:/~BUN/root/chunk-nhtrqkcr.js:25:7810)
at runLoop (B:/~BUN/root/chunk-nhtrqkcr.js:25:2045)
at evaluate (B:/~BUN/root/chunk-nhtrqkcr.js:25:1435)
(The B:/~BUN/root/... paths are the same /$bunfs/root/... virtual filesystem as in the original report — Windows renders the bundled drive as B:.)
Still reproduces on 1.18.31, which is the current latest release.
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.
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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊