Integrate NemoClaw recovery and dashboard routing

This commit is contained in:
mmckeen-nv
2026-05-08 09:32:56 -07:00
parent 819e3e5f7d
commit 94bd7737d3
25 changed files with 1001 additions and 152 deletions
@@ -1,6 +1,7 @@
import { NextResponse } from "next/server"
import { execOpenShell, normalizeSandboxPhase, resolveSandboxRef } from "@/app/lib/openshellHost"
import { listBackupCatalog } from "@/app/lib/backupCatalog"
import { getNemoClawDoctorReport } from "@/app/lib/nemoclawCli"
function parseField(output: string, label: string) {
const normalizedLabel = label.toLowerCase()
@@ -23,6 +24,15 @@ export async function GET(
const phase = normalizeSandboxPhase(parseField(resolved.details, "Phase"))
const catalog = await listBackupCatalog()
const relatedBackups = catalog.filter((backup) => backup.sandboxId === sandboxId || backup.sandboxName === resolved.name)
const nemoclawDoctor = await getNemoClawDoctorReport(resolved.name).catch((error) => ({
available: false,
supported: false,
attempted: false,
version: null,
minimumVersion: "0.0.37",
report: null,
error: error instanceof Error ? error.message : "NemoClaw doctor check failed",
}))
let sshConfig = ""
let sshConfigError = ""
@@ -60,6 +70,16 @@ export async function GET(
? `${relatedBackups.length} saved backup${relatedBackups.length === 1 ? "" : "s"} in catalog.`
: "No saved catalog backups yet.",
},
{
key: "nemoclaw-doctor",
label: "NemoClaw doctor",
ok: !nemoclawDoctor.supported || Boolean(nemoclawDoctor.report && nemoclawDoctor.report.status !== "fail"),
detail: nemoclawDoctor.supported
? nemoclawDoctor.report
? `NemoClaw ${nemoclawDoctor.version || "unknown"} doctor reported ${nemoclawDoctor.report.status} (${nemoclawDoctor.report.failed} failed, ${nemoclawDoctor.report.warnings} warnings).`
: nemoclawDoctor.error || "NemoClaw doctor did not return a report."
: `Using OpenShell compatibility checks; NemoClaw doctor requires ${nemoclawDoctor.minimumVersion}+${nemoclawDoctor.version ? `, found ${nemoclawDoctor.version}` : ""}.`,
},
]
return NextResponse.json({
@@ -71,6 +91,19 @@ export async function GET(
phase,
},
checks,
nemoclaw: {
doctor: {
available: nemoclawDoctor.available,
supported: nemoclawDoctor.supported,
attempted: nemoclawDoctor.attempted,
version: nemoclawDoctor.version,
minimumVersion: nemoclawDoctor.minimumVersion,
status: nemoclawDoctor.report?.status ?? null,
failed: nemoclawDoctor.report?.failed ?? null,
warnings: nemoclawDoctor.report?.warnings ?? null,
error: nemoclawDoctor.error ?? null,
},
},
backupCount: relatedBackups.length,
durationMs: Date.now() - startedAt,
checkedAt: new Date().toISOString(),
+20 -1
View File
@@ -2,6 +2,7 @@ import { NextResponse } from "next/server"
import { execFile } from "node:child_process"
import { promisify } from "node:util"
import { OPENSHELL_BIN, hostCommandEnv } from "@/app/lib/hostCommands"
import { recoverSandboxWithNemoClaw } from "@/app/lib/nemoclawCli"
import { inspectSandbox, resolveSandboxRef } from "@/app/lib/openshellHost"
const execFileAsync = promisify(execFile)
@@ -100,6 +101,21 @@ export async function POST(
}, { status: 409 })
}
const nemoclawRecover = await recoverSandboxWithNemoClaw(sandboxName)
if (nemoclawRecover.attempted && nemoclawRecover.ok) {
return NextResponse.json({
ok: true,
restarted: true,
restartMode: "nemoclaw-recover",
sandboxId: resolved.id,
sandboxName,
readiness,
nemoclawRecover,
elapsedMs: Date.now() - startedAt,
note: "NemoClaw recover completed. The sandbox runtime and dashboard forward were checked without deleting the sandbox.",
})
}
const runtime = await runSandboxShell(sandboxName, restartOpenClawGatewayScript(), 45000)
return NextResponse.json({
@@ -109,9 +125,12 @@ export async function POST(
sandboxId: resolved.id,
sandboxName,
readiness,
nemoclawRecover,
runtime,
elapsedMs: Date.now() - startedAt,
note: "OpenClaw runtime restarted inside the sandbox. The sandbox pod was not deleted.",
note: nemoclawRecover.attempted
? "NemoClaw recover did not complete, so the dashboard fell back to restarting the in-sandbox OpenClaw runtime. The sandbox pod was not deleted."
: "OpenClaw runtime restarted inside the sandbox. The sandbox pod was not deleted.",
})
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to restart sandbox runtime"