@sema-agent/core
Version:
Stateless, task-oriented AI agent core
42 lines (41 loc) • 2.26 kB
JavaScript
import { CheckpointError, resolveCheckpointStore } from "../checkpoint-store.js";
import { compositionLegRecord } from "./checkpoint-scope.js";
import { expireRowWithDuty } from "./expire-settle.js";
import { settleTeardownLeg } from "./teardown-bounded.js";
export async function voidVerifierPause(input) {
const { token, runner, sessions, locallyClaimedTokens, parentConstraintRegistry, suspendedEnvReaps } = input;
const store = resolveCheckpointStore({}, runner.deps);
if (store === undefined)
throw new CheckpointError("checkpoint.not_found", "no CheckpointStore wired (RunnerDeps.checkpointStore) — there is no verifier card to void");
const cp = await store.get(token);
if (cp === null)
throw new CheckpointError("checkpoint.not_found", "no checkpoint row for this token — nothing was voided");
const leg = compositionLegRecord(cp.state.compositionLeg);
if (leg?.entry !== "verify") {
throw new CheckpointError("resume.composition_mismatch", `this card was not parked by a verification gate's verifier leg (it records ${leg === undefined ? "no composition leg" : `a ${leg.entry} leg`}) — ` +
"voidVerifierPause voids only a verifier's own card; nothing was settled and the row is as it was", { reason: "not_a_verifier_card" });
}
const report = (err, sessionId) => {
try {
runner.deps.onError?.(err, { phase: "config", sessionId });
}
catch {
}
};
const won = await expireRowWithDuty({
token, scope: cp.scope, store, locallyClaimedTokens, parentConstraintRegistry, suspendedEnvReaps,
destroyLabel: "voided verifier pause env destroy",
onDestroyError: report,
});
if (!won)
return false;
let unpinErr;
await settleTeardownLeg(() => sessions.unpin?.(cp.sessionId), "sessions.unpin (voided verifier pause)", (err) => {
unpinErr = err;
report(err, cp.sessionId);
});
if (unpinErr !== undefined) {
throw new CheckpointError("checkpoint.void_unpin_failed", `the verifier card was voided (the row is expired) but its session's pin was not released: ${unpinErr.message} — the session stays pinned until it is unpinned`);
}
return true;
}