* 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.
()
| 452 | * {@link runProxy}. So this only ever runs for an in-process direct session. |
| 453 | */ |
| 454 | private installPpidWatchdog(): void { |
| 455 | if (this.mode !== 'direct') return; |
| 456 | const pollMs = parsePpidPollMs(process.env.CODEGRAPH_PPID_POLL_MS); |
| 457 | if (pollMs <= 0) return; |
| 458 | this.ppidWatchdog = setInterval(() => { |
| 459 | const reason = supervisionLostReason({ |
| 460 | originalPpid: this.originalPpid, |
| 461 | currentPpid: process.ppid, |
| 462 | hostPpid: this.hostPpid, |
| 463 | isAlive: isProcessAlive, |
| 464 | }); |
| 465 | if (reason) { |
| 466 | process.stderr.write( |
| 467 | `[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n` |
| 468 | ); |
| 469 | this.stop(); |
| 470 | } |
| 471 | }, pollMs); |
| 472 | this.ppidWatchdog.unref(); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | function sleep(ms: number): Promise<void> { |
no test coverage detected