Skip to content

desktop (macOS): memory reaches 5.8 GB — every open project location keeps its own copy of each MCP server (14× rea, 14× codegraph) #2267

Backlog

Description

@xgd16

Summary

On macOS, OpenCode (Rune) 0.0.0-dev-527 sits at 5.8 GB in Activity Monitor during normal use (screenshot below). The built-in perf recorder says the Rune UI process itself is small (resident_bytes 453,820,416, peak_footprint_bytes 607,307,576), so I walked the process tree of opencode-desktop: the app had 15 project locations booted at once, and each location was running its own copy of every configured MCP server — 14 × rea node processes (~245 MB each), 14 × npm exec rea-agents launcher shims (~85 MB each) and 14–15 codegraph process trees (~140 MB each; codegraph itself spawns two nested node processes per instance). That is roughly 6.6 GB of duplicate MCP child processes on top of a ~1 GB opencode-cli sidecar.

Environment

  • OpenCode (Rune): 0.0.0-dev-527 (packaged dev build, latest release; bundled CLI 0.0.0-dev-1390-arm64)
  • OS: macOS 27.2.1 (26B131), Apple M2 Pro (10 cores: 6P+4E), 32 GB, arm64
  • Shell: fish 4.9.3
  • Client: desktop app, dev channel, packaged
  • MCP config: 2 top-level entries in opencode.json (codegraph plus a servers group) that expand to 4 stdio/remote servers: rea (rea-agents@6.7.0 via npx), codegraph, browse, and one remote HTTP server
  • Usage: 15 project folders with sessions/tabs in the sidebar

