Repository navigation
MCP servers spawn 2-4 duplicate processes per server on startup, causing TasksMax exhaustion and EAGAIN errors #31554
Description
Bug Description
On Linux (Ubuntu), opencode-web spawns 2–4 duplicate processes per MCP server on startup instead of one. With 10 MCP servers configured, this produces 36 processes instead of ~10–20. The duplicate processes are not cleaned up on restart — they accumulate.
This causes EAGAIN: resource temporarily unavailable, posix_spawn errors when the system approaches the TasksMax limit, making MCP servers appear as "failed" in opencode mcp list.
Environment
- OS: Linux (Ubuntu, systemd)
- opencode version: latest (headless server mode via
opencode web) - MCP servers configured: 10 local stdio-type servers (github, memory, time, sequential-thinking, fetch, context7, ast_grep, grep_app, websearch, searxng)
- Systemd config:
TasksMax=200(raised to 500 during debugging) - Initial state: TasksCurrent ≈ 190/200 → spawns fail with EAGAIN
Evidence
Process duplication
After a single opencode-web restart, ps aux shows each MCP server has 2–4 instances running simultaneously:
github: 2x sh + node (via npx)
memory: 2x sh + node (via npx)
time: 2x uv tool uvx + 2x uv cache python
sequential: 2x npm exec + 2x sh + node
fetch: 2x uv tool uvx + 2x uv cache python
context7: 2x npm exec + 2x sh + node
websearch: 2x npm exec + 2x sh + node
searxng: 2x python3 direct
Total: 36 processes for 10 MCP servers
EAGAIN errors
When TasksCurrent approaches TasksMax (190/200), all MCP servers report:
EAGAIN: resource temporarily unavailable, posix_spawn
MCP error -32000: Connection closed
The processes exist but opencode cannot communicate with them.
Memory impact
- Duplicate processes consume ~660MB extra memory beyond the expected ~17 processes
- System had 1.3GB+ headroom but spawns still failed due to TasksMax limit
Root Cause (Preliminary)
The duplication appears to be triggered by opencode's startup sequence spawning MCP servers via multiple mechanisms simultaneously:
npm exec(npx wrapper)sh -c "command"+ node binaryuv tool uvx(for Python servers)python3direct invocation
All mechanisms succeed, leaving multiple process trees running in parallel.
Related Issues
- Bug: MCP servers spawn duplicate processes per session — 1 project = 8+ instances, 2+ projects = crash #29939 — MCP servers spawn duplicate processes per session (1 project = 8+ instances)
- MCP servers spawned 8-10x per instance on Windows, consuming ~3.5 GB RAM on startup #26336 — MCP servers spawned 8-10x per instance on Windows (~3.5 GB RAM)
- Local stdio MCP servers leak processes on disconnect / replace / rollback #26714 — Local stdio MCP servers leak processes on disconnect
Expected Behavior
- Each MCP server should spawn exactly one process tree (not multiple parallel trees)
- Duplicate processes from a previous restart should be cleaned up before starting fresh
- When system resources are constrained, opencode should handle this gracefully instead of spawning in a way that guarantees EAGAIN
Workaround
Raising TasksMax from 200 → 500 in systemd mitigates the EAGAIN trigger, but does not fix the duplication.
Impact
- Wastes ~660MB RAM per restart
- Triggers EAGAIN errors under normal load (TasksMax 200 → 190 used before any MCP spawns)
- Makes MCP servers appear failed even though processes are running and functional via direct stdio
- Accumulated duplicates across restarts could eventually exhaust memory
Activity
github-actions commentedon Jun 9, 2026
This issue might be a duplicate of existing issues. Please check:
Ruslanastro commentedon Aug 8, 2026
Same bug reproduced on the Windows desktop app (Electron, @opencode-aidesktop, v1.18.15), 2/2 restarts.
Evidence after a fresh app restart (all timestamps same boot, every local stdio MCP server spawned twice ~5s apart, both copies children of the same app utility process):
mcp.*.enabledtoggle or command shape affects it.Original report (now closed as duplicate): #41331.
liudongyan13701205717-source commentedon Aug 21, 2026
+1; this likely contributes to the "MCP fails to load on startup" reports on Desktop (#40516) and the stale-state issue (#35285). Duplicate spawns competing for CPU at startup would also explain intermittent startup timeouts. Tracking together.
sajjad-rabby commentedon Oct 14, 2026
Related Windows reproduction: duplicate MCP process starts under OpenWork 0.18.58.0 / OpenCode engine 1.18.30
I'm reporting a related symptom to the Linux reproduction in this issue and the existing Windows Desktop report.
Environment: Windows, OpenWork 0.18.58.0, bundled OpenCode engine 1.18.30. The running engine version was identified using the bundled version manifest and a SHA-256 match against the running binary. The binary's PE
FileVersionfield disagrees with that version and was not used as the version authority.Observed process creation: In one captured engine lifetime, the primary engine started at 08:53:03 UTC. Eighteen direct engine children appeared in four process-start clusters:
Process ancestry associated the resulting server process trees with the same live engine; no engine restart occurred during this observation. Six local-server families ended up with four apparently identical instances each, while four other observed families had one instance each. The Firebase server was configured but absent from the captured process population.
These are observed process-start clusters, not confirmed MCP initialization cycles. The underlying trigger remains unknown.
Memory measurements: From the same idle snapshot, the engine-managed local MCP process population, including local
mcp-remotebridges, measured approximately:These are different memory metrics and should not be interpreted interchangeably. The committed footprint is substantially larger than resident-private memory; system-wide commit-limit pressure was not established. Savings from reducing instances have not been tested.
Two older same-name AgentMemory processes were excluded after investigation showed that they belong to a separately managed standalone daemon, rather than the current engine's MCP process population.
Root cause remains unconfirmed. The captured configuration defines one agent and the runtime state identifies one primary engine. The observation does not establish that project, session, or agent lifecycle behavior is responsible, nor does it prove that Windows process-tree cleanup is causing the repeated starts. The current INFO-level engine logs did not reveal the trigger.
This appears related at the symptom level to #26336 and #29939, but the trigger in this environment remains undetermined.
This differs from the 1.18.15 desktop report above (two waves, stock Desktop app): ours is four clusters under the OpenWork host on engine 1.18.30.
I can provide appropriately redacted process ancestry, server counts, and configuration structure if needed. No credentials, private state, or diagnostic file uploads are included.
Running-Lag commentedon Oct 15, 2026
I am having the same issue.

The MCP server I am using (https://github.com/browsermcp/mcp) is unable to handle multiple instances of it running at the same time.
This causes the second one to kill the first one and results in errors:
VariableVince commentedon Oct 23, 2026
Could be fixed now by the PR that closed #52741