()
| 578 | // hang. Instead, fall back to the in-process engine until a daemon answers |
| 579 | // again, and re-serve whatever the dead daemon never answered. |
| 580 | const onDaemonLost = (): void => { |
| 581 | if (shuttingDown || daemonSocket !== socket) return; // host teardown, or already handled |
| 582 | daemonStatus = 'failed'; |
| 583 | daemonSocket = null; |
| 584 | try { socket.destroy(); } catch { /* ignore */ } |
| 585 | process.stderr.write( |
| 586 | `[CodeGraph MCP] Shared daemon connection lost; serving this session in-process (degraded), re-serving ${inflight.size} in-flight request(s).\n` |
| 587 | ); |
| 588 | const orphaned = [...inflight.values()]; |
| 589 | inflight.clear(); |
| 590 | for (const line of orphaned) void handleLocally(line); |
| 591 | // A link that stayed up past the longest wait starts the backoff over; one |
| 592 | // that keeps dropping right after it attaches keeps backing off. |
| 593 | if (Date.now() - attachedAt >= retryMaxMs) retryDelayMs = retryBaseMs; |
| 594 | scheduleDaemonRetry(); |
| 595 | }; |
| 596 | socket.on('close', onDaemonLost); |
| 597 | socket.on('error', onDaemonLost); |
| 598 | // A daemon that came up mid-session has never seen this client: prime its |
nothing calls this directly
no test coverage detected