Handle gateway failures during sandbox delete

This commit is contained in:
Codex
2026-04-28 21:51:26 +00:00
parent b17d3a292d
commit 42561a7eff
3 changed files with 31 additions and 7 deletions
+24 -3
View File
@@ -78,11 +78,28 @@ function isSandboxNotFound(output: string) {
return /sandbox not found|status:\s*NotFound|not present in the live OpenShell gateway/i.test(output)
}
function isGatewayRecoverable(output: string) {
return /Unknown gateway|Deploy it first|transport error|tcp connect error|Connection refused|invalid peer certificate|BadSignature/i.test(output)
}
function isValidNemoClawSandboxName(value: string) {
return /^[a-z][a-z0-9-]*[a-z0-9]$|^[a-z]$/.test(value)
}
function isNemoClawSandboxNotRegistered(output: string, sandboxName: string) {
return new RegExp(`Unknown command:\\s*${sandboxName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "i").test(output)
}
async function cleanupNemoClawSandbox(sandboxName: string) {
if (!isValidNemoClawSandboxName(sandboxName)) {
return {
ok: true as const,
stdout: "",
stderr: "",
note: "Skipped NemoClaw registry cleanup because the target is not a valid NemoClaw sandbox name.",
}
}
const startedAt = Date.now()
console.log(`[sandbox/delete] nemoclaw-cleanup:start sandbox=${sandboxName}`)
try {
@@ -169,7 +186,6 @@ export async function POST(request: Request) {
const result = await deleteSandbox(target.sandboxName)
const deleteOutput = [result.error, result.stdout, result.stderr].filter(Boolean).join("\n")
const openShellAlreadyGone = !result.ok && isSandboxNotFound(deleteOutput)
const cleanup = await cleanupNemoClawSandbox(target.sandboxName)
if (!result.ok && !openShellAlreadyGone) {
return NextResponse.json({
@@ -183,10 +199,15 @@ export async function POST(request: Request) {
error: result.error,
stdout: result.stdout,
stderr: result.stderr,
nemoclaw: cleanup,
}, { status: 500 })
recoverableGateway: isGatewayRecoverable(deleteOutput),
note: isGatewayRecoverable(deleteOutput)
? "OpenShell gateway is unavailable or its trust state is broken. Repair gateway trust, then retry delete."
: "OpenShell delete failed before NemoClaw cleanup ran.",
}, { status: isGatewayRecoverable(deleteOutput) ? 503 : 500 })
}
const cleanup = await cleanupNemoClawSandbox(target.sandboxName)
if (!cleanup.ok) {
return NextResponse.json({
ok: false,
+3 -3
View File
@@ -95,7 +95,7 @@ export default function Dashboard() {
const sleep = (ms: number) => new Promise((resolve) => window.setTimeout(resolve, ms))
const gatewayTrustError = Boolean(error && /BadSignature|invalid peer certificate|transport error|certificate signature/i.test(error))
const gatewayTrustError = Boolean(error && /BadSignature|invalid peer certificate|transport error|certificate signature|Unknown gateway|Deploy it first|Connection refused|tcp connect error/i.test(error))
const repairGatewayTrust = async () => {
if (gatewayRepairing) return
@@ -346,7 +346,7 @@ export default function Dashboard() {
<div className="mx-auto mt-5 max-w-2xl rounded-sm border border-amber-500/40 bg-amber-500/10 p-4 text-left">
<h4 className="text-xs font-semibold uppercase tracking-wider text-amber-300">Gateway Trust Mismatch</h4>
<p className="mt-2 text-xs leading-5 text-amber-100/80">
OpenShell reached the gateway, but certificate verification failed. This usually means the gateway regenerated mTLS material while this controller still has stale trust files.
OpenShell could not use the selected gateway. This usually means the gateway stopped, was undeployed, or regenerated mTLS material while this controller still has stale trust files.
</p>
<button
type="button"
@@ -440,7 +440,7 @@ export default function Dashboard() {
<div className="mx-auto mt-5 max-w-2xl rounded-sm border border-amber-500/40 bg-amber-500/10 p-4 text-left">
<h4 className="text-xs font-semibold uppercase tracking-wider text-amber-300">Gateway Trust Mismatch</h4>
<p className="mt-2 text-xs leading-5 text-amber-100/80">
OpenShell reached the gateway, but certificate verification failed. This usually means the gateway regenerated mTLS material while this controller still has stale trust files.
OpenShell could not use the selected gateway. This usually means the gateway stopped, was undeployed, or regenerated mTLS material while this controller still has stale trust files.
</p>
<button
type="button"