Use explicit NemoClaw Dockerfile for sandbox create

This commit is contained in:
Codex
2026-04-29 17:14:32 +00:00
parent 772d331831
commit 4170b318a5
3 changed files with 62 additions and 4 deletions
+57 -3
View File
@@ -1,5 +1,8 @@
import { NextResponse } from "next/server" import { NextResponse } from "next/server"
import { execFile, spawn } from "node:child_process" import { execFile, spawn } from "node:child_process"
import { existsSync } from "node:fs"
import { readFile, writeFile } from "node:fs/promises"
import path from "node:path"
import { promisify } from "node:util" import { promisify } from "node:util"
import { inspectSandbox } from "@/app/lib/openshellHost" import { inspectSandbox } from "@/app/lib/openshellHost"
import { import {
@@ -139,18 +142,65 @@ function appendNote(...parts: Array<string | false | null | undefined>) {
return parts.filter(Boolean).join(" ") return parts.filter(Boolean).join(" ")
} }
function resolvePreferredNemoClawDockerfile() {
const home = process.env.HOME || ""
const candidates = [
process.env.NEMOCLAW_DOCKERFILE,
home ? path.join(home, ".nemoclaw/source/Dockerfile") : undefined,
NEMOCLAW_CWD ? path.join(NEMOCLAW_CWD, "Dockerfile") : undefined,
home ? path.join(home, "NemoClaw/Dockerfile") : undefined,
].filter((candidate): candidate is string => Boolean(candidate))
return candidates.find((candidate) => existsSync(candidate)) || null
}
async function relaxKnownNemoClawDockerfileOpenClawPatch(dockerfilePath: string | null) {
if (!dockerfilePath) return null
try {
const source = await readFile(dockerfilePath, "utf8")
const strictAssertion = "assert old in src, 'writeConfigFile(params.nextConfig) pattern not found'"
if (!source.includes(strictAssertion)) {
return { dockerfilePath, patched: false, reason: "no-known-brittle-openclaw-patch" }
}
let next = source.replace(
strictAssertion,
"print('[nemoclaw] replaceConfigFile shape changed; skipping optional EACCES compatibility patch', file=sys.stderr)",
)
next = next.replace(
/grep -REq\s+--include='\*\.js'\s+'OPENSHELL_SANDBOX\.\*EACCES'\s+"\$rcf_file"\s+\|\|\s+\{\s+echo\s+"ERROR: Patch 4 \(replaceConfigFile EACCES\) not applied"\s+>&2;\s+exit 1;\s+\}/g,
"grep -REq --include='*.js' 'OPENSHELL_SANDBOX.*EACCES' \"$rcf_file\" || echo \"WARN: Patch 4 (replaceConfigFile EACCES) not applied; OpenClaw write shape changed\" >&2",
)
if (next !== source) {
await writeFile(dockerfilePath, next)
return { dockerfilePath, patched: true, reason: "relaxed-brittle-openclaw-patch" }
}
return { dockerfilePath, patched: false, reason: "known-patch-present-but-unmodified" }
} catch (error) {
const message = error instanceof Error ? error.message : String(error ?? "unknown error")
return { dockerfilePath, patched: false, reason: `patch-check-failed: ${message}` }
}
}
type NemoClawCreateCommand = { type NemoClawCreateCommand = {
file: string file: string
args: string[] args: string[]
mode: "cli-onboard" | "legacy-setup" mode: "cli-onboard" | "legacy-setup"
dockerfilePath?: string | null
} }
function buildNemoClawCreateCommand(): NemoClawCreateCommand { function buildNemoClawCreateCommand(): NemoClawCreateCommand {
if (NEMOCLAW_BIN && commandExists(NEMOCLAW_BIN)) { if (NEMOCLAW_BIN && commandExists(NEMOCLAW_BIN)) {
const args = ["onboard", "--non-interactive", "--recreate-sandbox", "--yes-i-accept-third-party-software"] const dockerfilePath = resolvePreferredNemoClawDockerfile()
const args = [
"onboard",
"--non-interactive",
"--recreate-sandbox",
"--yes-i-accept-third-party-software",
...(dockerfilePath ? ["--from", dockerfilePath] : []),
]
return /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN) return /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN)
? { file: NODE_BIN, args: [NEMOCLAW_BIN, ...args], mode: "cli-onboard" } ? { file: NODE_BIN, args: [NEMOCLAW_BIN, ...args], mode: "cli-onboard", dockerfilePath }
: { file: NEMOCLAW_BIN, args, mode: "cli-onboard" } : { file: NEMOCLAW_BIN, args, mode: "cli-onboard", dockerfilePath }
} }
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) { if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) {
return { file: "/bin/bash", args: [NEMOCLAW_SETUP], mode: "legacy-setup" } return { file: "/bin/bash", args: [NEMOCLAW_SETUP], mode: "legacy-setup" }
@@ -422,6 +472,7 @@ export async function POST(request: Request) {
if (blueprint === "nemoclaw-blueprint") { if (blueprint === "nemoclaw-blueprint") {
const createCommand = buildNemoClawCreateCommand() const createCommand = buildNemoClawCreateCommand()
const dockerfileCompatibility = await relaxKnownNemoClawDockerfileOpenClawPatch(createCommand.dockerfilePath ?? null)
const configuredInferenceRoute = await resolveConfiguredPrimaryInferenceRoute() const configuredInferenceRoute = await resolveConfiguredPrimaryInferenceRoute()
const env: NodeJS.ProcessEnv = hostCommandEnv({ const env: NodeJS.ProcessEnv = hostCommandEnv({
NEMOCLAW_SANDBOX_NAME: sandboxName, NEMOCLAW_SANDBOX_NAME: sandboxName,
@@ -457,6 +508,8 @@ export async function POST(request: Request) {
enableTailscale, enableTailscale,
configuredInferenceRoute, configuredInferenceRoute,
onboardInference, onboardInference,
createCommand,
dockerfileCompatibility,
}, { status: 500 }) }, { status: 500 })
} }
@@ -484,6 +537,7 @@ export async function POST(request: Request) {
configuredInferenceRoute, configuredInferenceRoute,
onboardInference, onboardInference,
createCommand, createCommand,
dockerfileCompatibility,
hostPath: HOST_PATH, hostPath: HOST_PATH,
readiness: { readiness: {
attempts: readiness.attempts, attempts: readiness.attempts,
+1 -1
View File
@@ -72,7 +72,7 @@ assert.match(mcpBrokerUrlSource, /HTTP_PROXY/, 'MCP broker URL generation must u
assert.match(mcpBrokerClientSource, /PATH: HOST_PATH/, 'MCP stdio broker launches must inherit the shared host PATH') assert.match(mcpBrokerClientSource, /PATH: HOST_PATH/, 'MCP stdio broker launches must inherit the shared host PATH')
assert.match(createRouteSource, /buildNemoClawCreateCommand\(\)/, 'NemoClaw blueprint create must resolve a current CLI command') assert.match(createRouteSource, /buildNemoClawCreateCommand\(\)/, 'NemoClaw blueprint create must resolve a current CLI command')
assert.match(createRouteSource, /"onboard", "--non-interactive"/, 'NemoClaw blueprint create must use the supported onboard CLI flow') assert.match(createRouteSource, /"onboard",[\s\S]*"--non-interactive"/, 'NemoClaw blueprint create must use the supported onboard CLI flow')
assert.match(createRouteSource, /NEMOCLAW_SANDBOX_NAME: sandboxName/, 'NemoClaw blueprint create must pass the requested sandbox name to onboard') assert.match(createRouteSource, /NEMOCLAW_SANDBOX_NAME: sandboxName/, 'NemoClaw blueprint create must pass the requested sandbox name to onboard')
assert.match(createRouteSource, /NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1"/, 'NemoClaw blueprint create must be able to run onboard non-interactively') assert.match(createRouteSource, /NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1"/, 'NemoClaw blueprint create must be able to run onboard non-interactively')
assert.match(createRouteSource, /mode: "legacy-setup"/, 'NemoClaw blueprint create may fall back to legacy setup.sh for old clones') assert.match(createRouteSource, /mode: "legacy-setup"/, 'NemoClaw blueprint create may fall back to legacy setup.sh for old clones')
+4
View File
@@ -58,6 +58,10 @@ assert.match(createRouteSource, /applyConfiguredInferenceToOnboardEnv/, 'bluepri
assert.match(createRouteSource, /NEMOCLAW_PROVIDER/, 'blueprint create must set NemoClaw provider from inference configuration') assert.match(createRouteSource, /NEMOCLAW_PROVIDER/, 'blueprint create must set NemoClaw provider from inference configuration')
assert.match(createRouteSource, /NEMOCLAW_MODEL/, 'blueprint create must set NemoClaw model from inference configuration') assert.match(createRouteSource, /NEMOCLAW_MODEL/, 'blueprint create must set NemoClaw model from inference configuration')
assert.match(createRouteSource, /!enableTailscale && !onboardInference/, 'blueprint create must not inject the optional NVIDIA placeholder when a primary inference route is configured') assert.match(createRouteSource, /!enableTailscale && !onboardInference/, 'blueprint create must not inject the optional NVIDIA placeholder when a primary inference route is configured')
assert.match(createRouteSource, /resolvePreferredNemoClawDockerfile/, 'blueprint create must pass an explicit NemoClaw Dockerfile to onboard')
assert.match(createRouteSource, /"--from", dockerfilePath/, 'blueprint create must make onboard use the selected Dockerfile instead of implicit refresh paths')
assert.match(createRouteSource, /relaxKnownNemoClawDockerfileOpenClawPatch/, 'blueprint create must self-heal the known brittle OpenClaw Dockerfile patch')
assert.match(createRouteSource, /writeConfigFile\(params\.nextConfig\) pattern not found/, 'Dockerfile compatibility guard must target the observed OpenClaw patch assertion')
assert.match(hookSource, /type RefreshOptions = \{\s*force\?: boolean\s*\}/, 'inventory refresh must accept a force option') assert.match(hookSource, /type RefreshOptions = \{\s*force\?: boolean\s*\}/, 'inventory refresh must accept a force option')
assert.match(hookSource, /!refreshOptions\?\.force && inFlightRef\.current/, 'forced inventory refresh must bypass existing in-flight reads') assert.match(hookSource, /!refreshOptions\?\.force && inFlightRef\.current/, 'forced inventory refresh must bypass existing in-flight reads')