export const PLAY_RUNTIME_CONTRACT = 5; export const PLAY_RUNTIME_CONTRACT_MIN_SUPPORTED = 1; export const PLAY_RUNTIME_CONTRACT_HEADER = 'x-deepline-runtime-contract'; /** Shared runner/gateway envelope limit for unacknowledged progress recovery. */ export const RUNTIME_RUNNER_TERMINAL_PROGRESS_MAX_EVENTS = 2_000; /** * Opaque, per-request correlation key generated inside the sandbox runner. * It contains no customer data and lets gateway logs distinguish a request that * never reached Fly from one that was accepted but failed downstream. */ export const PLAY_RUNTIME_TRANSPORT_ATTEMPT_HEADER = 'x-deepline-runtime-transport-attempt'; const RUNTIME_TRANSPORT_ATTEMPT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; /** * Validate the opaque runner-generated correlation value before it appears in * any gateway log or response header. It is intentionally not a credential. */ export function resolvePlayRuntimeTransportAttemptId( raw: string | string[] | null | undefined, ): string | null { const value = Array.isArray(raw) ? raw[0] : raw; const trimmed = value?.trim(); return trimmed && RUNTIME_TRANSPORT_ATTEMPT_ID.test(trimmed) ? trimmed : null; } export const RUNTIME_CONTRACT_CHANGELOG = [ { contract: 5, changed: 'Runtime Sheet completion and lazy launch lookup use bounded, cancellation-aware gateway operations.', compatOwner: 'runtime', compatRemoval: 'contract 4 runtime lane drain', }, { contract: 4, changed: 'Runtime receipt heartbeat requests can carry one positional lease ID per receipt key.', compatOwner: 'runtime', compatRemoval: 'contract 3 runtime lane drain', }, { contract: 3, changed: 'Runtime receipt completion responses are compact acknowledgements; receipt reads remain the payload replay path.', compatOwner: 'runtime', compatRemoval: 'contract 2 support window closure', }, { contract: 2, changed: 'Runtime receipt batch responses use positional nulls and v2 lease-aware receipt semantics.', compatOwner: 'runtime', compatRemoval: 'ledger cutover milestone M1', }, ] as const; export function runtimeReceiptCompletionResponse< T extends { output?: unknown }, >(runtimeContract: number | null | undefined, receipt: T | null): T | null { if (!receipt || (runtimeContract ?? 1) < 3) return receipt; const { output, ...ack } = receipt; void output; return ack as T; } export type RuntimeContractResolution = | { ok: true; contract: number } | { ok: false; requestedContract: number; currentContract: number; minSupportedContract: number; }; export function resolvePlayRuntimeContract( rawContract: string | null | undefined, ): RuntimeContractResolution { const trimmed = rawContract?.trim(); const requestedContract = trimmed ? Number(trimmed) : 1; if ( !Number.isInteger(requestedContract) || requestedContract < PLAY_RUNTIME_CONTRACT_MIN_SUPPORTED || requestedContract > PLAY_RUNTIME_CONTRACT ) { return { ok: false, requestedContract, currentContract: PLAY_RUNTIME_CONTRACT, minSupportedContract: PLAY_RUNTIME_CONTRACT_MIN_SUPPORTED, }; } return { ok: true, contract: requestedContract }; }