mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 14:16:34 +09:00
* fix(session): atomic writes to current.json + corrupted-file self-heal (#2307) Apply BIWizzard's diff from the issue verbatim. Same class as #1707 (metrics partial-JSON corruption) and #1637 (daemon-state.json write-race) which were both fixed elsewhere with atomic writes; session.js was missed in that sweep. Changes: - Add atomicWrite(file, data) helper: writes to `${file}.tmp.${pid}` then rename()s into place. rename() is atomic on the same filesystem, so concurrent writers (session-restore, metric, daemon workers, teammates) can't interleave partial content. - Replace all 5 fs.writeFileSync calls on session files with atomicWrite. - In restore(): wrap JSON.parse in try/catch so existing corrupt session files self-heal — log the error and start a fresh session rather than throwing out of the hook. Why this matters: per-fd offsets in writeFileSync mean writer B can overwrite the first N bytes of writer A's payload but cannot shrink the file — A's tail dangles past B's end, producing valid JSON + trailing garbage. session-restore then throws on the bare JSON.parse. Closes #2307. Co-Authored-By: BIWizzard <noreply@github.com> Co-Authored-By: RuFlo <ruv@ruv.net> * fix(hive-mind): await spawned claude before returning (#2297) Per clement-livdeo's root-cause: spawnClaudeCodeInstance() spawned the `claude` child with stdio:'inherit', registered an exit handler for logging only, then returned `{ success: true, promptFile }` immediately. The command handler resolved, the CLI process finished, and the still-initializing `claude` child lost its controlling terminal and was killed/orphaned. The signature tell that confirms the diagnosis: a stray XTVERSION reply ("iTerm2 3.6.1064;1;2;4;6;17;18;21;22;52") leaked onto the next shell prompt — the terminal queried for capabilities, but the child died before reading the answer. Also explains why the existing `claudeProcess.on('exit', ...)` log lines ("Claude Code completed successfully", "Claude Code exited with code N") never printed — the parent was already gone. Fix: await the child's exit (or error) before returning. The existing exit- handler logging now works, and the non-interactive (-p / --non-interactive) path completes only after Claude Code does. Different cause from #1748 (which fixed an MCP-config issue where workers exited because they lacked mcp__ruflo__* tools via --mcp-config). Closes #2297. Co-Authored-By: clement-livdeo <noreply@github.com> Co-Authored-By: RuFlo <ruv@ruv.net> * fix(statusline): resolve installed CLI bin + bump cache TTL 10s→60s (#2337) Per shaal's report: the statusline helper ran `npx --yes @claude-flow/cli@latest hooks statusline --json` on every uncached render, cached only 10 s. Because of the `@latest` tag, npx re-resolves the package from the registry and relaunches the entire @claude-flow/cli on each call. Claude Code refreshes the statusline several times a second while streaming, and with multiple concurrent sessions this spawned a near-continuous storm of `npm exec` / node processes: - load average 40-65 on a 12-core machine (~6 concurrent sessions) - each live `npm exec` process burned 55-90 % of a core - new PIDs every 1-2 s as the storm cycled Raising the local cache TTL alone dropped the reporter's load from ~43 to ~2.3, confirming this delegation as the dominant source. Fix (applied to BOTH the committed dogfood helper at `.claude/helpers/statusline.cjs` AND the init generator template at `v3/@claude-flow/cli/src/init/statusline-generator.ts` so existing and future installs both benefit): 1. New `resolveCliBin()` — mirrors getPkgVersion()'s install-location probing and returns the absolute path to a usable `bin/cli.js` (project / monorepo / plugin marketplace / global node_modules, incl. custom-prefix layouts like ~/.npm-global). 2. `getStatuslineData()` now invokes the CLI directly via `process.execPath` + the resolved bin — no npx, no registry round-trip, no @latest re-resolve. Falls back to `npx --prefer-offline @claude-flow/cli` (no @latest) only when nothing is installed locally, so cold environments still work. 3. `CACHE_TTL_MS` 10_000 → 60_000. Closes #2337. Co-Authored-By: shaal <noreply@github.com> Co-Authored-By: RuFlo <ruv@ruv.net> --------- Co-authored-by: BIWizzard <noreply@github.com>