* 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.
()
| 496 | * {@link runProxy}. So this only ever runs for an in-process direct session. |
| 497 | */ |
| 498 | private installPpidWatchdog(): void { |
| 499 | if (this.mode !== 'direct') return; |
| 500 | const pollMs = parsePpidPollMs(process.env.CODEGRAPH_PPID_POLL_MS); |
| 501 | if (pollMs <= 0) return; |
| 502 | this.ppidWatchdog = setInterval(() => { |
| 503 | const reason = supervisionLostReason({ |
| 504 | originalPpid: this.originalPpid, |
| 505 | currentPpid: process.ppid, |
| 506 | hostPpid: this.hostPpid, |
| 507 | isAlive: isProcessAlive, |
| 508 | }); |
| 509 | if (reason) { |
| 510 | process.stderr.write( |
| 511 | `[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n` |
| 512 | ); |
| 513 | this.stop(); |
| 514 | } |
| 515 | }, pollMs); |
| 516 | this.ppidWatchdog.unref(); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | function sleep(ms: number): Promise<void> { |
no test coverage detected