/** * Process-level safety net for late transport errors. * * The failure this guards against: undici resolves `fetch()` and the request path moves on, * but the underlying socket is reset LATER — by a CDN edge, a free-tier host recycling * connections, or a discarded failover candidate whose un-read body `discardCandidate()` * cancelled. undici emits that late error on a stream with no listener, Node escalates it to * an `uncaughtException`, and with no handler installed the whole proxy exits 1. This proxy * fronts every client session, so a third party closing a socket must never take it down — * the same reasoning as an unset `${ENV}` disabling one provider instead of aborting startup. * * Design (fork-validated in freellmapi's process-safety-net, adopted 2026-08-13 — see * docs/history/freellmapi-adoption-review-2026-08-13.md §1.3): swallow ONLY a closed allowlist of * transport error codes plus a short list of Node/undici-authored message shapes, and * preserve Node's default fail-fast exit(1) for everything else, so genuine bugs still crash * loudly. The classifier is a pure function so it is unit-testable without touching global * handlers. */ /** Pure: true when the error is a transport failure that should not crash the process. */ export declare function isTransportError(err: unknown): boolean; export type ProcessErrorDecision = "swallow" | "fatal"; /** Pure: swallow transport errors; everything else keeps Node's fail-fast default. */ export declare function classifyProcessError(err: unknown): ProcessErrorDecision; type ProcessLike = Pick; export interface SafetyNetHooks { log?: (line: string, detail?: unknown) => void; exit?: (code: number) => void; /** Best-effort flush before a fatal exit (the write-behind caches' crash window). */ beforeExit?: () => void; /** Injectable process for tests; the idempotence guard applies only to the real one. */ proc?: ProcessLike; } /** * Decide and act on a process-level error. Returns the decision so tests can assert it: * `swallow` logs one line and lets the process continue; `fatal` flushes (best-effort) and * exits 1, preserving Node's default. */ export declare function handleProcessError(kind: "uncaughtException" | "unhandledRejection", err: unknown, hooks?: SafetyNetHooks): ProcessErrorDecision; /** Test-only: forget that the real-process handlers were installed. */ export declare function resetProcessSafetyNet(): void; /** * Install the global handlers. Idempotent on the real process. Call at the top of the serve * path, before the server takes traffic — a CLI subcommand does not need (or get) it. */ export declare function installProcessSafetyNet(hooks?: SafetyNetHooks): void; export {};