mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 22:28:10 +09:00
`.claude-flow/swarm/swarm-state.json` was retaining entries with
`status: "running"` indefinitely after the host process exited.
Each `claude-flow start --daemon` registered a new swarm; nothing ever
reconciled those entries against PID liveness or heartbeat TTL, so
crashed/exited orchestrators left permanent ghost registrations.
Reporter measured three orphan swarms accumulated in a single afternoon
on Windows v3.7.0-alpha.8.
Two changes in `swarm-tools.ts`:
1. `swarm_init` now records `pid: process.pid` on the new
`SwarmState`. Backward compatible — the field is optional.
2. `loadSwarmStore()` runs `reconcileOrphanSwarms()` on every read
and persists if anything changed. Reconciliation marks any
`status: 'running'` entry as `terminated` (with a
`terminationReason`) when:
- PID-based: `pid` is set and the process is dead
(ESRCH from `process.kill(pid, 0)`; EPERM still counts as
alive — different user but live)
- TTL fallback: pre-#1799 entries with no `pid` are reaped
when `updatedAt` is older than 24h (conservative; live but
long-idle swarms can recover by writing a heartbeat)
`swarm_status` and `swarm_health` no longer return the ghost entries
the reporter complained about. Cost is sub-millisecond (one kill(0)
syscall per running entry).
Closes #1799.