@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
52 lines • 3.36 kB
TypeScript
/**
* HOW an ensure stops a supervisor it is entitled to stop: SIGTERM, a deadline, then SIGKILL - with
* the stop intent on record before the first signal and, when the SIGKILL was needed, the terminal
* record written by THIS process, because a SIGKILLed supervisor runs no exit handler (senpi#2566).
* Split out of `host-ensure.ts`.
*/
import type { ChildProcess } from "node:child_process";
import { type DaemonPidFile } from "../../utils/process-identity.ts";
import type { HostStopSender } from "./host-crash-record.ts";
import type { HostGenerationPaths } from "./host-daemon-paths.ts";
import type { ChildExit } from "./host-readiness.ts";
import { type HostStopIntent } from "./host-stop-intent.ts";
export declare const DEFAULT_STOP_TIMEOUT_MS: number;
export declare const SIGKILL_GRACE_MS = 2000;
/**
* The longest a SIGTERM wait here can run: the ordinary window, or a supervisor's reported stall wait. The
* stall wait is read from the same `SENPI_RPC_CHILD_STALLED_STOP_MAX_MS` the supervisor bounds itself by, so
* an operator who raises it also raises every lock and deadline sized from this budget.
*/
export declare const STOP_WAIT_BUDGET_MS: number;
export interface StopTarget {
readonly daemonDir: string;
readonly generation: HostGenerationPaths;
readonly instanceId: string;
readonly sender: HostStopSender;
readonly reason: string;
}
export declare function ensureSender(): HostStopSender;
export declare function announceStop(target: StopTarget, targetPid: number): Promise<HostStopIntent>;
/**
* Ownership for the reuse decision. An identity we cannot read proves nothing: it can neither
* claim the host nor authorize a kill, so it reads as "not ours" and the caller starts fresh
* rather than failing the whole ensure on an observation gap.
*/
export declare function matchesPidFileOrUnknown(pidFile: DaemonPidFile, probe: (pid: number) => Promise<string | undefined>): Promise<boolean>;
/**
* The supervisor was SIGKILLed and is gone: record the generation's end before the caller releases
* the registration that holds the intent. The intent as the supervisor last left it wins - it may have
* layered its own step on - and the one this caller wrote stands in when the file is gone.
*/
export declare function recordEscalation(target: StopTarget, announced: HostStopIntent): Promise<void>;
export declare function stopSpawnedChild(child: ChildProcess, childExit: Promise<ChildExit>, termTimeoutMs: number, target: StopTarget): Promise<void>;
/** Replacing a managed host nothing can reach: only through its validated pidfile (I1). */
export declare function stopManagedHost(pidFile: DaemonPidFile, termTimeoutMs: number, target: StopTarget, readStartTime?: (pid: number) => Promise<string | undefined>): Promise<void>;
type PidFileOwnership = "owns" | "gone" | "unknown";
export declare function resolvePidFileOwnership(pidFile: DaemonPidFile, readStartTime?: (pid: number) => Promise<string | undefined>): Promise<PidFileOwnership>;
/** ESRCH means the process is already gone, which is what every caller here wants. */
export declare function signalPid(pid: number, signal: NodeJS.Signals): void;
export declare function delay(ms: number): Promise<void>;
export declare function isNodeErrorCode(error: unknown, code: string): boolean;
export {};
//# sourceMappingURL=host-ensure-stop.d.ts.map