Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(cyclops-cs): add instance details and logs (#7191)

r33drichards886a268fd77c
diff --git a/libs/fleet/e2e/fixtures/mock-api.ts b/libs/fleet/e2e/fixtures/mock-api.ts
index 2ed2341aee..a740e80349 100644
--- a/libs/fleet/e2e/fixtures/mock-api.ts
+++ b/libs/fleet/e2e/fixtures/mock-api.ts
@@ -800,6 +800,84 @@ export async function mockInstancesApi(page: Page): Promise<void> {
)
}
+export async function mockInstanceDetailApi(page: Page): Promise<void> {
+ await page.route(
+ "**/api/k8s/apis/osgym.cua.ai/v1alpha1/namespaces/demo-pool/osgymsandboxes/vm-xyz789",
+ async route => {
+ await route.fulfill({
+ contentType: "application/json",
+ body: JSON.stringify({
+ apiVersion: "osgym.cua.ai/v1alpha1",
+ kind: "OSGymSandbox",
+ metadata: {
+ name: "vm-xyz789",
+ namespace: "demo-pool",
+ creationTimestamp: "2026-05-28T09:55:00Z",
+ annotations: {
+ "osgym.cua.ai/origin-warmpool": "demo-pool",
+ "osgym.cua.ai/origin-warmpool-namespace": "demo-pool",
+ },
+ ownerReferences: [
+ {
+ kind: "OSGymSandboxClaim",
+ name: "claim-abc123",
+ controller: true,
+ },
+ ],
+ },
+ spec: { vmTemplate: { runtime: "kubevirt" } },
+ status: {
+ phase: "Ready",
+ ready: true,
+ vmName: "vm-xyz789",
+ },
+ }),
+ })
+ },
+ )
+
+ await page.route(
+ "**/api/k8s/api/v1/namespaces/demo-pool/pods?labelSelector=*",
+ async route => {
+ await route.fulfill({
+ contentType: "application/json",
+ body: JSON.stringify({
+ items: [
+ {
+ metadata: {
+ name: "virt-launcher-vm-xyz789-abcde",
+ namespace: "demo-pool",
+ creationTimestamp: "2026-05-28T09:55:10Z",
+ },
+ spec: {
+ nodeName: "kubevirt-worker-1",
+ containers: [{ name: "compute" }, { name: "guest-console-log" }],
+ },
+ status: { phase: "Running" },
+ },
+ ],
+ }),
+ })
+ },
+ )
+
+ await page.route(
+ "**/api/k8s/api/v1/namespaces/demo-pool/pods/virt-launcher-vm-xyz789-abcde/log?*",
+ async route => {
+ const url = new URL(route.request().url())
+ const container = url.searchParams.get("container")
+ if (container !== "guest-console-log") {
+ await route.fulfill({ status: 400, body: "unexpected log container" })
+ return
+ }
+ await route.fulfill({
+ contentType: "text/plain",
+ body: "2026-05-28T10:00:00Z guest console ready\n",
+ })
+ },
+ )
+}
+
// ---------------------------------------------------------------------------
// Claims API mocking (OSGymSandboxClaim CRD)
// ---------------------------------------------------------------------------
diff --git a/libs/fleet/e2e/pools.spec.ts b/libs/fleet/e2e/pools.spec.ts
index 126c56b106..fe543adab5 100644
--- a/libs/fleet/e2e/pools.spec.ts
+++ b/libs/fleet/e2e/pools.spec.ts
@@ -1,6 +1,7 @@
import { test, expect } from "@playwright/test"
import {
mockAuth,
+ mockInstanceDetailApi,
mockInstancesApi,
mockNamespacesApi,
mockPoolsApi,
@@ -477,6 +478,40 @@ test.describe("Pool detail instances", () => {
await expect(availableRow.getByRole("button", { name: "Release" })).toHaveCount(0)
await expect(page.getByText("other-pool-instance")).toHaveCount(0)
})
+
+ test("opens instance details and displays guest console logs", async ({ page }) => {
+ await mockAuth(page)
+ await mockNamespacesApi(page)
+ await mockPoolsApi(page)
+ await mockInstancesApi(page)
+ await mockClaimsApi(page)
+ await mockInstanceDetailApi(page)
+ await page.context().grantPermissions(
+ ["clipboard-read", "clipboard-write"],
+ { origin: "http://localhost:5180" },
+ )
+
+ await page.goto("/pools/demo-pool/demo-pool")
+ await page.getByRole("link", { name: "vm-xyz789" }).click()
+
+ await expect(page).toHaveURL(
+ /\/pools\/demo-pool\/demo-pool\/instances\/vm-xyz789$/,
+ )
+ await expect(page.getByRole("heading", { name: "vm-xyz789" })).toBeVisible()
+ await expect(
+ page.getByRole("heading", { name: "Guest console logs", exact: true }),
+ ).toBeVisible()
+ await expect(page.getByRole("heading", { name: "Overview" })).toHaveCount(0)
+ await expect(page.getByLabel("Guest console logs")).toContainText(
+ "guest console ready",
+ )
+ await page.getByRole("button", { name: "Copy logs" }).click()
+ await expect(page.getByRole("button", { name: "Copied" })).toBeVisible()
+ await expect
+ .poll(() => page.evaluate(() => navigator.clipboard.readText()))
+ .toContain("guest console ready")
+ await expect(page.getByLabel("Log container")).toHaveCount(0)
+ })
})
test.describe("Retired navigation", () => {
diff --git a/libs/fleet/src/App.tsx b/libs/fleet/src/App.tsx
index 78f4267928..cd2145a9ef 100644
--- a/libs/fleet/src/App.tsx
+++ b/libs/fleet/src/App.tsx
@@ -26,6 +26,7 @@ import {
import { Helmet } from "react-helmet-async";
import { PoolsList } from "./pages/PoolsList";
import { ClaimDetail } from "./pages/ClaimDetail";
+import { InstanceDetail } from "./pages/InstanceDetail";
import { PoolDetail } from "./pages/PoolDetail";
import { PoolNew } from "./pages/PoolNew";
import { UserApiKeys } from "./pages/UserApiKeys";
@@ -413,6 +414,10 @@ export function App() {
</TitledPage>
}
/>
+ <Route
+ path="/pools/:namespace/:poolName/instances/:instanceName"
+ element={<InstanceDetail />}
+ />
<Route path="/modules" element={<Navigate to="/pools" replace />} />
<Route
path="/modules/new"
diff --git a/libs/fleet/src/fleet/instances.ts b/libs/fleet/src/fleet/instances.ts
index 62c7ad17af..62ec87de89 100644
--- a/libs/fleet/src/fleet/instances.ts
+++ b/libs/fleet/src/fleet/instances.ts
@@ -1,7 +1,8 @@
import { getToken } from "../auth/keycloak"
import { isLocalVisualPreview } from "../local-visual-preview"
-import type { PoolInstance } from "./models"
+import type { InstancePod, PoolInstance } from "./models"
+const GUEST_CONSOLE_CONTAINER = "guest-console-log"
const WARM_POOL_LABEL = "osgym.cua.ai/warmpool"
const ORIGIN_WARM_POOL_ANNOTATION = "osgym.cua.ai/origin-warmpool"
const ORIGIN_WARM_POOL_NAMESPACE_ANNOTATION =
@@ -20,8 +21,17 @@ interface SandboxResource {
controller?: boolean
}>
}
+ spec?: {
+ vmTemplate?: {
+ runtime?: string
+ }
+ }
status?: {
phase?: string
+ runtime?: string
+ ready?: boolean
+ vmName?: string
+ message?: string
}
}
@@ -29,6 +39,55 @@ interface SandboxResourceList {
items?: SandboxResource[]
}
+interface PodResource {
+ metadata?: {
+ name?: string
+ namespace?: string
+ creationTimestamp?: string
+ }
+ spec?: {
+ nodeName?: string
+ containers?: Array<{ name?: string }>
+ initContainers?: Array<{ name?: string }>
+ ephemeralContainers?: Array<{ name?: string }>
+ }
+ status?: {
+ phase?: string
+ }
+}
+
+interface PodResourceList {
+ items?: PodResource[]
+}
+
+class KubernetesApiError extends Error {
+ constructor(
+ message: string,
+ readonly status: number,
+ ) {
+ super(message)
+ }
+}
+
+async function k8sRequest(path: string): Promise<Response> {
+ const token = await getToken()
+ return fetch(`/api/k8s/${path}`, {
+ headers: { Authorization: token ? `Bearer ${token}` : "" },
+ })
+}
+
+async function k8sJson<T>(path: string): Promise<T> {
+ const response = await k8sRequest(path)
+ if (!response.ok) {
+ const body = await response.text()
+ throw new KubernetesApiError(
+ body || `Kubernetes request failed: ${response.status}`,
+ response.status,
+ )
+ }
+ return response.json() as Promise<T>
+}
+
function belongsToPool(
sandbox: SandboxResource,
namespace: string,
@@ -59,30 +118,123 @@ function instanceModel(sandbox: SandboxResource): PoolInstance | null {
name: metadata.name,
namespace: metadata.namespace,
phase: sandbox.status?.phase ?? "Pending",
+ runtime: sandbox.status?.runtime ?? sandbox.spec?.vmTemplate?.runtime,
+ vmName: sandbox.status?.vmName,
+ ready: sandbox.status?.ready,
+ message: sandbox.status?.message,
claimName,
createdAt: metadata.creationTimestamp ?? "",
}
}
+function podModel(pod: PodResource): InstancePod | null {
+ const metadata = pod.metadata
+ if (!metadata?.name || !metadata.namespace) return null
+
+ const containers = [
+ ...(pod.spec?.initContainers ?? []),
+ ...(pod.spec?.containers ?? []),
+ ...(pod.spec?.ephemeralContainers ?? []),
+ ]
+ .map(container => container.name)
+ .filter((name): name is string => Boolean(name))
+
+ return {
+ name: metadata.name,
+ namespace: metadata.namespace,
+ phase: pod.status?.phase ?? "Unknown",
+ nodeName: pod.spec?.nodeName,
+ createdAt: metadata.creationTimestamp ?? "",
+ containers,
+ }
+}
+
export async function listPoolInstances(
namespace: string,
poolName: string,
): Promise<PoolInstance[]> {
if (isLocalVisualPreview()) return []
- const token = await getToken()
- const response = await fetch(
- `/api/k8s/apis/osgym.cua.ai/v1alpha1/namespaces/${encodeURIComponent(namespace)}/osgymsandboxes`,
- { headers: { Authorization: token ? `Bearer ${token}` : "" } },
+ const list = await k8sJson<SandboxResourceList>(
+ `apis/osgym.cua.ai/v1alpha1/namespaces/${encodeURIComponent(namespace)}/osgymsandboxes`,
)
- if (!response.ok) {
- const body = await response.text()
- throw new Error(body || `instance request failed: ${response.status}`)
- }
-
- const list = (await response.json()) as SandboxResourceList
return (list.items ?? [])
.filter(sandbox => belongsToPool(sandbox, namespace, poolName))
.map(instanceModel)
.filter((instance): instance is PoolInstance => instance !== null)
}
+
+export async function getPoolInstance(
+ namespace: string,
+ instanceName: string,
+): Promise<PoolInstance> {
+ const sandbox = await k8sJson<SandboxResource>(
+ `apis/osgym.cua.ai/v1alpha1/namespaces/${encodeURIComponent(namespace)}/osgymsandboxes/${encodeURIComponent(instanceName)}`,
+ )
+ const instance = instanceModel(sandbox)
+ if (!instance) throw new Error("Instance response is missing metadata")
+ return instance
+}
+
+async function getPodByName(
+ namespace: string,
+ podName: string,
+): Promise<InstancePod | null> {
+ try {
+ const pod = await k8sJson<PodResource>(
+ `api/v1/namespaces/${encodeURIComponent(namespace)}/pods/${encodeURIComponent(podName)}`,
+ )
+ return podModel(pod)
+ } catch (error) {
+ if (error instanceof KubernetesApiError && error.status === 404) return null
+ throw error
+ }
+}
+
+async function getKubeVirtPod(
+ namespace: string,
+ vmName: string,
+): Promise<InstancePod | null> {
+ const selector = encodeURIComponent(`kubevirt.io/domain=${vmName}`)
+ const list = await k8sJson<PodResourceList>(
+ `api/v1/namespaces/${encodeURIComponent(namespace)}/pods?labelSelector=${selector}`,
+ )
+ const pods = (list.items ?? [])
+ .map(podModel)
+ .filter((pod): pod is InstancePod => pod !== null)
+ return pods.find(pod => pod.phase === "Running") ?? pods[0] ?? null
+}
+
+export async function getInstancePod(
+ instance: PoolInstance,
+): Promise<InstancePod | null> {
+ const workloadName = instance.vmName ?? instance.name
+ if (instance.runtime === "macos" || instance.runtime === "gvisor") {
+ return getPodByName(instance.namespace, workloadName)
+ }
+
+ const kubeVirtPod = await getKubeVirtPod(instance.namespace, workloadName)
+ if (kubeVirtPod) return kubeVirtPod
+
+ // Older resources may not have status.runtime populated yet.
+ return getPodByName(instance.namespace, workloadName)
+}
+
+export async function getInstanceLogs(
+ pod: InstancePod,
+ tailLines = 1000,
+): Promise<string> {
+ const query = new URLSearchParams({
+ container: GUEST_CONSOLE_CONTAINER,
+ tailLines: String(tailLines),
+ timestamps: "true",
+ })
+ const response = await k8sRequest(
+ `api/v1/namespaces/${encodeURIComponent(pod.namespace)}/pods/${encodeURIComponent(pod.name)}/log?${query}`,
+ )
+ if (!response.ok) {
+ const body = await response.text()
+ throw new Error(body || `Log request failed: ${response.status}`)
+ }
+ return response.text()
+}
diff --git a/libs/fleet/src/fleet/models.ts b/libs/fleet/src/fleet/models.ts
index e1702cfe2a..d5b89a73eb 100644
--- a/libs/fleet/src/fleet/models.ts
+++ b/libs/fleet/src/fleet/models.ts
@@ -55,6 +55,19 @@ export interface PoolInstance {
name: string
namespace: string
phase: string
+ runtime?: string
+ vmName?: string
+ ready?: boolean
+ message?: string
claimName?: string
createdAt: string
}
+
+export interface InstancePod {
+ name: string
+ namespace: string
+ phase: string
+ nodeName?: string
+ createdAt: string
+ containers: string[]
+}
diff --git a/libs/fleet/src/pages/InstanceDetail.tsx b/libs/fleet/src/pages/InstanceDetail.tsx
new file mode 100644
index 0000000000..8ccae08fd8
--- /dev/null
+++ b/libs/fleet/src/pages/InstanceDetail.tsx
@@ -0,0 +1,242 @@
+import { useCallback, useEffect, useRef, useState } from "react"
+import { useNavigate, useParams } from "react-router-dom"
+import Container from "@cloudscape-design/components/container"
+import Header from "@cloudscape-design/components/header"
+import SpaceBetween from "@cloudscape-design/components/space-between"
+import StatusIndicator from "@cloudscape-design/components/status-indicator"
+import Toggle from "@cloudscape-design/components/toggle"
+import { CuaButton } from "../components/CuaButton"
+import { useFlash } from "../components/FlashContext"
+import { PageEmpty, PageError } from "../components/PageState"
+import { PageShell } from "../components/PageShell"
+import {
+ getInstanceLogs,
+ getInstancePod,
+ getPoolInstance,
+} from "../fleet/instances"
+import type { InstancePod, PoolInstance } from "../fleet/models"
+
+const LOG_REFRESH_INTERVAL_MS = 5000
+
+function statusType(
+ phase: string,
+): "success" | "pending" | "error" | "info" | "stopped" {
+ switch (phase) {
+ case "Ready":
+ case "Running":
+ return "success"
+ case "Pending":
+ case "Resetting":
+ return "pending"
+ case "Failed":
+ case "Terminating":
+ return "error"
+ case "Succeeded":
+ return "stopped"
+ default:
+ return "info"
+ }
+}
+
+export function InstanceDetail() {
+ const { namespace = "", poolName = "", instanceName = "" } = useParams()
+ const navigate = useNavigate()
+ const flash = useFlash()
+ const [instance, setInstance] = useState<PoolInstance | null>(null)
+ const [pod, setPod] = useState<InstancePod | null>(null)
+ const [logs, setLogs] = useState("")
+ const [loading, setLoading] = useState(true)
+ const [logsLoading, setLogsLoading] = useState(false)
+ const [loadError, setLoadError] = useState<string | null>(null)
+ const [logsError, setLogsError] = useState<string | null>(null)
+ const [autoRefresh, setAutoRefresh] = useState(true)
+ const [copied, setCopied] = useState(false)
+ const [lastRefreshed, setLastRefreshed] = useState<Date | null>(null)
+ const logRequestRef = useRef(0)
+ const copyResetRef = useRef<number | null>(null)
+
+ const loadInstance = useCallback(async () => {
+ setLoading(true)
+ setLoadError(null)
+ try {
+ const nextInstance = await getPoolInstance(namespace, instanceName)
+ const nextPod = await getInstancePod(nextInstance)
+ setInstance(nextInstance)
+ setPod(nextPod)
+ } catch (error) {
+ setLoadError(String((error as Error).message))
+ } finally {
+ setLoading(false)
+ }
+ }, [instanceName, namespace])
+
+ useEffect(() => {
+ if (namespace && instanceName) void loadInstance()
+ }, [instanceName, loadInstance, namespace])
+
+ const loadLogs = useCallback(async () => {
+ if (!pod) return
+ const requestId = ++logRequestRef.current
+ setLogsLoading(true)
+ setLogsError(null)
+ try {
+ const nextLogs = await getInstanceLogs(pod)
+ if (requestId !== logRequestRef.current) return
+ setLogs(nextLogs)
+ setLastRefreshed(new Date())
+ } catch (error) {
+ if (requestId !== logRequestRef.current) return
+ setLogsError(String((error as Error).message))
+ } finally {
+ if (requestId === logRequestRef.current) setLogsLoading(false)
+ }
+ }, [pod])
+
+ useEffect(() => {
+ if (!pod) return
+ void loadLogs()
+ }, [loadLogs, pod])
+
+ useEffect(() => {
+ if (!autoRefresh || !pod) return
+ const timer = window.setInterval(() => void loadLogs(), LOG_REFRESH_INTERVAL_MS)
+ return () => window.clearInterval(timer)
+ }, [autoRefresh, loadLogs, pod])
+
+ useEffect(() => {
+ return () => {
+ if (copyResetRef.current !== null) {
+ window.clearTimeout(copyResetRef.current)
+ }
+ }
+ }, [])
+
+ const copyLogs = async () => {
+ if (!logs) return
+ try {
+ await navigator.clipboard.writeText(logs)
+ setCopied(true)
+ if (copyResetRef.current !== null) {
+ window.clearTimeout(copyResetRef.current)
+ }
+ copyResetRef.current = window.setTimeout(() => {
+ setCopied(false)
+ copyResetRef.current = null
+ }, 2000)
+ } catch (error) {
+ flash.push({
+ type: "error",
+ header: "Failed to copy logs",
+ content: String((error as Error).message),
+ })
+ }
+ }
+
+ if (loading && !instance) {
+ return (
+ <PageShell eyebrow="Fleet / Pool / Instance" title={instanceName || "Instance"}>
+ <PageEmpty title="Loading instance…" />
+ </PageShell>
+ )
+ }
+
+ if (!instance) {
+ return (
+ <PageShell eyebrow="Fleet / Pool / Instance" title={instanceName || "Instance"}>
+ <PageError
+ title="Instance unavailable"
+ action={<CuaButton onClick={loadInstance}>Try again</CuaButton>}
+ >
+ {loadError}
+ </PageError>
+ </PageShell>
+ )
+ }
+
+ return (
+ <PageShell
+ eyebrow="Fleet / Pool / Instance"
+ title={instance.name}
+ description={
+ <StatusIndicator type={statusType(instance.phase)}>
+ {instance.phase}
+ </StatusIndicator>
+ }
+ secondaryActions={
+ <SpaceBetween direction="horizontal" size="xs">
+ <CuaButton
+ tone="icon"
+ ariaLabel="Refresh instance"
+ iconName="refresh"
+ loading={loading}
+ onClick={loadInstance}
+ />
+ <CuaButton onClick={() => navigate(`/pools/${namespace}/${poolName}`)}>
+ Back to pool
+ </CuaButton>
+ </SpaceBetween>
+ }
+ >
+ <Container
+ header={
+ <Header
+ variant="h2"
+ description={
+ lastRefreshed
+ ? `Last refreshed ${lastRefreshed.toLocaleTimeString()}`
+ : "Most recent 1,000 lines from the guest console."
+ }
+ actions={
+ <SpaceBetween direction="horizontal" size="s" alignItems="center">
+ <Toggle
+ checked={autoRefresh}
+ onChange={({ detail }) => setAutoRefresh(detail.checked)}
+ >
+ Auto-refresh
+ </Toggle>
+ <CuaButton
+ iconName="copy"
+ disabled={!logs}
+ onClick={copyLogs}
+ >
+ {copied ? "Copied" : "Copy logs"}
+ </CuaButton>
+ <CuaButton
+ tone="icon"
+ ariaLabel="Refresh logs"
+ iconName="refresh"
+ loading={logsLoading}
+ disabled={!pod}
+ onClick={loadLogs}
+ />
+ </SpaceBetween>
+ }
+ >
+ Guest console logs
+ </Header>
+ }
+ >
+ {!pod ? (
+ <PageEmpty title="Workload pod not available">
+ The instance may still be starting. Refresh the instance to try again.
+ </PageEmpty>
+ ) : logsError ? (
+ <PageError
+ title="Unable to load guest console logs"
+ action={<CuaButton onClick={loadLogs}>Try again</CuaButton>}
+ >
+ {logsError}
+ </PageError>
+ ) : logsLoading && !logs ? (
+ <PageEmpty title="Loading guest console logs…" />
+ ) : (
+ <section aria-label="Guest console logs">
+ <pre className="cua-instance-log-view">
+ {logs || "No guest console output."}
+ </pre>
+ </section>
+ )}
+ </Container>
+ </PageShell>
+ )
+}
diff --git a/libs/fleet/src/pages/PoolDetail.tsx b/libs/fleet/src/pages/PoolDetail.tsx
index 5ae88d2071..fb36f9907a 100644
--- a/libs/fleet/src/pages/PoolDetail.tsx
+++ b/libs/fleet/src/pages/PoolDetail.tsx
@@ -559,7 +559,19 @@ function InstancesTable({ pool }: { pool: PoolData }) {
{
id: "name",
header: "Name",
- cell: (instance: InstanceRow) => instance.name,
+ cell: (instance: InstanceRow) => (
+ <Link
+ href={`#/pools/${pool.namespace}/${pool.name}/instances/${instance.name}`}
+ onFollow={event => {
+ event.preventDefault()
+ navigate(
+ `/pools/${pool.namespace}/${pool.name}/instances/${instance.name}`,
+ )
+ }}
+ >
+ {instance.name}
+ </Link>
+ ),
sortingField: "name",
},
{
diff --git a/libs/fleet/src/shell.css b/libs/fleet/src/shell.css
index eae4a194e3..52abd96266 100644
--- a/libs/fleet/src/shell.css
+++ b/libs/fleet/src/shell.css
@@ -136,6 +136,27 @@ body,
white-space: nowrap;
}
+.cua-instance-log-view {
+ box-sizing: border-box;
+ min-height: 360px;
+ max-height: 65vh;
+ margin: 0;
+ padding: 18px 20px;
+ overflow: auto;
+ border: 1px solid var(--cua-color-border-subtle, rgba(255, 255, 255, 0.12));
+ border-radius: var(--cua-radius-control);
+ background:
+ linear-gradient(180deg, rgba(159, 215, 255, 0.035), transparent 72px),
+ #0a0d10;
+ color: #d9e4ec;
+ font-family: var(--cua-dashboard-font-mono, monospace);
+ font-size: 12px;
+ line-height: 1.65;
+ tab-size: 2;
+ white-space: pre-wrap;
+ overflow-wrap: anywhere;
+}
+
#cua-dashboard-root .cua-dashboard-button button {
appearance: none;
display: inline-flex;