fix: surface sandbox create progress diagnostics

Persist sandbox creation lifecycle events to the activity log, surface progress in the dashboard, and expose controller gateway override diagnostics.
This commit is contained in:
mmckeen-nv
2026-06-03 09:14:54 -06:00
committed by GitHub
parent c57ecb1131
commit c500998567
6 changed files with 126 additions and 23 deletions
+23 -20
View File
@@ -1,32 +1,35 @@
import { NextResponse } from 'next/server'
// Mock OpenShell configuration
// In production, this would call OpenShell API
const mockOpenshellConfig = {
enabled: true,
port: 8080,
policies: ['resource-control', 'network-isolation', 'audit-logging']
}
import {
OPENSHELL_BIN,
OPENSHELL_HOME,
OPENSHELL_XDG_CONFIG_HOME,
openshellGatewayAddressEnv,
} from '@/app/lib/hostCommands'
export async function GET() {
try {
return NextResponse.json(mockOpenshellConfig)
const gatewayAddressEnv = openshellGatewayAddressEnv()
return NextResponse.json({
ok: true,
enabled: true,
openshellBin: OPENSHELL_BIN,
openshellHome: OPENSHELL_HOME,
xdgConfigHome: OPENSHELL_XDG_CONFIG_HOME,
gatewayAddressEnv,
gatewayOverrideActive: Boolean(gatewayAddressEnv.OPENSHELL_GATEWAY_URL || gatewayAddressEnv.OPENSHELL_GATEWAY_HOST),
note: 'These values are passed to controller-launched OpenShell/NemoClaw child processes. Upstream CLIs must still honor them for full gateway override support.',
})
} catch (error) {
return NextResponse.json(
{ error: 'Failed to fetch OpenShell config' },
{ ok: false, error: error instanceof Error ? error.message : 'Failed to fetch OpenShell config' },
{ status: 500 }
)
}
}
export async function POST(request: Request) {
try {
const body = await request.json()
return NextResponse.json({ ...mockOpenshellConfig, ...body })
} catch (error) {
return NextResponse.json(
{ error: 'Failed to update OpenShell config' },
{ status: 500 }
)
}
export async function POST() {
return NextResponse.json(
{ ok: false, error: 'OpenShell config is read from environment variables or ~/.config/openshell/*.json; update those files and restart the controller.' },
{ status: 405 }
)
}
+77
View File
@@ -4,6 +4,7 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "
import path from "node:path"
import { promisify } from "node:util"
import { inspectSandbox, resolveSandboxRef } from "@/app/lib/openshellHost"
import { recordActivity } from "@/app/lib/activityLog"
import { repairOpenClawExecApprovalsFile } from "@/app/lib/sandboxPrivilegedFiles"
import {
commandExists,
@@ -59,6 +60,15 @@ function appendNote(...parts: Array<string | false | null | undefined>) {
return parts.filter(Boolean).join(" ")
}
async function recordCreateActivity(entry: Parameters<typeof recordActivity>[0]) {
try {
await recordActivity(entry)
} catch (error) {
const message = error instanceof Error ? error.message : String(error ?? "activity log write failed")
console.warn(`[sandbox/create] activity-log:error message=${message}`)
}
}
type NemoClawCreateCommand = {
file: string
args: string[]
@@ -755,6 +765,14 @@ export async function POST(request: Request) {
return NextResponse.json({ ok: false, error: "blueprint is required" }, { status: 400 })
}
await recordCreateActivity({
type: "sandbox.create.start",
status: "info",
sandboxName,
message: `Sandbox creation started for ${sandboxName} using ${blueprint}.`,
metadata: { blueprint, gpuMode, inferenceMode: createInference.mode },
})
if (isNemoClawOnboardBlueprint(blueprint)) {
const agent = nemoClawAgentForBlueprint(blueprint)
const isOpenClawAgent = agent === "openclaw"
@@ -782,6 +800,13 @@ export async function POST(request: Request) {
)
if (!result.ok) {
await recordCreateActivity({
type: "sandbox.create.error",
status: "error",
sandboxName,
message: `Sandbox creation command failed for ${sandboxName}.`,
metadata: { blueprint, agent, gpuMode, inferenceMode: createInference.mode, elapsedMs: elapsedMs(requestStartedAt), error: result.error },
})
return NextResponse.json({
ok: false,
error: result.error,
@@ -812,6 +837,16 @@ export async function POST(request: Request) {
console.log(
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} agent=${agent} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
)
await recordCreateActivity({
type: created ? "sandbox.create.success" : "sandbox.create.warning",
status: created ? "success" : "warning",
sandboxId: verification.details?.id || undefined,
sandboxName,
message: created
? `Sandbox ${sandboxName} is ready after ${readiness.attempts} readiness checks.`
: `Sandbox creation command finished for ${sandboxName}, but readiness was not verified.`,
metadata: { blueprint, agent, gpuMode, inferenceMode: createInference.mode, readinessAttempts: readiness.attempts, elapsedMs: elapsedMs(requestStartedAt) },
})
return NextResponse.json({
ok: created,
@@ -865,6 +900,13 @@ export async function POST(request: Request) {
const createAttempt = await runCreateCommandBounded(OPENSHELL_BIN, ["sandbox", "create", "--name", sandboxName, ...openShellGpuArgs(gpuMode)], env, 15000)
if (createAttempt.completed && createAttempt.exitCode !== 0) {
await recordCreateActivity({
type: "sandbox.create.error",
status: "error",
sandboxName,
message: `Custom sandbox creation command failed for ${sandboxName}.`,
metadata: { blueprint, gpuMode, elapsedMs: elapsedMs(requestStartedAt), error: createAttempt.error, exitCode: createAttempt.exitCode },
})
return NextResponse.json({
ok: false,
error: createAttempt.error ?? `create command failed with exit code ${createAttempt.exitCode}`,
@@ -893,6 +935,16 @@ export async function POST(request: Request) {
console.log(
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} createTimedOut=${createAttempt.timedOut} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
)
await recordCreateActivity({
type: created ? "sandbox.create.success" : "sandbox.create.warning",
status: created ? "success" : "warning",
sandboxId: verification.details?.id || undefined,
sandboxName,
message: created
? `Custom sandbox ${sandboxName} is ready after ${readiness.attempts} readiness checks.`
: `Custom sandbox creation finished for ${sandboxName}, but readiness was not verified.`,
metadata: { blueprint, gpuMode, readinessAttempts: readiness.attempts, elapsedMs: elapsedMs(requestStartedAt), createTimedOut: createAttempt.timedOut },
})
return NextResponse.json({
ok: created,
blueprint,
@@ -979,6 +1031,18 @@ export async function POST(request: Request) {
)
const createFailed = createAttempt.completed && createAttempt.exitCode !== 0 && !created
await recordCreateActivity({
type: created ? "sandbox.create.success" : createFailed ? "sandbox.create.error" : "sandbox.create.warning",
status: created ? "success" : createFailed ? "error" : "warning",
sandboxId: verification.details?.id || undefined,
sandboxName,
message: created
? `Quick deploy sandbox ${sandboxName} is ready after ${readiness.attempts} readiness checks.`
: createFailed
? `Quick deploy command failed for ${sandboxName}.`
: `Quick deploy started for ${sandboxName}, but readiness was not verified.`,
metadata: { blueprint, gpuMode, sourceSandboxName: source.name, readinessAttempts: readiness.attempts, elapsedMs: elapsedMs(requestStartedAt), createTimedOut: createAttempt.timedOut, forcedReady: createAttempt.forcedReady, error: createAttempt.error },
})
return NextResponse.json({
ok: created,
blueprint,
@@ -1032,9 +1096,22 @@ export async function POST(request: Request) {
}, { status: created ? 200 : createFailed ? 500 : 502 })
}
await recordCreateActivity({
type: "sandbox.create.error",
status: "error",
sandboxName,
message: `Sandbox creation failed for ${sandboxName}: unknown blueprint ${blueprint}.`,
metadata: { blueprint, gpuMode, elapsedMs: elapsedMs(requestStartedAt) },
})
return NextResponse.json({ ok: false, error: `unknown blueprint: ${blueprint}` }, { status: 400 })
} catch (error) {
const message = error instanceof Error ? error.message : "Sandbox creation failed"
await recordCreateActivity({
type: "sandbox.create.error",
status: "error",
message: `Sandbox creation failed: ${message}`,
metadata: { elapsedMs: elapsedMs(requestStartedAt) },
})
const status = /required|must be|too long|unknown blueprint/.test(message) ? 400 : 500
console.log(`[sandbox/create] request:error elapsedMs=${elapsedMs(requestStartedAt)} message=${message}`)
return NextResponse.json({ ok: false, error: message }, { status })
+1 -1
View File
@@ -42,7 +42,7 @@ export default function ActivityPanel() {
<div className="flex items-start justify-between gap-4 max-md:flex-col">
<div>
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Activity Log</h2>
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Recent backup, restore, catalog, and support actions recorded by the controller.</p>
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Recent sandbox creation, backup, restore, catalog, and support actions recorded by the controller.</p>
</div>
<div className="flex items-center gap-2">
<button type="button" onClick={loadActivity} disabled={loading} className="action-button px-3 py-2">
+6
View File
@@ -8,6 +8,7 @@ import HelpPanel from './components/HelpPanel'
import WizardPanel from './components/WizardPanel'
import McpConfigurationPanel from './components/McpConfigurationPanel'
import LiveTelemetryBar from './components/LiveTelemetryBar'
import ActivityPanel from './components/ActivityPanel'
import { useSandboxInventory } from './hooks/useSandboxInventory'
import {
createHydrationSafeDashboardSessionState,
@@ -292,6 +293,7 @@ export default function Dashboard() {
</p>
</div>
<ConfigurationPanel sandboxId="new-sandbox" mode="create" onCreateSuccess={handleCreateSuccess} />
<ActivityPanel />
</div>
) : isDestroyMode ? (
<div className="space-y-6">
@@ -400,6 +402,10 @@ export default function Dashboard() {
</div>
)}
<div className="mb-6">
<ActivityPanel />
</div>
{inventoryEnabled && loading ? (
<div className="flex items-center justify-center h-64" data-testid="inventory-loading-state">
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">
+6 -1
View File
@@ -12,10 +12,11 @@ const terminalReadinessPath = path.join(root, 'app/api/openshell/terminal/readin
const telemetryPath = path.join(root, 'app/api/telemetry/real/route.ts')
const openshellHostPath = path.join(root, 'app/lib/openshellHost.ts')
const sandboxHealthPath = path.join(root, 'app/api/sandbox/[sandboxId]/health/route.ts')
const openshellConfigPath = path.join(root, 'app/api/config/openshell/route.ts')
const packageJsonPath = path.join(root, 'package.json')
const serverPath = path.join(root, 'server.mjs')
const [runtimeAuthoritySource, dashboardOpenSource, dashboardProxySource, terminalLiveSource, terminalReadinessSource, telemetrySource, openshellHostSource, sandboxHealthSource, packageJsonSource, serverSource] = await Promise.all([
const [runtimeAuthoritySource, dashboardOpenSource, dashboardProxySource, terminalLiveSource, terminalReadinessSource, telemetrySource, openshellHostSource, sandboxHealthSource, openshellConfigSource, packageJsonSource, serverSource] = await Promise.all([
readFile(runtimeAuthorityPath, 'utf8'),
readFile(dashboardOpenPath, 'utf8'),
readFile(dashboardProxySharedPath, 'utf8'),
@@ -24,6 +25,7 @@ const [runtimeAuthoritySource, dashboardOpenSource, dashboardProxySource, termin
readFile(telemetryPath, 'utf8'),
readFile(openshellHostPath, 'utf8'),
readFile(sandboxHealthPath, 'utf8'),
readFile(openshellConfigPath, 'utf8'),
readFile(packageJsonPath, 'utf8'),
readFile(serverPath, 'utf8'),
])
@@ -60,6 +62,9 @@ assert.match(openshellHostSource, /const canMintBootstrapFromCli = instance\.id
assert.match(openshellHostSource, /readSandboxOpenClawDashboardToken/, 'sandbox dashboard bootstrap must fall back to the sandbox OpenClaw token when CLI output is bare')
assert.match(openshellHostSource, /openclaw dashboard', 15000\)\.catch/, 'sandbox dashboard bootstrap should let OpenClaw initialize before reading the fallback token')
assert.match(openshellHostSource, /withDashboardToken\(tokenizedBootstrapUrl, token\)/, 'sandbox dashboard bootstrap should synthesize a tokenized launch URL from the fallback token')
assert.match(openshellConfigSource, /openshellGatewayAddressEnv/, 'OpenShell config route must expose controller gateway override diagnostics')
assert.match(openshellConfigSource, /gatewayOverrideActive/, 'OpenShell config route must report whether gateway overrides are active')
assert.match(openshellConfigSource, /Upstream CLIs must still honor them/, 'OpenShell config route must make the upstream dependency explicit')
assert.match(packageJsonSource, /"dev": "NODE_ENV=development node server\.mjs"/, 'development script must run through the custom server so websocket proxy bridges are active')
assert.match(packageJsonSource, /"start": "NODE_ENV=production node server\.mjs"/, 'production start must run the custom server without Next dev-mode heap growth')
assert.match(serverSource, /const dashboardWsProxyPort = parseOptionalPort\(process\.env\.OPENCLAW_DASHBOARD_WS_PROXY_PORT/, 'custom server must make the dedicated dashboard websocket sidecar opt-in')
+12
View File
@@ -24,6 +24,7 @@ const versionedInstallerPath = path.join(root, 'install_versioned_nemoclaw_opens
const hookPath = path.join(root, 'app/hooks/useSandboxInventory.ts')
const pagePath = path.join(root, 'app/page.tsx')
const configPanelPath = path.join(root, 'app/components/ConfigurationPanel.tsx')
const activityPanelPath = path.join(root, 'app/components/ActivityPanel.tsx')
const inferencePanelPath = path.join(root, 'app/components/InferenceEndpointPanel.tsx')
const sandboxInferencePanelPath = path.join(root, 'app/components/SandboxInferencePanel.tsx')
const sidebarPath = path.join(root, 'app/components/Sidebar.tsx')
@@ -52,6 +53,7 @@ const versionedInstallerSource = await readFile(versionedInstallerPath, 'utf8')
const hookSource = await readFile(hookPath, 'utf8')
const pageSource = await readFile(pagePath, 'utf8')
const configPanelSource = await readFile(configPanelPath, 'utf8')
const activityPanelSource = await readFile(activityPanelPath, 'utf8')
const inferencePanelSource = await readFile(inferencePanelPath, 'utf8')
const sandboxInferencePanelSource = await readFile(sandboxInferencePanelPath, 'utf8')
const sidebarSource = await readFile(sidebarPath, 'utf8')
@@ -69,6 +71,16 @@ assert.match(
/readiness:\s*\{\s*attempts: readiness\.attempts,\s*elapsedMs: readiness\.elapsedMs,/,
'blueprint create response must expose readiness polling metadata',
)
assert.match(createRouteSource, /recordActivity/, 'sandbox create route must persist create progress to the activity log')
assert.match(createRouteSource, /async function recordCreateActivity/, 'sandbox create activity logging must be isolated behind a best-effort helper')
assert.match(createRouteSource, /activity-log:error/, 'sandbox create activity logging failures must be reported without failing creation')
assert.match(createRouteSource, /sandbox\.create\.start/, 'sandbox create route must record a durable start event before long-running work')
assert.match(createRouteSource, /sandbox\.create\.success/, 'sandbox create route must record a durable success event')
assert.match(createRouteSource, /sandbox\.create\.error/, 'sandbox create route must record durable failure events')
assert.ok(createRouteSource.indexOf('if (!blueprint)') < createRouteSource.indexOf('sandbox.create.start'), 'sandbox create route must validate required blueprint before recording a start event')
assert.match(createRouteSource, /sandbox\.create\.error[\s\S]*unknown blueprint/, 'unknown blueprint must be paired with a durable error event after a start event')
assert.match(pageSource, /<ActivityPanel \/>/, 'dashboard must surface the activity log so create progress remains visible after navigation')
assert.match(activityPanelSource, /sandbox creation/, 'activity panel copy must include sandbox creation progress events')
assert.match(createRouteSource, /"onboard",[\s\S]*"--non-interactive",[\s\S]*"--recreate-sandbox"/, 'blueprint create must use the Monday-era normal NemoClaw onboard flow')
assert.match(createRouteSource, /type NemoClawAgent = "openclaw" \| "hermes"/, 'blueprint create must model OpenClaw and Hermes NemoClaw agents')
assert.match(createRouteSource, /function nemoClawAgentForBlueprint\(blueprint: string\): NemoClawAgent/, 'blueprint create must map dashboard blueprints to NemoClaw agents')