UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

64 lines (63 loc) • 4.13 kB
/** * Reverting one consolidation driver run by its run id. The run's products — those of the plans its run account lists * (`ConsolidationDriverRunRow.planIds`) that stand in the store at the rev they were minted at — are challenged in one * batch through the engine's challenge account, so they leave the active set, their supersession edges suspend * (`deriveSupersededSet`) and the inputs those edges held back come back. No second mechanism: a withdrawn product is a * challenged product. The revert is one-way: nothing here promises that resolving the generation brings a product back * (the challenge's model-visible guidance may lead a later session to delete it). * * What is reverted, stated: the scope's LATEST driver run (the run account keeps one row per scope), once it has settled * and no plan holds the scope's seat (a pending run or a seated plan would still write). Whether a product landed is read * off the committed store, not off the plan's product states. A product edited after the run is not challenged and is * named; one another challenge already withholds is challenged too, under a generation of this revert's own. A plan of the * scope whose request id has the run's cycle spelling but that the run account does not list — a cycle whose commit threw * or whose row write was lost, or another caller's plan under that spelling — is named, never touched. * * A retry with the same `requestId` hands the challenge writer the same event ids, so it opens no new generation; its * receipt reports the state at the time of the retry (a product whose generation of this revert was resolved since is * `resolved`, not withdrawn). */ import type { MemoryEngine } from "./engine.js"; /** The engine faces the revert reads and the one it writes through. `MemoryEngine` satisfies it. */ export type ConsolidationRunRevertEngine = Pick<MemoryEngine, "readConsolidationDriverRun" | "readConsolidationGateState" | "listCommittedHeaders" | "readChallengeExclusions" | "challengeEntries" | "governance">; export interface RevertConsolidationRunInput { scope: string; /** The `runId` of the run's receipt (`ConsolidationRunReceipt.runId`). */ runId: string; /** The host's note, recorded on each challenge event (host audit face). */ reason: string; /** The idempotency identity: a retry carries the same id and opens no new generation. */ requestId: string; } export interface ConsolidationRunRevertReceipt { runId: string; scope: string; /** Products of the run withheld now, with the generation of this revert's challenge on each. */ withdrawn: Array<{ id: string; planId: string; generation: number; }>; /** Products of the run this revert does not withhold: edited after the run, no longer standing in this scope, or * withheld once by this revert and no longer (its generation was resolved since). */ notWithdrawn: Array<{ id: string; planId: string; why: "edited_since_run" | "absent" | "resolved"; }>; /** Every entry a landed product of the run superseded, as it stands once the revert is written; `by` names the * carrier that holds a `superseded` one back now. */ inputs: Array<{ id: string; state: "active" | "superseded" | "withheld" | "absent"; by?: string; }>; /** Plans of the scope with the run's cycle spelling that the run account does not list: not touched. */ unlistedPlans: string[]; /** Plans the run account lists that could not be read: their products were not considered. */ unreadablePlans: string[]; } /** Revert the scope's latest settled consolidation driver run (see the module comment). Refuses `memory.consolidation_refused` * — having written nothing — when an argument is not a non-empty string, when `runId` is not the scope's latest run, when * that run is pending, or when a plan holds the scope's seat. */ export declare function revertConsolidationRun(engine: ConsolidationRunRevertEngine, input: RevertConsolidationRunInput): Promise<ConsolidationRunRevertReceipt>;