GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Memory leak in AI SDK Effect runtime — EventTarget listeners never cleaned up · Issue #34574 · anomalyco/opencode

Memory leak in AI SDK Effect runtime — EventTarget listeners never cleaned up #34574

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Memory leak in AI SDK Effect runtime — EventTarget listeners never cleaned up#34574
Copy link
Assignees
nexxeln

Description

@fifaliao
fifaliao
opened on Jun 30, 2026
Issue body actions

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 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.

Reacted by Kisfork, Juan Jose Vidanez and Forrest Hopkins
Reacted by Damián, Agustinus Nathaniel and sclement2

Activity

  1. github-actions
    assigned
    nexxeln
    on Jun 30, 2026
  2. github-actions commented on Jun 30, 2026

    @github-actions
    github-actionsBot
    on Jun 30, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of existing issues. Please check:

    • Memory leak in server mode: unbounded EventTarget listeners added to Effect-ts internal emitter (QL) per session #29204: Nearly identical — memory leak in server mode with unbounded EventTarget listeners on Effect-ts internal emitter per session, same MaxListenersExceededWarning stack trace from ~effect/Effect/evaluate, same server mode context, same GB-scale memory growth pattern
    • MaxListenersExceededWarning after web interface starts #28492: MaxListenersExceededWarning after web interface starts
    • [BUG] MaxListenersExceededWarning #31622: MaxListenersExceededWarning bug report
    • Memory Megathread #20695: Memory Megathread tracking many related memory issues
    • Memory leak during long-running session with multiple bash tool calls #33385: Memory leak during long-running sessions with monotonic RSS growth
  3. shashb27 commented on Aug 20, 2026

    @shashb27
    shashb27
    on Aug 20, 2026
    More actions

    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 EventTarget leak described here:

    PR #38939 — targets a different leak

    • 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.
    • Different leak path, different subsystem. The issue here is the bundled AI SDK Effect runtime; fix(core): prevent allBounded listener leak via PubSub subscription #38939 is the V2 PubSub core.

    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:

    1. An upstream AI-SDK dependency bump (if the listener leak is fixed in a newer SDK version), or
    2. 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.)

  4. nicekit37 commented on Sep 16, 2026

    @nicekit37
    nicekit37
    on Sep 16, 2026
    More actions

    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.

  5. thdxr commented on Oct 11, 2026

    @thdxr
    thdxr
    on Oct 11, 2026
    Member
    More actions

    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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

  6. thdxr
    closed this as not plannedon Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @nexxeln
    nexxeln

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.