codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

Index coordinator wedges permanently after a worker is killed mid-run: orphaned generation markers in /tmp are never reaped on daemon restart

Open sblattj opened this issue 2 months ago • 4 comments

Summary

When an index worker is terminated mid-run (client/session exit, SIGKILL, crash), it can leave orphaned per-generation marker files in the daemon's /tmp coordination directory. From then on, every new index worker, including the daemon's own file-watcher auto-refresh, refuses to start with:

CBM index worker could not start: a pre-coordination or unverified CBM generation is active

A daemon restart does not clear these markers, so the wedge survives every restart. Only a full machine reboot (which wipes /tmp) clears it. In practice this recurs repeatedly on a busy machine that runs many concurrent MCP clients.

Environment

  • codebase-memory-mcp 0.10.8
  • macOS (per-user coordination dir at /tmp/cbm-daemon-<uid>/)

Root cause (as observed)

  • The coordination directory (/tmp/cbm-daemon-<uid>/) holds advisory locks plus per-generation marker files: cbm-<generation-id>.rw and cbm-<generation-id>.turn.
  • A cleanly completed generation is fine, but a generation whose worker is killed after it enters pre-coordination/admission but before it verifies leaves its .rw/.turn markers behind.
  • New workers treat that orphaned, unverified generation as "active" and refuse to proceed (correct as a safety check against clobbering an in-progress index), but there is no path that reaps it.
  • Because the markers live in /tmp and are not reaped on daemon startup, restarting the daemon re-reads the same orphaned state and stays wedged. Reboot is the only self-heal.

The index databases themselves stay healthy and queryable throughout; only new indexing / auto-refresh is blocked.

Repro (sketch)

  1. Start indexing a repo.
  2. Kill the index worker (or the client that spawned it) mid-run, before the generation verifies.
  3. Attempt any subsequent index (or let the file-watcher auto-refresh fire on a git change).
  4. It fails with the "pre-coordination or unverified CBM generation is active" error.
  5. Restart the daemon: still fails. Only a reboot clears it.

Impact

  • Silent, permanent loss of auto-refresh and manual re-indexing until reboot.
  • High-concurrency setups (many MCP clients / short-lived sessions) hit it often, since mid-run kills are common there.
  • The failure is easy to misread as a version/build conflict; the actual cause is an unreaped orphaned generation.

Requested fix

On daemon startup (and/or when no live worker holds the corresponding lock), reap orphaned/unverified generation markers so the coordinator self-heals without a reboot. Options:

  • On startup, remove .rw/.turn markers for generations whose owning process is no longer alive (advisory-lock probe / PID liveness).
  • Age out unverified generations after a bounded TTL (a real generation verifies in seconds).
  • Emit a clear diagnostic when a wedge is detected and reaped, distinct from a genuine version/build conflict.

Current workaround

Stop the daemon, clear the /tmp coordination directory (equivalent to what a reboot does), and let the daemon respawn. The index DBs are untouched by this.

sblattj avatar Sep 21 '26 21:09 sblattj

Same message here on Linux (0.10.8). In our case the trigger was the held-lock unlink described in #2178: systemd-tmpfiles' q /tmp … 10d removed the daemon's cbm-<endpoint>.lifetime.lock 10 days after the daemon started, and the first pre-coordination or unverified CBM generation refusal came three minutes after the cleaner ran. Details are in #2178.

Your orphaned-marker observation matches what we see too. Over two weeks, 117 index workers were killed by the 15-minute quiet timeout (outcome=hang), and /tmp/cbm-daemon-<uid> now holds 14 .rw/.turn markers, dated 09-16 to 09-24, that no process has open. The two mechanisms can overlap, so when someone reports this message, it's worth checking both the held locks' inodes and orphaned markers.

ptfff avatar Sep 25 '26 04:09 ptfff

Thank you for the detailed report, and thank you @ptfff for adding the Linux observations. I checked the matching refusal on main at c61b3806bfe4c25f7003728b21d5b96a0db20e8f: src/main.c:3107-3114 emits that message when cbm_daemon_ipc_local_transition_seal_legacy does not return success. The message alone does not distinguish orphaned files from a live or unverifiable generation, so I cannot yet confirm the proposed marker-reaping diagnosis. We need more time to review that distinction together with the held-lock report linked here. Keeping this open and high priority, with the next investigation on our side. Please do not remove coordination files while any CBM processes may still be using them; this reply is not an endorsement of the cleanup workaround.

DeusData avatar Oct 01 '26 18:10 DeusData

Thank you again for the macOS and Linux observations. I have no new verified diagnosis beyond the earlier distinction between orphaned files and live or unverifiable generations. The next investigation remains on our side; please do not remove coordination files that running processes may still use.

DeusData avatar Oct 19 '26 22:10 DeusData

Thank you again for the observations on both platforms. Distinguishing orphaned coordination state from a live or unverifiable generation is still waiting on maintainer investigation. Sorry for the delay; I’ll follow up soon.

DeusData avatar Oct 25 '26 17:10 DeusData