* PPID watchdog mirroring the one in `MCPServer.start` — kills the proxy if * the MCP host (or its proxy of a host, see HOST_PPID_ENV) goes away without * closing stdin. Issue #277 documents why we can't rely on stdin EOF on * Linux: the parent may be SIGKILL'd and reparenting doesn't close pipes
(socket: net.Socket)
| 812 | * watchers to clean up, so this is cheap. |
| 813 | */ |
| 814 | function startPpidWatchdog(socket: net.Socket): void { |
| 815 | const pollMs = parsePollMs(process.env.CODEGRAPH_PPID_POLL_MS); |
| 816 | if (pollMs <= 0) return; |
| 817 | // Baseline from the CLI entry's earliest capture, not process.ppid here — |
| 818 | // a launcher killed during our first ~100ms would otherwise leave the |
| 819 | // baseline at 1 and blind the divergence check forever (#1185). |
| 820 | const originalPpid = EARLY_PPID; |
| 821 | const hostPpid = parseHostPpid(process.env[HOST_PPID_ENV]); |
| 822 | const timer = setInterval(() => { |
| 823 | const reason = supervisionLostReason({ |
| 824 | originalPpid, |
| 825 | currentPpid: process.ppid, |
| 826 | hostPpid, |
| 827 | isAlive: isProcessAliveLocal, |
| 828 | }); |
| 829 | if (reason) { |
| 830 | process.stderr.write(`[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n`); |
| 831 | try { socket.destroy(); } catch { /* ignore */ } |
| 832 | process.exit(0); |
| 833 | } |
| 834 | }, pollMs); |
| 835 | timer.unref?.(); |
| 836 | } |
| 837 | |
| 838 | function parsePollMs(raw: string | undefined): number { |
| 839 | return parseDelayMs(raw, DEFAULT_PPID_POLL_MS); |
no test coverage detected