MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / installCommandSupervision

Function installCommandSupervision

src/bin/command-supervision.ts:54–78  ·  view source on GitHub ↗
(label: string, watchdog: WatchdogOptions = {})

Source from the content-addressed store, hash-verified

52 * SIGKILLed (#1231).
53 */
54export function installCommandSupervision(label: string, watchdog: WatchdogOptions = {}): CommandSupervision {
55 // Liveness watchdog: a separate process that SIGKILLs us if our event loop
56 // stops turning for too long (a wedged synchronous loop). Self-disables on
57 // CODEGRAPH_NO_WATCHDOG.
58 const liveness = installMainThreadWatchdog(watchdog);
59
60 // PPID watchdog: detect that the parent (or the host threaded past the
61 // relaunch shim) died and we've been orphaned, then exit instead of leaking.
62 const stopParentWatch = watchParent((reason) => {
63 try {
64 process.stderr.write(`[CodeGraph ${label}] Parent process exited (${reason}); aborting.\n`);
65 } catch { /* stderr gone with the parent — exit anyway */ }
66 process.exit(1);
67 });
68
69 let stopped = false;
70 return {
71 stop(): void {
72 if (stopped) return;
73 stopped = true;
74 stopParentWatch();
75 liveness?.stop();
76 },
77 };
78}
79
80/**
81 * Call `onLost` once, when the parent — or the host threaded past the

Callers 2

runIndexFunction · 0.90
mainFunction · 0.90

Calls 4

watchParentFunction · 0.85
exitMethod · 0.80
writeMethod · 0.65

Tested by

no test coverage detected