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

Method backstopShouldExit

src/mcp/daemon.ts:467–477  ·  view source on GitHub ↗

* Decide whether the inactivity backstop should reap the daemon right now. * Public + `isAlive`-injected for deterministic tests; the timer calls it each * tick with the real liveness probe. * * The backstop exists ONLY to catch a **phantom** client (#692) — one counted * but actually

(isAlive: (pid: number) => boolean)

Source from the content-addressed store, hash-verified

465 * client keeps the daemon up. Has the sweep's side effect (drops dead peers).
466 */
467 backstopShouldExit(isAlive: (pid: number) => boolean): boolean {
468 if (this.stopping || this.clients.size === 0) return false; // idle timer owns the no-client case
469 if (Date.now() - this.lastActivityAt < this.maxIdleMs) return false; // still within the window
470 this.reapDeadClients(isAlive);
471 if (this.clients.size === 0) return false; // sweep cleared them — idle timer takes over
472 const anyProvablyAlive = [...this.clients].some((session) => {
473 const peers = this.clientPeers.get(session);
474 return peers != null && peers.pid !== null && !peerIsDead(peers, isAlive);
475 });
476 return !anyProvablyAlive;
477 }
478
479 /**
480 * Drop every connected client whose peer process is gone. Returns the count

Callers 2

startLivenessTimersMethod · 0.95

Calls 3

reapDeadClientsMethod · 0.95
peerIsDeadFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected