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 — serve (1.18.25): MCP child processes accumulate on web-client reconnects until the server OOMs · Issue #46035 · anomalyco/opencode

serve (1.18.25): MCP child processes accumulate on web-client reconnects until the server OOMs #46035

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
serve (1.18.25): MCP child processes accumulate on web-client reconnects until the server OOMs#46035
Copy link
Assignees
neriousy
Labels
pending closetriaging

Description

@elewarr
elewarr
opened on Aug 28, 2026
Issue body actions

Environment

  • opencode 1.18.25, opencode serve --hostname 0.0.0.0 --port 4040, headless under systemd (Linux, LXC, Debian 13)
  • 5 local MCP servers configured globally in opencode.json (two started via uv, three via npx), plus a few remote ones
  • clients: several browser tabs of the web UI, one opencode attach TUI

What happens

Each client connection, and each reconnect, initializes a full set of MCP server processes. When the connection dies, its processes are not reaped. An interrupted web session tab reconnects in a loop and leaks another full set on every cycle: about 5 processes, ~300 MB.

We watched the systemd unit grow ~20 GB in about 65 minutes (systemd recorded peaks of 20.4 GB and 20.1 GB on two runs), at which point the container hit its memory limit and the kernel OOM-killed the server. The kill interrupts every session, which interrupts more browser tabs, which reconnect and leak faster. After the first OOM, the second one arrived within the hour.

The server also re-spawns MCP sets at startup for projects nobody has open. Within a minute of a fresh start, with zero web clients connected, we counted 23 MCP processes, including 3 sets that only exist in a project-scoped config of a directory no session was using. This matches what #43845 describes for the V2 beta, but on stable.

Reproduction

  1. Run opencode serve with several local MCP servers in the global config.
  2. Open multiple sessions in web tabs.
  3. Restart the server (or break the connections any other way). Leave the tabs open.
  4. Watch ps under the server's cgroup.

Evidence

  • Census 22 minutes after one restart: ~100 MCP processes (34x lean-lsp, 22x gsd-mcp, 16x minimax, 16x playwright, 10x zai; each with an extra npm exec/uv wrapper, 70-100 MB RSS per process). RSS grew ~300 MB/min.
  • Killed the browser's TCP connections with ss -K: five fresh connections reappeared within 45 seconds, with another MCP set behind them.
  • With all web tabs closed, the counts freeze. A lone TUI attach does not leak.
  • MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 event listeners added (Effect emitter) appeared in the log minutes before the second OOM kill.
  • The server also holds about 15 loopback connections to itself (internal API calls) with similar lifetimes.

Expected

MCP processes die with the connection that spawned them. Process count should settle at one set per live client, and startup should not warm MCP sets for projects nobody opened.

Workaround (what we run with now)

Close interrupted web tabs, keep the global MCP list short, give the server memory headroom. Raising our container limit from 24 to 48 GB bought roughly a night, not a fix.

Related

  • service: restart leaves stale daemon and duplicated MCP servers running #42270 (stale daemon + duplicated MCP servers after restart, V2)
  • service: v2 service spawns one local MCP server pair per cataloged project directory at startup #43845 (one MCP pair per cataloged project dir at startup, V2 beta)
  • MCP servers spawn 2-4 duplicate processes per server on startup, causing TasksMax exhaustion and EAGAIN errors #31554 (duplicate MCP processes at startup)
  • opencode2: RSS grows ~530 MB/min during active agent turn (OOM crash) #41502 (RSS growth during active turns, OOM)
  • [BUG] opencode serve leaks memory and wedges when an upstream SSE endpoint hangs #36739 (serve leaks memory when an upstream SSE hangs)

Version note

We upgraded 1.18.23 to 1.18.25 the same evening this started, so we cannot say the upgrade introduced it. Heavy multi-tab web usage is the stronger correlate.

