MAESTRO: Expand startup orphan cleanup to target mcp-server and worker-service processes

The startup cleanupOrphanedProcesses() only targeted chroma-mcp, leaving
orphaned mcp-server.cjs and worker-service.cjs processes undetected after
daemon crashes. Expanded to target all claude-mem process types with
30-minute age filtering and current PID exclusion. Closes PR #687 (which
had a spawnDaemon regression removing Windows WMIC support).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2026-02-05 22:06:46 -05:00
parent edfc1a403f
commit d333c7dc08
5 changed files with 243 additions and 140 deletions
+2 -1
View File
@@ -23,4 +23,5 @@ These PRs address orphaned/zombie processes. This is a recurring theme — v9.0.
- [x] Review PR #713 (`fix: prevent SDK subprocess accumulation` by @cjpeterein). Files: 17 files (very large PR). Steps: (1) `gh pr checkout 713` (2) This is a large PR touching many files — check how much overlaps with v9.0.8 ProcessRegistry work (3) Large PRs on process management are risky. If substantial overlap exists with shipped code, close with explanation. (4) If unique value remains, request the author to rebase and reduce scope.
> **Result: CLOSED** — 873 additions across 18 files with extensive overlap with shipped infrastructure. ProcessRegistry (v9.0.8) provides PID tracking and 3-layer orphan reaper, SessionQueueProcessor (v9.0.13) provides 3-minute idle timeout, and ProcessManager.ts already handles startup orphan cleanup. The only genuinely new addition was a try/finally wrapper around the SDK query loop, which is redundant given deleteSession() → abort() → ensureProcessExit() → SIGKILL escalation already handles subprocess cleanup. The large surface area (18 files) makes this high-risk for marginal defensive benefit.
- [ ] Review PR #687 (`fix: expand orphaned process cleanup to include mcp-server and worker-service` by @MrSaneApps). File: `src/services/infrastructure/ProcessManager.ts`. Steps: (1) `gh pr checkout 687` (2) Single-file change expanding what processes the reaper targets — low risk (3) Verify it correctly identifies mcp-server and worker-service processes (4) Run `npm run build` (5) If clean: `gh pr merge 687 --rebase --delete-branch`
- [x] Review PR #687 (`fix: expand orphaned process cleanup to include mcp-server and worker-service` by @MrSaneApps). File: `src/services/infrastructure/ProcessManager.ts`. Steps: (1) `gh pr checkout 687` (2) Single-file change expanding what processes the reaper targets — low risk (3) Verify it correctly identifies mcp-server and worker-service processes (4) Run `npm run build` (5) If clean: `gh pr merge 687 --rebase --delete-branch`
> **Result: CLOSED — Core concept implemented on main.** The PR correctly identified a real gap: startup cleanup only targeted `chroma-mcp` while orphaned `mcp-server.cjs` and `worker-service.cjs` processes went undetected after daemon crashes. However, the PR also destructively rewrote `spawnDaemon()`, removing the Windows WMIC spawn path (needed for console-popup-free daemon spawning) in favor of a simple `spawn()` with `windowsHide: true` — a regression. The `claude-mem` pattern was also overly broad. **Implemented directly on main:** expanded `cleanupOrphanedProcesses()` to target `mcp-server.cjs`, `worker-service.cjs`, and `chroma-mcp` with 30-minute age filtering, current PID exclusion, and proper `parseElapsedTime()` helper. Build passes, tests added and passing.