import type { LaneRecord } from "../autonomy/lane-tracker.ts"; import type { GoalState } from "../goals/goal-state.ts"; import type { AgentBindingContract, AgentResumeContext, AttemptRetryState, AttemptUsageSnapshot, ExecutionGrant, WorkerExecutionContract, WorkerResultContract, WorkerRole } from "../orchestration/contracts.ts"; import { DelegationOrchestrationLedger, type PrepareDelegationInput, type PrepareManagedDelegationInput, type StartedDelegationAttempt } from "../orchestration/delegation-ledger.ts"; import type { OrchestrationEventStore } from "../orchestration/event-store.ts"; import type { AttemptDispatchReadiness, AttemptRuntimeState, TaskRuntimeProjection } from "../orchestration/task-runtime.ts"; export type PendingVerificationRecovery = { action: "dispatch"; subjectTaskId: string; implementationProfileId: string; summary: string; artifactUris: readonly string[]; verifierExecutionContract?: WorkerExecutionContract; } | { action: "reconcile"; subjectTaskId: string; verifierTaskId: string; verifierAttemptId: string; verdict: "accepted" | "rejected" | "inconclusive"; reasonCode: string; }; /** * Sole owner of in-process worker lifecycle state. LaneRecord is a compatibility/UI projection; * all transitions are committed through DurableTaskRuntime before the projection is returned. */ export declare class WorkerLifecycle { readonly ledger: DelegationOrchestrationLedger; private nextLaneNumber; private readonly isProcessAlive; constructor(options: { agentDir: string; sessionId: string; isProcessAlive?: (pid: number) => boolean; now?: () => number; /** * Pre-built durable event store, forwarded to `DelegationOrchestrationLedger`. Defaults to * `undefined`, which the ledger resolves to its own real `OrchestrationEventStore` — a * zero-behavior-change no-op for every existing caller. Only the destructive-testing harness * passes a store constructed over a fault-injecting `fs`. */ store?: OrchestrationEventStore; }); prepare(input: Omit, laneId?: string): { record: LaneRecord; attempt: AttemptRuntimeState; }; /** Return the next generated lane id without reserving it or changing lifecycle state. */ getNextAvailableLaneIdCandidate(): string; /** Queue the next distinct task/attempt for an idle logical agent. */ prepareAgentTurn(input: { agentId: string; instructions: string; controlMessageId?: string; dependsOnTaskIds?: readonly string[]; }): { record: LaneRecord; attempt: AttemptRuntimeState; }; ensureAgent(input: { agentId: string; parentAgentId?: string; role: WorkerRole; resumeContext: AgentResumeContext; }): AgentBindingContract; /** Retire one idle logical worker while retaining its durable binding and transcript identity. */ retireAgent(agentId: string): AgentBindingContract; prepareManaged(input: PrepareManagedDelegationInput & { leaseTtlMs: number; compileGrant(target: { objectiveId: string; taskId: string; attemptId: string; }): ExecutionGrant; }): { record: LaneRecord; attempt: AttemptRuntimeState; handle: StartedDelegationAttempt; created: boolean; }; synchronizeGoalState(goal: GoalState): LaneRecord[]; start(laneId: string, leaseTtlMs: number): StartedDelegationAttempt; startAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId?: string): StartedDelegationAttempt; renewLease(laneId: string, leaseTtlMs: number): import("../orchestration/contracts.ts").AttemptLease; checkpoint(laneId: string, input: { summary: string; artifactIds?: readonly string[]; evidenceIds?: readonly string[]; usage?: AttemptUsageSnapshot; }): import("../orchestration/contracts.ts").AttemptCheckpoint; /** * Suspend only attempts whose exact controller owner is known (explicit shutdown) or whose * recorded local owner PID is proven gone (recovery). A live/unknown owner is never stolen. */ suspendBoundInProcessAttemptsForRestart(ownerId?: string): string[]; /** * Applies an explicitly authorized restart suspension. The caller must identify both the logical * lane and the current lease fence; process liveness policy is intentionally kept by this class. */ suspendBoundAttempt(args: { laneId: string; ownerId: string; leaseId: string; fencingToken: number; reasonCode: string; retry?: AttemptRetryState; }): void; resumeAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId?: string): StartedDelegationAttempt; suspendAgent(laneId: string, agentId: string, ownerId: string, reasonCode?: string, retry?: AttemptRetryState): void; scheduleAgentRetry(args: { laneId: string; agentId: string; ownerId: string; reasonCode: string; retry: AttemptRetryState; }): AttemptRuntimeState; bindGrant(attemptId: string, grant: ExecutionGrant): void; finish(result: WorkerResultContract, options?: { notify?: boolean; }): LaneRecord; reconcileVerification(args: { subjectTaskId: string; verifierTaskId: string; verifierAttemptId: string; verdict: "accepted" | "rejected" | "inconclusive"; reasonCode: string; }): LaneRecord; cancel(laneId: string, reasonCode: string): LaneRecord | undefined; recoverQueued(): Array<{ record: LaneRecord; attempt: AttemptRuntimeState; verificationOfTaskId?: string; }>; /** Close crash windows between implementation completion, verifier dispatch, and reconciliation. */ getPendingVerificationRecoveries(): PendingVerificationRecovery[]; getTask(taskId: string): TaskRuntimeProjection["tasks"][string] | undefined; getAgent(agentId: string): AgentBindingContract | undefined; getLatestAgentAttempt(agentId: string): AttemptRuntimeState | undefined; getTaskRuntimeSnapshot(): TaskRuntimeProjection; /** Read-only dispatch gate for an already persisted queued worker attempt. */ getAttemptDispatchReadiness(attemptId: string): AttemptDispatchReadiness; getRecords(): LaneRecord[]; getManagedRecords(): LaneRecord[]; getAllRecords(): LaneRecord[]; getRecord(laneId: string): LaneRecord | undefined; getManagedRecord(laneId: string): LaneRecord | undefined; getManagedAttempt(laneId: string): AttemptRuntimeState | undefined; getManagedHandle(laneId: string): StartedDelegationAttempt | undefined; getActiveAttempt(laneId: string): AttemptRuntimeState | undefined; getResult(laneId: string): WorkerResultContract | undefined; getAttemptUsage(laneId: string): AttemptUsageSnapshot | undefined; getRunningCount(profileId?: string): number; getPendingTerminalNotifications(): Array<{ notificationId: string; record: LaneRecord; }>; getTerminalNotification(laneId: string): { notificationId: string; status: "pending" | "delivered"; record: LaneRecord; } | undefined; markNotificationsDelivered(notificationIds: readonly string[]): void; private ensureTerminalNotifications; private enqueueTerminalNotification; private requireActiveAttempt; private startedHandle; private startPreparedManagedAttempt; } //# sourceMappingURL=worker-lifecycle.d.ts.map