import type { Employee, EngineSessionRef, Session } from "../../shared/types.js"; import { type UpdateSessionFields } from "../registry.js"; import type { TurnSurface } from "./types.js"; /** The three ways a turn can end. Anything else is not terminal. */ export type TurnOutcome = "succeeded" | "failed" | "interrupted"; export interface SettleTurnInput { sessionId: string; attemptToken: string; outcome: TurnOutcome; result?: string | null; error?: string | null; cost?: number; durationMs?: number; /** * This turn's cost/turn delta. Present whenever an engine actually ran — * including a rate-limit fallback or retry, because a recovered turn is still * a turn. Absent only for aborts that never reached an engine. */ accounting?: { cost?: number; numTurns?: number; }; /** Native engine-session id, filed inside the receipt's own fenced write so a * resume finds it and a losing turn never overwrites a newer turn's. */ engineSession?: { engine: string; nativeId: string; meta?: Omit; }; /** Transport fields folded into the same write as the receipt. */ fields?: UpdateSessionFields; /** * Statuses the attempt may settle from. The default running-only fence is * what makes an interrupted row immutable to a late success; the rate-limit * timeout widens it because that turn settles out of `waiting`. */ expectedStatuses?: readonly Session["status"][]; employee?: Employee; /** Interrupters pass false — they report the interrupt themselves. The status * reconciler, the interrupt nobody is left to report, keeps the default. */ notifyParent?: boolean; surface: TurnSurface; } /** * The single completion path. Every terminal receipt in every runner is written * here, in this fixed order: account for the turn, write the receipt — engine * session included — wake the parent, tell the transport. * * It exists because two runners each grew their own copy of that sequence and * drifted — one of them silently skipped accounting, which disabled employee * budget caps for the majority of turns. Adding a completion site anywhere else * re-opens exactly that hole. * * Returns the settled session, or undefined when a stop, reset, or newer turn * has already taken ownership of the attempt. */ export declare function settleTurn(input: SettleTurnInput): Promise; //# sourceMappingURL=completion.d.ts.map