UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

57 lines (56 loc) • 4.15 kB
/** * A run continues a session whose log lost records: the leg's view of the session's storage tells the run what the replay that loaded the * log dropped (`SessionStorage.getReplayLoss`), at the first branch read of the run. Two findings, one notice a leg: * * - the branch read broke at a parent the log does not hold, and the replay dropped records (the {@link LineageBreak}'s `replayLoss`) — * the evidence that the missing parent may be one of them: the branch ends at the entry that names it, the entries that survive below * the break are the conversation the run continues, and the finding is a `break`; * - the branch is whole but the replay dropped records (the log's last records were unreadable and its head fell back to the last one * still readable, or the damage sat off the branch): the finding is the count and the head the run continues from. * * The stop is the walk's own floor stop (`pathToRoot` with the break's child as the floor), so no second walk exists. A break the * replay cannot account for (it dropped nothing: a log written with a parent it never held) is refused as it was — `corrupt_session` — * and so is every reader outside a run (a fork, an export, the store kit), which gets no announcement and so no re-root. */ import { type SessionStorage } from "../../internal/harness.js"; import type { NoticeSeatInput } from "./notice-seat-input.js"; /** What a branch read found of the records the log's replay dropped: the replay's count, the head the branch was read from (`null` = nothing * of the log is readable) and the branch's length. */ export interface BranchLoss { readonly recordsDropped: number; readonly recordsTotal: number; readonly leaf: string | null; readonly entriesOnPath: number; } /** What one re-rooted branch read found besides: the parent the log does not hold, the entry the branch now starts at, and how many entries * of the log do not descend from that entry (the history above the break, and its side branches). */ export interface LineageReroot extends BranchLoss { readonly leaf: string; readonly missingParentId: string; readonly rootedAt: string; readonly entriesCut: number; } /** What a branch read found: the branch broke (and was ended at the break), or it is whole and the replay dropped records. */ export type ReplayLossFinding = ({ readonly break: false; } & BranchLoss) | ({ readonly break: true; } & LineageReroot); /** The leg's view of `storage`: every member as the storage answers it, but a branch read that breaks at a replay-proven loss ends at the * break, and a branch read in a log whose replay dropped records is reported to `found` (`leaf` = the entry the read started from). */ export declare function viewThroughReplayLoss(storage: SessionStorage, found: (finding: ReplayLossFinding) => void): SessionStorage; /** The leg's account of what the log's replay dropped (`session.lineage_rerooted`): one a leg for a whole branch, one a break for a broken one * (whichever read met it first), and a broken branch's notice already carries the count, so a whole branch read after it says nothing more. */ export declare function replayLossSeat(ids: Pick<NoticeSeatInput, "onNotice" | "runId">): (finding: ReplayLossFinding, sessionId: string) => void; /** One leg's reading of what the log's replay dropped. The acquire phase reads again after a lost write race and keeps only the attempt * that holds, so what an attempt found is held until the phase settles on one and said then (a break before a whole branch, so the break's * notice is the leg's only one); reads after that are said as they are made. */ export interface ReplayLossLeg { /** `storage` as this leg reads it, naming the session its findings are about. */ view(storage: SessionStorage, sessionId: string): SessionStorage; /** The attempt that found what is held is discarded: none of it is said. */ discard(): void; /** The attempt that holds is known: say what it found. */ settle(): void; } export declare function replayLossLeg(ids: Pick<NoticeSeatInput, "onNotice" | "runId">): ReplayLossLeg;