/** Tab 4: launch-evaluation gauntlet — priority strata, early stopping, budget, compute savings. */ import { useEffect, useState } from 'react'; import Alert from '@mui/material/Alert'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Chip from '@mui/material/Chip'; import CircularProgress from '@mui/material/CircularProgress'; import LinearProgress from '@mui/material/LinearProgress'; import MenuItem from '@mui/material/MenuItem'; import Paper from '@mui/material/Paper'; import TextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import { Cpu, Rocket } from 'lucide-react'; import * as api from '../../services/nextgen'; import type { ComputeReport, GauntletResult } from '../../types/nextgen'; import { DataLabelChip, MetricCard, PANEL_SX } from './common'; const EFFECT_PRESETS: Record }> = { clean: { label: 'Clean candidate (no planted regressions)', effects: {} }, catastrophic: { label: 'Catastrophic safety regression (-8pp safety-critical)', effects: { safety_critical: -0.08 } }, odd: { label: 'New-ODD regression (-3pp)', effects: { new_odd: -0.03 } }, improvement: { label: 'Improvement (+2pp safety-critical)', effects: { safety_critical: 0.02 } }, }; const DECISION_COLORS: Record = { REGRESSION: '#ef9a9a', PASS: '#81c784', INSUFFICIENT_EVIDENCE: '#ffb74d', }; function RecommendationChip({ rec }: { rec: string }) { const color = rec === 'LAUNCH' ? '#2e7d32' : rec === 'DO_NOT_LAUNCH' ? '#b71c1c' : '#e65100'; return ; } function ComputeSavingsCard({ report }: { report: ComputeReport }) { return ( Compute savings (measured benchmark) naive = {report.n_scenarios} scenarios × {report.n_models} models × full inference ( {report.naive_full_inferences} runs); optimized = {report.optimized_backbone_computes} backbone computes + {report.optimized_head_computes} head-only runs. Backbone {report.measured_backbone_s.toFixed(3)}s vs head {report.measured_head_s.toFixed(3)}s per scenario (measured). Invalidation: {report.invalidation} ); } export default function GauntletTab() { const [preset, setPreset] = useState('catastrophic'); const [budget, setBudget] = useState(120000); const [result, setResult] = useState(null); const [compute, setCompute] = useState(null); const [busy, setBusy] = useState<'run' | 'bench' | null>(null); const [error, setError] = useState(''); useEffect(() => { api.getComputeReport().then(setCompute).catch(() => {}); }, []); const run = async () => { setBusy('run'); setError(''); try { setResult(await api.runGauntlet({ effects: EFFECT_PRESETS[preset].effects, budget_units: budget })); } catch (e) { setError(String((e as Error).message ?? e)); } finally { setBusy(null); } }; const bench = async () => { setBusy('bench'); setError(''); try { setCompute(await api.runComputeBenchmark({ n_scenarios: 3, frames_per_sequence: 10 })); } catch (e) { setError(String((e as Error).message ?? e)); } finally { setBusy(null); } }; const scale = result?.scale; return ( setPreset(e.target.value)} sx={{ minWidth: 340 }}> {Object.entries(EFFECT_PRESETS).map(([k, v]) => ( {v.label} ))} setBudget(Number(e.target.value))} sx={{ width: 140 }} /> {error && {error}} {result && ( <> {result.halted && } {result.run_id} · {result.candidate_version} vs {result.baseline_version} · wall{' '} {result.timing.wall_s.toFixed(2)}s ·{' '} {result.timing.units_per_second ? `${Math.round(result.timing.units_per_second).toLocaleString()} units/s` : ''} {result.recommendation.blockers.length > 0 && ( {result.recommendation.blockers.join(' · ')} )} {result.statistical_validity} Priority strata progress {result.strata.map((s) => { const frac = s.units_available ? s.units_evaluated / s.units_available : 0; return ( P{s.priority} {s.stratum} {s.units_evaluated.toLocaleString()} / {s.units_available.toLocaleString()} units {s.units_saved_by_early_stop > 0 ? ` · ${s.units_saved_by_early_stop.toLocaleString()} saved by early stop` : ''} {s.delta_estimate !== null ? ` · Δ ${(s.delta_estimate * 100).toFixed(2)}pp` : ''} ); })} {result.processed_order.length < result.priority_order.length && ( {result.priority_order.filter((p) => !result.processed_order.includes(p)).join(', ')} never reached (halted). )} Budget funnel {scale && ( )} Early-stop events {result.events.length === 0 && ( No early-stop events — all strata ran to their evidence thresholds. )} {result.events.map((e, i) => ( {e.stratum ? `${e.stratum}: ` : ''} {e.detail} ))} )} {compute ? ( ) : ( No compute benchmark yet — run one to see the naive-vs-optimized savings card. )} ); }