import type { DeliverHookPayload, SessionCapabilities } from "#channel/types.js"; import type { DurableSessionState } from "#execution/durable-session-store.js"; import type { HarnessModelMessage } from "#harness/messages.js"; import type { SessionInboxHandle, SessionInboxPayload } from "#execution/session-inbox/inbox.js"; import type { TurnSelection } from "#execution/session/input-queue.js"; import type { WorkflowEntryResult } from "#execution/session/entry-input.js"; import type { AgentWorkflowRetentionDefinition } from "#shared/agent-definition.js"; /** * Cross-deployment checkpoint contract. The successor may run a different eve * build than the owner that produced it; bump when any field changes shape so * an older successor rejects the handoff instead of misreading state. * * A newer successor must always accept older checkpoints: every bump adds the * upgrade from the previous version in `checkpoint-migrations.ts`. */ export declare const SESSION_CHECKPOINT_VERSION = 13; /** Everything a successor needs to continue an idle session. Hooks are derived from the state. */ export interface SessionCheckpoint { readonly version: typeof SESSION_CHECKPOINT_VERSION; readonly capabilities?: SessionCapabilities; readonly history: HarnessModelMessage[]; readonly retention?: AgentWorkflowRetentionDefinition; readonly serializedContext: Record; readonly sessionState: DurableSessionState; readonly sessionTimeoutMs: number | false; } export type SessionOwnerActivation = { readonly kind: "active"; } | { readonly kind: "incompatible"; readonly reason: "checkpoint-version"; /** Commands accepted by partial successor claims before it rejected the checkpoint. */ readonly payloads: readonly SessionInboxPayload[]; } | { readonly kind: "failed"; readonly error: unknown; /** Commands accepted by partial successor claims before startup failed. */ readonly payloads: readonly SessionInboxPayload[]; }; interface SessionHandoffInput { readonly checkpoint: Omit; readonly deploymentId: string; readonly inbox: SessionInboxHandle; readonly isInitialOwner: boolean; readonly sessionId: string; } export declare function sessionAnchorToken(sessionId: string): string; type SessionTransferOutcome = { readonly kind: "transferred"; } | { readonly kind: "retained"; readonly reason: SessionRetainedReason; }; type SessionRetainedReason = "same-deployment" | "missing-deployment" | "not-idle" | "busy" | "accepted-during-release" | "activation-failed" | "checkpoint-incompatible" | "known-incompatible"; /** A compaction handoff the owner owes; the successor keeps this deadline. */ export interface CompactionHandoff { readonly sessionTimeoutDeadline: Date | undefined; } type SessionTransferState = Pick; /** * The sole boundary for moving an idle session to a successor run: on another * exact deployment when newer code accepts a delivery, or on this deployment * after compaction so no single run's event log grows with the session. * Constructed once per owner; each `try*` method attempts one transfer. * When the upstream atomic hook-handoff primitive lands, only this class changes. * * Skipping known-incompatible targets requires this owner run to execute the * `incompatible` activation branch below. Owners still on an older eve build * treat that signal as a generic failure and attempt handoff on every turn; * they still benefit from successors returning incompatibility without step * retries. */ export declare class SessionHandoff { private readonly input; private anchor; /** Deployments that rejected this session's checkpoint during this owner run. */ private readonly incompatibleTargetDeploymentIds; constructor(input: SessionHandoffInput); /** * Attempts to move the session to the selected delivery's deployment. When a * compaction handoff is due and that deployment is this one or unknown, the * session moves to a fresh run here instead. The outcome states whether the * successor activated or this owner retained the session. Candidate failures * recover locally rather than escaping. */ tryTransfer(selection: TurnSelection, state: SessionTransferState, options?: { readonly compaction?: CompactionHandoff; }): Promise; /** * Attempts to move a session that compacted to a fresh run on this * deployment. Without a delivery the caller guarantees no input is waiting, * and the successor parks until the next one arrives. The successor keeps * the session's deadline. */ tryCompactionTransfer(state: SessionTransferState, compaction: CompactionHandoff & { readonly delivery?: DeliverHookPayload; }): Promise; private transfer; /** After a transfer, the original run parks until the final owner reports the session result. */ awaitAnchoredResult(): Promise; disposeAnchor(): Promise; /** Starts the candidate and waits for it to activate or fail. */ private startAndActivate; /** Reclaims the exact hook set and replays payloads accepted while it was released. */ private recover; private reportRetained; private ensureAnchor; } export {};