Skip to content

serena/rust-analyzer: share one rust-analyzer across sessions via lspmux #290

@paulnsorensen

Description

@paulnsorensen

Part 4/4 of the local-llm rightsize effort (research in hallouminate/.cheese/research/{serena-ra-memory,lspmux-serena-status}/).

Problem

Every Claude Code session spawns its own serena MCP server, which spawns its own rust-analyzer at ~4.4 GiB RSS each (3 found concurrently = ~13 GiB; one was 3 days stale). Two upstream causes:

  1. serena hardcodes cachePriming.enable=true + cargo.autoreload=true in solidlsp/language_servers/rust_analyzer.py → each instance eagerly indexes the full dep graph (arrow/fastembed) instead of ~400 MB lazy. Fix PR rust-analyzer: lightweight profile (disable cachePriming + cargo.auto… oraios/serena#1557 is maintainer-acknowledged ("makes sense, helps us" — MischaPanch), blocked only on a flaky-test timeout bump (#1559). Serena ships ~1 release/week, so this lands on its own — no local patch.
  2. serena never shares LS instances (one per session by design; #693 closed as "client's problem") and doesn't reap children on ungraceful exit (#1490, zero maintainer engagement).

Decision: lspmux — N serena sessions share one rust-analyzer, idle-killed after timeout.

lspmux status (verified 2026-06-11): it IS ra-multiplex renamed at v0.3.0 (GitHub pr2502/ra-multiplex redirects to codeberg.org/p2502/lspmux); last commit 2026-02-25; packaged in Homebrew/Nix/AUR; recommended by the rustaceanvim maintainer; sunshowers/lspmux-rust-analyzer wraps it for exactly the Claude-Code-multi-session case. v0.3.0 fixed processId handling so the LS survives the first client disconnecting.

Tasks

  • Install lspmux (cargo install or AUR; pin version) via dotfiles tooling.
  • Config: instance_timeout = 300 (idle kill), per-workspace instance keying.
  • Shim rust-analyzer so serena launches the lspmux client instead of the real binary. Verification gate first: serena's DependencyProvider may resolve via rustup which rust-analyzer, bypassing a PATH shim — confirm with ps parentage after a fresh session; consider shimming the rustup proxy path or using sunshowers/lspmux-rust-analyzer.
  • Gate 2: confirm lspmux passes serena's initializationOptions through unmodified (it rewrites processId in initialize; if it strips cachePriming settings the upstream #1557 fix would be lost through the mux).
  • If either gate fails: stop, document findings on this issue — do not silently fall back to patching serena.
  • One-time cleanup of current stale rust-analyzers (pkill -f rust-analyzer; serena respawns on demand).
  • Watch rust-analyzer: lightweight profile (disable cachePriming + cargo.auto… oraios/serena#1557 — upgrade serena once merged (cuts per-instance RSS independent of lspmux).

Acceptance

  • Two concurrent Claude Code sessions in the same Rust workspace → exactly one rust-analyzer process (ps axo pid,ppid,comm | grep rust-analyzer).
  • 5+ min after all sessions exit, zero rust-analyzer processes remain.
  • serena symbol tools (find_symbol, find_referencing_symbols) still work through the mux in both sessions.

Risks

  • Single-author project (no maintained alternative found — absence claim from search exhaustion, not a catalog).
  • rustaceanvim flagged lspmux 0.3.x compat as unverified (ra-multiplex -> lspmux mrcjkb/rustaceanvim#870) — relevant if the editor shares the same instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions