@sema-agent/core
Version:
Stateless, task-oriented AI agent core
31 lines (30 loc) • 2.28 kB
TypeScript
/**
* The TaskStream façade's REAP lane (T4), verbatim from `Runner.runTaskStream`: `destroy()`'s
* once-memoized work for a run that SUSPENDED. Runs AFTER `run` has settled (the destroy verb awaits the run before
* calling it), fences any concurrent resume first (the single-shot `expire` CAS — only the winner destroys the
* paused env; a loser retires its reap record only when no same-Runner claimant is in flight), evicts the
* terminally expired token's parked-constraint entry, and destroys the paused env best-effort behind a
* swallow-guarded onError sink so the memoized `destroy()` promise keeps its "never throws" contract.
*
* The lane returns the same async function the one-file façade declared; the destroy verb still calls it in the
* same position (after its own `await orTimeout(run.catch(…))`), so every await inside it sits on the tick it did.
*/
import type { CheckpointToken } from "../checkpoint-store.js";
import type { InheritedGate, RunnerDepsSeat, SuspendReap, TaskStreamLiveSeat } from "./contracts.js";
export interface StreamReapInput {
/** borrowed-readonly — the stream's live state; `reapHandle` is read ONCE at the call (the run has settled, so it is the terminal fact). */
live: TaskStreamLiveSeat;
/** borrowed-readonly — the Runner's deployment deps, read LIVE (`onError`, after the fence's await too). */
runner: RunnerDepsSeat;
/** borrowed-readonly — the Runner's same-Runner claim marks: a lost fence preserves the reap record only while one is in flight. */
locallyClaimedTokens: Set<CheckpointToken>;
/** borrowed-mutable — the Runner's parked-constraint registry: the expired token's entry is evicted. */
parentConstraintRegistry: Map<CheckpointToken, NonNullable<InheritedGate["parentConstraints"]>>;
/** borrowed-mutable — the Runner's suspended-env reap handles: the winner (and an unclaimed loser) retires this token's record. */
suspendedEnvReaps: Map<CheckpointToken, SuspendReap>;
}
export interface StreamReapResult {
/** The reap step the destroy verb runs after the run settled: fence, evict, destroy the paused env — never throws. */
reapSuspended: () => Promise<void>;
}
export declare function streamReap(input: StreamReapInput): StreamReapResult;