* PPID watchdog (#277) — direct mode only. Daemon mode is detached on purpose * and reaps via idle timeout; proxy mode installs its own watchdog inside * runProxy. So this only ever runs for an in-process direct session.
()
| 424 | * {@link runProxy}. So this only ever runs for an in-process direct session. |
| 425 | */ |
| 426 | private installPpidWatchdog(): void { |
| 427 | if (this.mode !== 'direct') return; |
| 428 | const pollMs = parsePpidPollMs(process.env.CODEGRAPH_PPID_POLL_MS); |
| 429 | if (pollMs <= 0) return; |
| 430 | this.ppidWatchdog = setInterval(() => { |
| 431 | const reason = supervisionLostReason({ |
| 432 | originalPpid: this.originalPpid, |
| 433 | currentPpid: process.ppid, |
| 434 | hostPpid: this.hostPpid, |
| 435 | isAlive: isProcessAlive, |
| 436 | }); |
| 437 | if (reason) { |
| 438 | process.stderr.write( |
| 439 | `[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n` |
| 440 | ); |
| 441 | this.stop(); |
| 442 | } |
| 443 | }, pollMs); |
| 444 | this.ppidWatchdog.unref(); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | function sleep(ms: number): Promise<void> { |
no test coverage detected