export type Phase = | 'bump' | 'deploy-canary' | 'smoke-canary' | 'telemetry-canary' | 'ramp' | 'smoke-live' | 'telemetry-live' | 'rollback' | 'halt' | 'done' export type PhaseOutcome = 'pass' | 'fail' | 'rolled-back' | 'harness-stop' | 'state-conflict' export type PipelineState = { readonly phase: Phase readonly smoke: PhaseOutcome | null } export function pipelineStart(): PipelineState { return { phase: 'bump', smoke: null } } /** * The operator pipeline. A pinned smoke failure halts: the canary stays at 0% and * telemetry does not run. A ramp rollback is already done, so the pipeline halts * instead of rolling back again. A live worker failure enters rollback. A harness fault * or a state conflict stops with the split held. */ export function nextPhase(state: PipelineState, outcome: PhaseOutcome): PipelineState { if (outcome === 'harness-stop' || outcome === 'state-conflict') return { phase: 'halt', smoke: state.smoke } switch (state.phase) { case 'bump': return outcome === 'pass' ? { phase: 'deploy-canary', smoke: null } : { phase: 'halt', smoke: null } case 'deploy-canary': return outcome === 'pass' ? { phase: 'smoke-canary', smoke: null } : { phase: 'halt', smoke: null } case 'smoke-canary': return outcome === 'pass' ? { phase: 'telemetry-canary', smoke: outcome } : { phase: 'halt', smoke: outcome } case 'telemetry-canary': return outcome === 'pass' && state.smoke === 'pass' ? { phase: 'ramp', smoke: state.smoke } : { phase: 'halt', smoke: state.smoke } case 'ramp': return outcome === 'pass' ? { phase: 'smoke-live', smoke: state.smoke } : { phase: 'halt', smoke: state.smoke } case 'smoke-live': return outcome === 'pass' ? { phase: 'telemetry-live', smoke: state.smoke } : { phase: 'rollback', smoke: state.smoke } case 'telemetry-live': return outcome === 'pass' ? { phase: 'done', smoke: state.smoke } : { phase: 'rollback', smoke: state.smoke } case 'rollback': return { phase: 'halt', smoke: state.smoke } case 'halt': case 'done': return state } } /** A live check's result, reduced to what decides the run. */ export type LiveCheck = { readonly kind: 'pass' } | { readonly kind: 'fail'; readonly fault: 'worker' | 'harness_fault' | 'state_conflict' | 'insufficient_samples' | 'harness_unhealthy' } /** * After the ramp reaches 100%: the live smoke, its telemetry (with the rate gate) and the visual smoke. Any Worker * failure rolls back to `previous`, even beside a harness fault. A harness fault alone (no Chrome, a lost query, too few * rate checks ingested) stops with the new version live: it is not evidence against the version. */ export function liveVerdict(checks: readonly LiveCheck[]): 'rollback' | 'halt' | 'done' { if (checks.some(check => check.kind === 'fail' && check.fault === 'worker')) return 'rollback' if (checks.some(check => check.kind === 'fail')) return 'halt' return 'done' }