import type { RunAttemptRecord, RunAttemptStatus, RunEventRecord, RunRecord, } from '../domain/run'; import type { RunRetryPolicyRecord } from '../domain/runRetryPolicy'; export const MAX_RUN_EVENT_PAYLOAD_BYTES = 16 * 1024; export const MAX_RUN_EVENT_PAGE_SIZE = 500; export const MAX_CANCELLATION_RECOVERY_PAGE_SIZE = 500; export interface RunRepositoryReader { findRunById(runId: string): Promise; findAttemptById(attemptId: string): Promise; findLatestAttemptByRunId(runId: string): Promise; findRetryPolicyByRunId(runId: string): Promise; listEvents( runId: string, options?: { afterSequence?: number; limit?: number }, ): Promise; listCancellationRequested(options?: { beforeMs?: number; limit?: number; }): Promise; } export interface RunRepositoryTransaction extends RunRepositoryReader { insertRun(run: RunRecord): Promise; insertAttempt(attempt: RunAttemptRecord): Promise; insertRetryPolicy(policy: RunRetryPolicyRecord): Promise; /** * Replaces a Run only when its persisted version still equals * `expectedVersion`. The supplied Run must carry `expectedVersion + 1`. */ compareAndSetRun(run: RunRecord, expectedVersion: number): Promise; /** * Replaces an Attempt only when both state and callback sequence still match. * The Run aggregate version remains the primary serialization boundary. */ compareAndSetAttempt( attempt: RunAttemptRecord, expected: { status: RunAttemptStatus; callbackSequence: number; }, ): Promise; compareAndSetRetryPolicy( policy: RunRetryPolicyRecord, expectedVersion: number, ): Promise; appendEvent(event: RunEventRecord): Promise; } export interface RunRepository extends RunRepositoryReader { transaction( work: (transaction: RunRepositoryTransaction) => Promise, ): Promise; }