Reproduction

  1. Keep sessions open across ~15 project folders (they stay in the sidebar's recent sessions).
  2. Use the app normally for a couple of hours. Activity Monitor reports 5.8 GB for OpenCode (Rune) after ~2 h.
  3. Compare with the process tree: ps -axo pid,ppid,rss,args, then walk the children of the opencode-desktop pid.

Observed breakdown (2026-12-03 16:05 CST, also in process-tree.txt)

group procs avg MB total MB
rea mcp (node) 14 245 3,434
npm exec rea-agents shim 14 85 1,196
opencode-cli sidecar 1 997 997
codegraph.js child 15 58 867
codegraph serve --mcp 14 42 589
codegraph native node child 13 43 565
opencode-desktop (Rune UI) 1 472 472
browse mcp 1 3 3
total 73 8,122

RSS double-counts shared pages (Activity Monitor's footprint for the same tree was 5.8 GB), but the shape is unambiguous: ~470 MB Rune UI + ~1 GB sidecar, and ~6.6 GB in duplicate MCP servers.

Per-location cost is about 465 MB: rea 245 MB + npx shim 85 MB + codegraph ~140 MB.

Log evidence (sanitized 7-day excerpt attached)

server-1/opencode.log, 2026-11-27 → 2026-12-03:

  • 16 distinct directory= values, 15 of them project folders.
  • location services booted 181, location services evicted 125, location services reloaded 2 — evictions do happen, yet there were still 14 live copies of each stdio MCP server.
  • mcp connected 710 (rea 180, codegraph 180, browse 181, remote 169); 204 today alone. Each boot of a location connects a fresh set of MCP servers.
  • 4,572 watcher subscribe and 2,920 watcher started/stopped — every location also carries its own watcher set.

Perf recorder (desktop/perf/*):

  • perf.json (this launch): resident_bytes 453,820,416, footprint_bytes 476,464,952, peak_footprint_bytes 607,307,576; recent 60 s window p50 work_ms 2.1 / p95 8.4 — frames are fine, this is not the idle poll storm from perf(desktop): stop 30s wake_after echo chamber and idle poll churn #1692.
  • One memory-growth incident: minute floors 355 MB → 374 MB → 454 MB → 463 MB → 482 MB (+127,139,840 bytes in ~5 min), "confidence": "suspected growth, not a proven leak".
  • An earlier launch (pid 86038) grew from 147 MB to 607 MB over 45 min before exiting.
  • A fresh launch with no sessions stays around 150–275 MB, so the baseline is fine; the growth tracks the number of open locations.

Expected behavior

Memory should scale with the projects actually in use, not with the number of folders that have a session in the sidebar. A global stdio MCP server should be shared across locations, or spawned only for the active location, and its children should be reaped when a location is evicted.

Relation to #1649 / #2025

This is the same symptom as #1649 (Windows), on macOS and after the #2025 fix. #2025 removed the eager used_projects() attach loop, but on dev-527 every one of these 15 folders genuinely has a session, so per-location MCP spawning still multiplies into 14 copies of rea and codegraph.

If one MCP set per open location is intended, then either the MCP servers need to be shared across locations or the number of simultaneously booted locations needs a cap / more aggressive eviction — closing a location does not appear to free its MCP children today. Also note that each codegraph instance is a chain of three node processes (launcher → codegraph.js → worker), so one configured server becomes 3 processes per location; that is on codegraph, but it triples the per-location cost.

Attachments

Activity Monitor showing OpenCode (Rune) at 5.8 GB

  • opencode-rune-macos-memory-20261203.zip (178 KB) — sanitized archive:
    • desktop/perf/perf.json, perf.log, perf-incident-*.json unchanged
    • manifest.json with paths replaced by placeholders
    • server-1/opencode.log reduced to lifecycle/perf messages (mcp, location services, watcher, cli, plugin reconciliation, event stream, migration, errors) — home directory replaced with /Users/<user>, project paths pseudonymised as project-NN, command args= and credential-looking values redacted
    • process-tree.txt (the table above) and SANITIZATION.md

Activity

  1. Hona commented on Dec 3, 2026

    @Hona
    Member

    Thanks for the detailed process tree and sanitized server-1/opencode.log — they pinpointed the exact client-side triggers behind the 14 booted locations.

    Client-side fixes landed in opencode-rune (PR #2281, commit fba4e73c1)

    In server-1/opencode.log (runs e6377687 and 4e446b39), only 1–3 open tab folders booted at launch, followed seconds later by a simultaneous 9–11 location boot burst within ~3 ms (without mcp client attached server=rune). Auditing all location-scoped HTTP/WebSocket paths in opencode-rune turned up five client-side paths that booted cold project folders or prevented/undid idle location eviction:

    1. Automations /automation capability probe (apps/desktop/src/surfaces/automations/source.rs, crates/opencode-kit/src/client/automations.rs): Opening Automations spawned parallel GET /api/command?location[directory]=<dir> requests for every used_projects() folder, every open tab, and every automation row — matching the 9–11 simultaneous location-boot burst in the log. It now probes at most one already-warm location per server (the return tab or the server default "" with no location[directory] query) plus the single selected automation entry's directory.
    2. Idle background tabs in rune client MCP (features/workspace-tools/src/rune_mcp/mod.rs, apps/desktop/src/workspace/lifecycle/rune_mcp.rs): After perf(rune-mcp): attach client MCP only to active/open folders, not all sidebar projects #2025 removed used_projects(), sync_window still held a persistent ClientMcp WebSocket for every open tab, booting every restored background tab's location on launch and immediately re-booting evicted locations via WebSocket reconnect. It now attaches only to the active routed session/draft and actively busy background tabs (family_busy).
    3. Browser RPC capability probe (apps/desktop/src/surfaces/browser/rpc/suppression.rs): maybe_start_capability_probe picked app.projects.first(), booting an unopened project for a server-wide capability check. It now probes the server's already-booted default (or active draft) directory.
    4. Browser RPC location.shutdown handling (apps/desktop/src/surfaces/browser/rpc/comes_back.rs, apps/desktop/src/surfaces/browser/rpc/mod.rs, apps/desktop/src/session/events/mod.rs): Disposes idle, off-screen attachments with no active commands when location.shutdown arrives so AttachMachine backoff retries do not immediately re-boot evicted locations.
    5. File watches on connect/reconnect (features/files/src/watch.rs): watch::connected previously re-armed POST /api/experimental/fs/watch?location[directory]=... for every restored session's open file tabs. It now re-arms only the active session on connect/reconnect and re-arms off-screen sessions lazily in watch::shown.

    Verified locally: cargo check -j 1 -p opencode-desktop, cargo clippy -j 1 -p opencode-kit -p opencode-feature-workspace-tools -p opencode-feature-files -p opencode-desktop --no-deps, and pwsh scripts/guardrails.ps1 (11/11). Not yet verified interactively on macOS hardware.

    What still lives upstream in anomalyco/opencode server

    Leaving this issue open for macOS verification on the next dev build and because two core parts of the memory footprint live in the opencode server sidecar (anomalyco/opencode):

    • Per-location duplication of global stdio MCP servers: Every booted project location still spawns its own independent copy of globally configured stdio MCP servers (rea, codegraph, etc.) rather than sharing a single global server process across locations.
    • Reaping nested MCP child process trees on location eviction: When a location is evicted (location services evicted), nested child trees (such as npx shims and codegraph launcher → worker chains) need to be terminated cleanly so evicted locations actually release memory.

    Once the next dev release includes #2281, please re-check Activity Monitor / server-1/opencode.log on macOS and let us know whether the simultaneous multi-location boot burst and idle background-tab boots are gone.

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

Metadata

Metadata

Assignees

No one assigned

    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