@sema-agent/core
Version:
Stateless, task-oriented AI agent core
41 lines (40 loc) • 3.13 kB
TypeScript
/**
* The resume ladder's deployment PREFLIGHT rung (E9), verbatim from `Runner.resumeStream`:
* the LAST rung before the CAS. The deployment's `resumePreflight` screens the resume off the persisted row's
* facts under its own validated deadline; every non-answer arm refuses retry-later (the row stays pending);
* only an explicit, fully readable `terminal` verdict settles the row through the single-shot expire CAS
* (with the reap duty that win carries), and the window verdict is re-asserted after the hook's await.
*
* Async (the seat, the expire, the loss re-read, the bounded destroy). It ends by handing off to the rung
* after it (`next`) in its LAST continuation — the claim opens on the tick the preflight cleared — and
* returns what that rung returns.
*/
import { type Checkpoint, type CheckpointStore, type CheckpointToken } from "../checkpoint-store.js";
import type { InheritedGate, InstallingPhaseResult, RunnerDepsSeat, SuspendReap } from "./contracts.js";
export interface ResumePreflightInput<R> {
/** borrowed-readonly — the checkpoint token (handed to the deployment and to the settling CAS). */
token: CheckpointToken;
/** borrowed-readonly — the pending row; the deployment reads its persisted facts, never the caller's bag. */
cp: Checkpoint;
/** borrowed-readonly — the ONE signal read from admission; the seat's wait is bounded by it. */
resumeSignal: AbortSignal | undefined;
/** borrowed-readonly — the window verdict to re-assert after the seat's await (undefined when unarmed). */
recheckGovernanceWindow: (() => Promise<void>) | undefined;
/** borrowed-readonly — the store the row lives in (the terminal arm's expire and its loss re-read). */
store: CheckpointStore;
/** borrowed-readonly — the Runner's deployment deps, read LIVE through the Runner (reads `resumePreflight`, `resumePreflightTimeoutMs`, `onError` (after the seat's await too) and is the seat's owner); the one home of why it is a
* seat and not a captured object is {@link RunnerDepsSeat}. */
runner: RunnerDepsSeat;
/** borrowed-mutable — the Runner's same-Runner claim marks: opened with the expire attempt, released at the duty decision. */
locallyClaimedTokens: Set<CheckpointToken>;
/** borrowed-mutable — the Runner's parked-constraint registry: the token's entry is evicted when the terminal arm wins. */
parentConstraintRegistry: Map<CheckpointToken, NonNullable<InheritedGate["parentConstraints"]>>;
/** borrowed-mutable — the Runner's suspended-env reap handles: the winning terminal arm takes and destroys this token's. */
suspendedEnvReaps: Map<CheckpointToken, SuspendReap>;
/** borrowed-readonly — the rung after the preflight, entered in this rung's last continuation. */
next: (screened: ResumePreflightResult) => Promise<R>;
}
/** The preflight's completion is its whole result: every refusal throws, so reaching `next` IS the fact. */
export interface ResumePreflightResult extends InstallingPhaseResult {
}
export declare function resumePreflight<R>(input: ResumePreflightInput<R>): Promise<R>;