import { useCallback, useEffect, useRef, useState } from "react"; import { api, operatorCredentialReference, operatorSessionVersion } from "../lib/api"; import type { OperatorIdentity } from "../lib/api"; import type { CompatibilityAssessment, DeploymentCandidate, ExecutionApproval, HardwareState, RuntimeEnvironment, RuntimeProbe, RuntimeProfile } from "../types"; type RuntimeState = { environments: RuntimeEnvironment[]; profiles: RuntimeProfile[]; assessments: CompatibilityAssessment[]; approvals: ExecutionApproval[]; probes: RuntimeProbe[]; candidates: DeploymentCandidate[]; hardware: HardwareState; }; const emptyState: RuntimeState = { environments: [], profiles: [], assessments: [], approvals: [], probes: [], candidates: [], hardware: { overview: { status: "unknown", inventory_state: "unknown", node_count: 0, accelerator_count: 0 }, nodes: [] } }; const terminal = new Set(["completed", "failed", "cancelled"]); const label = (value: string) => value.replaceAll("_", " ").toUpperCase(); const measure = (value: unknown, divisor: number, suffix: string) => typeof value === "number" && Number.isFinite(value) ? `${(value / divisor).toFixed(2)} ${suffix}` : "unknown"; const approvalUsable = (item: ExecutionApproval) => item.scope === "lab_execution" && item.status === "approved" && !item.stale && !item.revoked_at && (!item.expires_at || Date.parse(item.expires_at) > Date.now()); export function RuntimeWorkspace({ role = "viewer" }: { role?: OperatorIdentity["role"] }) { const [state, setState] = useState(emptyState); const [profileId, setProfileId] = useState(""); const [nodeId, setNodeId] = useState(""); const [loading, setLoading] = useState(true); const [working, setWorking] = useState(false); const [error, setError] = useState(null); const mounted = useRef(false); const requestId = useRef(0); const mutation = useRef(false); const generation = operatorSessionVersion(); const current = useCallback(() => mounted.current && generation === operatorSessionVersion() && Boolean(operatorCredentialReference()), [generation]); const load = useCallback(async () => { const request = ++requestId.current; const valid = () => current() && request === requestId.current; try { const [environments, profiles, assessments, approvals, probes, candidates, hardware] = await Promise.all([ api.runtimeEnvironments(), api.runtimeProfiles(), api.compatibilityAssessments(), api.executionApprovals(), api.runtimeProbes(), api.deploymentCandidates(), api.hardware(), ]); if (!valid()) return; setState({ environments, profiles, assessments, approvals, probes, candidates, hardware }); setProfileId(id => profiles.some(item => item.id === id) ? id : ""); setNodeId(id => hardware.nodes.some(item => item.id === id) ? id : ""); setError(null); } catch (cause) { if (!valid()) return; setState(emptyState); setProfileId(""); setNodeId(""); setError(cause instanceof Error ? cause.message : "Runtime evidence unavailable"); } finally { if (valid()) setLoading(false); } }, [current]); useEffect(() => { mounted.current = true; setState(emptyState); setProfileId(""); setNodeId(""); setWorking(false); if (operatorCredentialReference()) { setLoading(true); void load(); } else setLoading(false); return () => { mounted.current = false; requestId.current += 1; }; }, [load]); const active = state.probes.some(item => !terminal.has(item.status)); useEffect(() => { if (!active) return; let stopped = false; let timer: number; const poll = async () => { await load(); if (!stopped) timer = window.setTimeout(() => void poll(), 2000); }; timer = window.setTimeout(() => void poll(), 2000); return () => { stopped = true; window.clearTimeout(timer); }; }, [active, load]); async function operate(action: () => Promise, admin = false) { if (mutation.current || !current() || role === "viewer" || (admin && role !== "admin")) return; mutation.current = true; setWorking(true); setError(null); requestId.current += 1; try { await action(); if (current()) await load(); } catch (cause) { if (current()) setError(cause instanceof Error ? cause.message : "Runtime operation failed"); } finally { mutation.current = false; if (current()) setWorking(false); } } const profile = state.profiles.find(item => item.id === profileId); const node = state.hardware.nodes.find(item => item.id === nodeId); const environment = state.environments.find(item => item.id === profile?.runtime_environment_id); const binding = JSON.stringify([generation, profile?.id, profile?.artifact_set_id, profile?.fingerprint, environment?.fingerprint, node?.id]); const canOperate = role !== "viewer" && current(); if (loading) return
Loading runtime evidence…
; return
{error ?
{error}
: null}
Technical execution boundary

Verified bytes, static compatibility and explicit LAB approval are separate gates. Successful historical probes do not establish current compatibility or production permission.

{!canOperate ?

Read-only runtime evidence. A verified operator session is required for assessment, probe and cancellation; LAB approval requires an administrator.

: null}

Runtime profile and target node

{profile ?
:

Select a profile to inspect immutable runtime provenance.

}
; } function Fact({ name, value }: { name: string; value: unknown }) { return
{name}
{typeof value === "boolean" ? String(value) : typeof value === "string" && value.length ? value : typeof value === "number" && Number.isFinite(value) ? value : "unknown"}
; } function RuntimeBinding({ state, profile, nodeId, role, working, canOperate, operate }: { state: RuntimeState; profile?: RuntimeProfile; nodeId?: string; role: OperatorIdentity["role"]; working: boolean; canOperate: boolean; operate: (action: () => Promise, admin?: boolean) => Promise; }) { const [assessmentId, setAssessmentId] = useState(""); const [approvalId, setApprovalId] = useState(""); const [probeId, setProbeId] = useState(""); const [operator, setOperator] = useState(""); const [reason, setReason] = useState(""); const matches = (item: { artifact_set_id: string; runtime_profile_id: string; compute_node_id: string }) => Boolean(profile && nodeId && item.artifact_set_id === profile.artifact_set_id && item.runtime_profile_id === profile.id && item.compute_node_id === nodeId); const assessments = state.assessments.filter(matches); const approvals = state.approvals.filter(item => item.artifact_set_id === profile?.artifact_set_id); const probes = state.probes.filter(matches); const assessment = assessments.find(item => item.id === assessmentId); const approval = approvals.find(item => item.id === approvalId); const probe = probes.find(item => item.id === probeId); const assessmentIdentity = JSON.stringify([assessment?.id, assessment?.environment_fingerprint, assessment?.stale, assessment?.status]); useEffect(() => { setReason(""); setOperator(""); }, [assessmentIdentity]); useEffect(() => { if (!assessment) setAssessmentId(""); if (!approval) setApprovalId(""); if (!probe) setProbeId(""); }, [assessment, approval, probe]); const assessmentUsable = assessment && !assessment.stale && !assessment.blockers.length && ["compatible", "requires_probe"].includes(assessment.status); const canStart = Boolean(canOperate && !working && assessmentUsable && approval && approvalUsable(approval)); const probeAssessment = state.assessments.find(item => item.id === probe?.compatibility_assessment_id && matches(item)); // Completed probes fingerprint measured runtime facts; assessments fingerprint admission evidence. const historyCurrent = Boolean(probe && probeAssessment && !probeAssessment.stale); const candidates = state.candidates.filter(item => matches(item) && item.runtime_probe_id === probe?.id && item.compatibility_assessment_id === probe?.compatibility_assessment_id); return <>

Static compatibility matrix

{!profile || !nodeId ?

Select both an exact profile and node. Evidence never falls back to another combination.

: null}
{assessments.map(item => )}
{assessment ? <>
{assessment.stale ?

Compatibility evidence is stale: {assessment.stale_reason ?? "Evidence changed"}

: null}{assessment.blockers.map(item =>

Probe blocked: {label(item)}

)} : null}

Exact ArtifactSet LAB approval

{approval ?
: null} {role === "admin" && canOperate && profile && nodeId ? <>

Review exact artifact {profile.artifact_set_id}. This approval permits LAB execution only.