UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

67 lines • 4.27 kB
/** * HOW a supervisor leaves without ending work: the handoff drain (SIGUSR1 to its child, a soft grace * that never kills busy sessions), the watch that turns a lost public entry into a drain, and the win32 * identity watchdog that notices a child gone without an exit event. Split out of `host-lifecycle.ts`, * which keeps the supervisor's orchestration (senpi#2566). Nothing here sends a terminating signal. */ import type { ChildProcess } from "node:child_process"; import { type HostStopSender } from "./host-crash-record.ts"; import type { HostGenerationPaths } from "./host-daemon-paths.ts"; import { type SupersessionPointer } from "./host-supersession.ts"; import type { SocketFileIdentity } from "./socket-ownership.ts"; export declare class SupervisorDrain { private draining; private graceTimer; private readonly child; private readonly shuttingDown; private readonly beginStopping; private readonly relay; private readonly overdue; /** * `relay` is the child's drain-request file (host-stop-intent.ts): the one way to reach a child * on every platform. Without it the request is the POSIX signal alone. `overdue` hears every grace * period the child is still draining (senpi#7098). */ constructor(child: ChildProcess, shuttingDown: () => boolean, beginStopping?: () => void, relay?: { readonly file: string; readonly sender: HostStopSender; }, overdue?: (drainingForMs: number) => void); get active(): boolean; /** * Ask the child to announce and park attached sessions as turns/requests settle. The supervisor * owns the soft grace from this instant; expiry rescans but NEVER kills busy sessions. Child * exit ends the supervisor regardless of clients that keep their connections open. */ drain(): void; stop(): void; /** Every expiry while the child still runs is reported and re-asks for a drain; nothing is ever cut short. */ private armGrace; /** * The signal-free drain request (#3653): armed BEFORE it is advertised, so an asker that finds the * marker never writes into a generation that is not yet reading. A marker that cannot be written * only leaves this generation reachable by the POSIX signal, as before. */ acceptRequests(generation: HostGenerationPaths): Promise<() => void>; private requestChildDrain; } /** The alarm a drain past its grace leaves beside the generation's crash records, which host alarms read. */ export declare function recordDrainOverdue(daemonDir: string, generation: string, drainingForMs: number): void; /** * Losing the public entry IS a drain request: nothing can reach this supervisor by path any more, and * the handoff that replaced it may never have signalled (#1893). A name that was deleted rather than * taken over is the same loss with nobody serving the path (#1961). */ export declare function drainOnPublicSocketLoss(path: string, identity: SocketFileIdentity | undefined, settled: () => boolean, drain: SupervisorDrain, onReplaced: () => void, pointer?: SupersessionPointer): () => void; /** * win32 only: a child that is gone, or whose pid now names another process, has exited even when no exit event came. * * The start time (a cold PowerShell CIM spawn) is read ONCE, at registration: it never changes while the pid is * live, and reading it every tick cost one or two WMI cold starts a second for the host's whole life (senpi#4684). * Each tick is a free `childLiveness`. Two dead ticks in a row are death. The pid can only be reused after the * child died, and our own child cannot answer EPERM, so the start time is read again only when the pid looked * dead and answers again, or liveness is inconclusive; a different start time is then death. Those reads, and the * retries of a failed registration read, back off to one a minute. A failed or absent read is UNKNOWN, never * death: a supervisor that died on a timed-out probe took its host with it (`connect ENOENT`, `reported dead`). */ export declare function watchWin32ChildIdentity(child: Pick<ChildProcess, "pid" | "exitCode" | "signalCode">, shuttingDown: () => boolean, onGone: () => void): Promise<() => void>; //# sourceMappingURL=host-lifecycle-drain.d.ts.map