claude-flow
Version:
Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration
42 lines • 1.79 kB
TypeScript
/**
* Parent-death watchdog (#2234).
*
* `ruflo mcp start` runs as a double-forked grandchild of Claude Code (`npx -y
* ruflo … mcp start` → `npm exec …` → `node … mcp start`). When Claude Code
* exits, only the `npm exec` shim is terminated; the `node` server reparents to
* `launchd`/`init` (`ppid === 1`) and silently lingers — leaving ~50 MB and an
* open database handle per restart. Over a week this accumulates to ~20
* orphaned servers (~1 GB), and an arbitrary stale one can win the next stdio
* handshake, transparently serving superseded code.
*
* Cheap, robust fix: poll `process.ppid`. When it becomes 1 (and didn't start
* there), our original parent has exited — we're orphaned. Run the cleanup
* hook and exit cleanly.
*
* @module runtime/parent-death-watchdog
*/
export interface ParentDeathWatchdogOptions {
/** Poll interval in ms. Default 2000. */
intervalMs?: number;
/**
* Cleanup hook fired when orphaning is detected. May be async. After it
* resolves (or throws), the process exits with code 0 (success) / 1 (error).
* Defaults to `process.exit(0)` directly.
*/
onOrphaned?: () => void | Promise<void>;
/** Override `process.ppid` getter (tests). */
ppidGetter?: () => number;
/** Override `process.exit` (tests). */
exit?: (code: number) => void;
}
export interface ParentDeathWatchdog {
stop(): void;
/** Manually trigger the orphan check (used by tests). */
checkOnce(): Promise<void>;
}
/**
* Install a parent-death watchdog. Safe to call once per process; calling
* twice replaces the previous interval.
*/
export declare function installParentDeathWatchdog(opts?: ParentDeathWatchdogOptions): ParentDeathWatchdog;
//# sourceMappingURL=parent-death-watchdog.d.ts.map