Activity

  1. github-actions
    assigned
    neriousy
    on Aug 28, 2026
  2. github-actions commented on Aug 28, 2026

    @github-actions
    github-actionsBot
    on Aug 28, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of or closely related to existing issues not yet listed in your references. Please check:

    • Memory leak in server mode: unbounded EventTarget listeners added to Effect-ts internal emitter (QL) per session #29204: Memory leak in server mode via unbounded EventTarget listeners per session — the MaxListenersExceededWarning you observed in your logs is the same symptom reported there, and the root cause may overlap.

    Also, the maintainers are tracking memory issues centrally in the Memory Megathread #20695, which includes instructions for capturing heap snapshots that would directly help diagnose this issue. If you can upload a heap snapshot following the instructions there, it would likely accelerate a fix.

  3. elewarr commented on Aug 28, 2026

    @elewarr
    elewarr
    on Aug 28, 2026
    Author
    More actions

    Checked #29204 — we see the same MaxListenersExceededWarning from the Effect emitter (11 listeners, same stack shape, ours on 1.18.25 serve), so the in-process listener accumulation it describes is probably part of what we hit too.

    One distinction worth keeping separate: in our case most of the 20 GB is external child processes, not core RSS. At the census point the opencode serve process itself was ~0.9 GB while the systemd unit (server + MCP children) held ~3 GB and was climbing ~300 MB/min via spawned MCP sets, about 100 processes at 70-100 MB each. Because core RSS stays under 2 GB for a long time on this path, the automatic heap snapshot flow (OPENCODE_AUTO_HEAP_SNAPSHOT=1, fires at 2 GB RSS) would likely never trigger for us.

    If a heap snapshot of the serve process would still help, tell us which flow to use for headless serve — the manual ctrl+p flow looks TUI-side as far as we can tell — and we will capture one. We can also reproduce the child-process accumulation on demand.

  4. YidiDev commented on Aug 29, 2026

    @YidiDev
    YidiDev
    on Aug 29, 2026
    More actions

    I found a deterministic local MCP lifecycle gap while investigating this. A real stdio MCP fixture that spawns one child shows that mcp.disconnect() terminates the MCP parent but leaves the child running. Full instance teardown already enumerates and terminates descendants, while dynamic disconnect/replacement only call client.close().

    I have a bounded regression test that fails consistently with child stdio fixture process was not terminated by disconnect; cleanup force-kills the fixture afterward. This proves an orphan-process path, although I have not yet established that web reconnects invoke this exact close path.

    Are you already changing MCP process cleanup, or would a focused fix plus regression test be useful?

  5. elewarr commented on Aug 30, 2026

    @elewarr
    elewarr
    on Aug 30, 2026
    Author
    More actions

    New data point on the open question (does the web-reconnect path hit the disconnect path @YidiDev instrumented?) — we censused the live server after reading the comment above.

    Setup: opencode 1.18.25 serve under systemd, headless, no TUI — only web tabs. Global MCP config = 4 stdio servers (one uvx, three npm exec). Server uptime 29 h, light use (2–4 active sessions/day).

    Child census under the serve PID right now:

    • 8 complete MCP sets (32 processes: shim → sh → node/python trees), all direct children of the serve process, all with parent shims still alive. Ages: two sets at ~29 h spawned 3 min apart, one at ~22 h, two at ~11 h spawned 12 s apart, plus newer pairs.
    • Zero orphans: not a single MCP-related process has PPID 1. Nothing matches the disconnect-kills-parent-leaves-grandchild shape.
    • LSP servers accumulate the same way: two pyright-langserver for the same project at 22 h and 18 h, a 19 h yaml-language-server.
    • Secondary symptom consistent with whole-set persistence: uv cache prune stalls on a lock held by a days-old uvx-based MCP process.

    Reading: on web reconnects we see no evidence that disconnect()/client.close() runs at all — if the superseded set's client went through the path @YidiDev's fixture exercises, the parent shim would be dead and the actual MCP server process re-parented to init. Instead the superseded sets persist intact and attached. So the reconnect leak looks upstream of the orphan-at-disconnect bug: a fresh set is spawned per (re)connection and the previous set is never torn down. The two defects compound — even once reconnects do call teardown, descendant-unaware termination (your finding) would still leak the node/python grandchildren.

    Caveat, kept honest: we can't count open web tabs from the server side, so "8 sets" could in principle mean 8 simultaneously open tabs — but the 3-min and 12-s spawn pairs, day-plus survival under light use, and our earlier 100-process/300 MB-per-min census make missing teardown the parsimonious explanation.

    To answer the question directly: yes, a focused fix + regression test is useful, and ideally the suite covers both layers: (a) reconnect tears down the superseded set, (b) teardown terminates the full descendant tree (your existing test). Happy to run an instrumented build against our workload — the accumulation reproduces within hours on a few web-tab reconnect cycles.

  6. elewarr commented on Aug 30, 2026

    @elewarr
    elewarr
    on Aug 30, 2026
    Author
    More actions

    Census update, plus corrections to our own numbers above:

    Count correction. The "8 complete sets" included one transient: a set observed at ~0 s elapsed was gone 40 min later without completing. Three censuses across an hour otherwise agree exactly: 7 complete sets, each the identical 4-server global shape, all launchers alive in S state (no zombies), zero PPID-1 processes.

    The client side. The web UI shows 4 open sessions, 0 TUI clients. That ratio invites a leak estimate, but we won't offer one: at least one session created in the last hour (visible via a fresh yaml-language-server under the serve PID) has no corresponding MCP set, and server-side session records include many subagent task sessions whose MCP behavior we can't inspect — sets simply can't be mapped to owners from process state. Under a one-set-per-session baseline, 7 sets for 4 open sessions would mean at least 3 superseded; verifying that baseline is exactly what needs instrumentation.

    Sharpening the "Reading" above. Alive launchers + zero orphans rule out the fixture's kill-the-direct-child behavior having run, but process state cannot distinguish "close/disconnect is never invoked on reconnect" from "it's invoked but terminates nothing." An instrumented build discriminates these directly — offer stands, we can force reconnect cycles on demand and correlate logs with the process tree.

    Scope note. LSP servers accumulate under the serve PID too (duplicate pyright-langserver for a single project, yaml/bash language servers). Whether MCP and LSP accumulation share a trigger is open — notably, the fresh session above spawned an LSP server but no MCP set — but a fix scoped to MCP teardown alone would leave the LSP accumulation standing regardless.

  7. YidiDev commented on Aug 30, 2026

    @YidiDev
    YidiDev
    on Aug 30, 2026
    More actions

    Thanks for the correction; the intact launchers and duplicate LSPs make this distinct from the descendant-orphan defect I reproduced.

    I traced the current ownership model on dev:

    • MCP state is created per (service graph, normalized directory), not per web session or SSE connection. Materializing a directory's MCP state starts the complete configured set, including globally configured entries.
    • One InstanceStore deduplicates concurrent loads of the same normalized directory, so a reconnect alone should not create another set in that store.
    • On server.connected, the web client refreshes active directories; directory bootstrap queries MCP status/resources. Browser-side directory eviction does not call backend instance.dispose, so directory states can remain after the corresponding browser state is gone.
    • LSP ownership is also per directory state, and its (server, root) deduplication is local to that state. Multiple retained directory states can therefore produce duplicate LSPs for the same repository root alongside complete MCP sets.

    That leaves two leading explanations for the seven stable sets: multiple live backend directory states, or multiple live service graphs/stores serving the same directory. The latter is possible architecturally, but a normal headless serve starts one listener, so directory retention is the first thing I would measure.

    Minimal instrumentation should assign IDs to the listener graph, InstanceStore, MCP/LSP state, and log { state_id, store_id, directory, server_name, child_pid } on create/finalize (plus { server_id, root } for LSP). One run would tell us whether the seven sets map to seven directories or multiple owners of the same directory. Logging disconnect alone would not answer that.

    I'll keep the process-tree fix scoped separately: it is a proven teardown bug and makes teardown complete once invoked, but it does not explain intact MCP sets or the LSP accumulation reported here. I can prepare the focused instrumentation patch for your Linux workload next if that would help.

  8. opencodejr commented on Oct 28, 2026

    @opencodejr
    opencodejrBot
    on Oct 28, 2026
    Contributor
    More actions

    Thanks for the very detailed report and the process census, @elewarr.

    Version 1.18.25 is OpenCode v1, which now only gets fixes for critical bugs: data loss, security problems, or crashes and breakage with no workaround. This leak is serious, but closing the interrupted web tabs stops it, so it's unlikely to be fixed in v1.

    We'd encourage moving to v2 (@opencode/cli), where active development happens. To be upfront, v2 has open reports of similar MCP process growth, so upgrading may not avoid this completely. These are the closest ones, most relevant first:

    • MCP: local servers are spawned per session and never released when a session ends #51249: local MCP servers spawned per session/directory and never released (v2 service)
    • mcp: orphaned local MCP server processes accumulate after sessions end #50363: orphaned local MCP server processes accumulate after sessions end (v2)
    • mcp: global stdio servers spawn once per loaded directory and exhaust memory #51003: global stdio MCP servers spawned once per loaded directory until memory runs out (v2)
    • Local MCP disconnect leaves descendant processes running #46253: a local MCP disconnect leaves npm exec/uvx descendant processes running (v2)
    • core: cached locations multiply MCP subprocesses #37844: cached locations multiply MCP subprocesses (v2)
    • service: v2 service spawns one local MCP server pair per cataloged project directory at startup #43845: one MCP set per cataloged project dir at startup (v2)

    If you think this counts as critical for v1, or you can reproduce it on v2, please reply here. If it happens on v2 and none of the issues above covers your case, include the v2 version and the same ps census.

  9. opencodejr
    added
    pending close
    triaging
    on Oct 28, 2026
  10. opencodejr
    closed this as not plannedon Oct 29, 2026
  11. opencodejr commented on Oct 29, 2026

    @opencodejr
    opencodejrBot
    on Oct 29, 2026
    Contributor
    More actions

    We haven't heard back, so I'm closing this as not planned. This was reported on opencode 1.18.25 (v1), which only gets critical fixes, and closing the interrupted web tabs stops the MCP process leak.

    The MCP lifecycle problems you describe are tracked for v2 in #51249, #50363, #51003, #46253, #37844 and #43845. If you can reproduce this on v2 (@opencode/cli) and none of those covers it, please open a new issue with the v2 version and a ps census like the one here. If you think it is critical for v1, reply here. Thanks again for such a thorough report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @neriousy
    neriousy

Labels

pending closetriaging

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.