π OpenHands: AI-Driven Development
feat(verify-openhands): launch --mars-web and --lock-to-cloud (#18848)
Engel Nyst394a56275396
diff --git a/.agents/skills/verify-openhands/SKILL.md b/.agents/skills/verify-openhands/SKILL.mdindex ac14b9a08c..7246d69065 100644--- a/.agents/skills/verify-openhands/SKILL.md+++ b/.agents/skills/verify-openhands/SKILL.md@@ -98,6 +98,14 @@ control-openhands stop # stops only this run; evidence sagent-server has no editor binary and nothing listens there). Where that is opt-in (#17660), `--vscode`turns it on; where the editor is bundled (before #17660, or since #18048), itis always included and `--vscode` changes nothing.+- **Launch variants** that a launcher flag or a deployment sets, not the+ operator's shell: `--mars-web` starts the launcher with `MARS_WEB=1` (the+ ingress hosts the Managed Agents bridge, `/mars/*`, and Add Backend offers+ Providers; doctor checks `/mars/health`). `--lock-to-cloud <url>` also serves+ the build locked to that Cloud host on `ports.lockedCloud` (P+4), because+ only `scripts/static-server.mjs` takes `--lock-to-cloud`; `browser goto+ <lockedCloud.url>/` opens it as a run page, and `stop` ends it with the run.+ Never hand-start these processes on fixed ports: `stop` cannot see them.- **Doctor** checks the launcher's process group, ports, served build revision,unauthenticated rejection, authenticated settings, Agent Server pin and theUI's minimum Agent Server version, automation health and a throwaway-tab UIdiff --git a/.agents/skills/verify-openhands/scripts/browser-daemon.mjs b/.agents/skills/verify-openhands/scripts/browser-daemon.mjsindex 6f86492eca..8ff45b40e1 100755--- a/.agents/skills/verify-openhands/scripts/browser-daemon.mjs+++ b/.agents/skills/verify-openhands/scripts/browser-daemon.mjs@@ -58,6 +58,14 @@ if (!runDir) {const privateDir = join(runDir, "private");const evidenceDir = join(runDir, "evidence");const baseUrl = new URL(process.env.OH_VERIFY_BASE_URL);+// Other origins this run serves (`launch --lock-to-cloud`): its own pages too.+const runOrigins = new Set([+ baseUrl.origin,+ ...(process.env.OH_VERIFY_EXTRA_ORIGINS ?? "")+ .split(",")+ .filter(Boolean)+ .map((u) => new URL(u).origin),+]);const eventsPath = join(privateDir, "browser-events.jsonl");const VIEWPORTS = {desktop: { width: 1440, height: 1000 },@@ -225,7 +233,7 @@ function record(kind, page, detail) {...detail,};const subject = entry.url || entry.page;- entry.appOrigin = originOf(subject) === baseUrl.origin;+ entry.appOrigin = runOrigins.has(originOf(subject));events.push(entry);try {appendFileSync(eventsPath, `${JSON.stringify(entry)}\n`, { mode: 0o600 });@@ -291,7 +299,7 @@ function watch(page) {query: query || undefined,method: request.method(),type: request.resourceType(),- app: origin === baseUrl.origin,+ app: runOrigins.has(origin),body,...bodyDetails,};@@ -537,9 +545,9 @@ function evidencePath(feature, name, ext) {function assertAppUrl(target, allowExternal) {const url = new URL(target, baseUrl);- if (!allowExternal && url.origin !== baseUrl.origin) {+ if (!allowExternal && !runOrigins.has(url.origin)) {throw new Error(- `Refusing to navigate outside this run (${baseUrl.origin}); pass --allow-external for a deliberate external check`,+ `Refusing to navigate outside this run (${[...runOrigins].join(", ")}); pass --allow-external for a deliberate external check`,);}return url.toString();diff --git a/.agents/skills/verify-openhands/scripts/control-openhands.mjs b/.agents/skills/verify-openhands/scripts/control-openhands.mjsindex 5a154b4598..89cc19c56f 100755--- a/.agents/skills/verify-openhands/scripts/control-openhands.mjs+++ b/.agents/skills/verify-openhands/scripts/control-openhands.mjs@@ -30,6 +30,7 @@ import { groupAlive, privatePurgeAllowed } from "./lib/process-groups.mjs";import {editorOffset,launcherEnvFor,+ lockedCloudOrigin,portsAfterRestart,runPorts,} from "./lib/launcher-env.mjs";@@ -291,13 +292,14 @@ function releaseClaim(run) {}}-async function findPortBlock(start, runDir, editor) {+async function findPortBlock(start, runDir, editor, options) {// The launcher needs ingress P, agent-server P+1, automation P+2, static// frontend P+3, and the editor port only when it serves VS Code (`editor`// is its offset from the agent-server port, or null; see editorOffset).+ // A --lock-to-cloud run also needs P+4.mkdirSync(verifyHome, { recursive: true });for (let base = start; base < start + 900; base += 10) {- const ports = Object.values(runPorts(base, editor));+ const ports = Object.values(runPorts(base, editor, options));const busy = await Promise.all(ports.map((p) => portOpen(p)));if (busy.some(Boolean)) continue;if (tryClaim(base, runDir)) return base;@@ -420,6 +422,8 @@ async function startBrowser(run) {...process.env,OH_VERIFY_RUN: run.dir,OH_VERIFY_BASE_URL: run.baseUrl,+ // `browser goto` may also open the run's own locked-to-Cloud page.+ OH_VERIFY_EXTRA_ORIGINS: run.lockedCloud?.url ?? "",},});child.unref();@@ -530,6 +534,19 @@ async function cmdLaunch({ flags }) {// and run.json of a run that may still be live. `restart` reuses a run.const requestedRunId = flags["run-id"];if (requestedRunId !== undefined) checkNewRunId(requestedRunId);+ let lockedCloud;+ if (flags["lock-to-cloud"] !== undefined) {+ try {+ lockedCloud = lockedCloudOrigin(+ flags["lock-to-cloud"] === true ? "" : flags["lock-to-cloud"],+ );+ } catch (error) {+ usage(+ error.message,+ "control-openhands launch --new --lock-to-cloud https://app.all-hands.dev",+ );+ }+ }if (nodeMajor() < 24) {throw new CliError(`Node >=24 is required by the launcher; this is ${process.version}.`,@@ -700,18 +717,22 @@ async function cmdLaunch({ flags }) {if (flags["automation-version"])env.OH_AUTOMATION_VERSION = flags["automation-version"];if (flags.vscode) env.OH_CANVAS_ENABLE_VSCODE = "true";+ // The ingress hosts the DigitalOcean Managed Agents web bridge (/mars/*)+ // only with exactly MARS_WEB=1 (OpenHands/OpenHands#18783).+ if (flags["mars-web"]) env.MARS_WEB = "1";// Only PASS_ENV and the flags above reach the launcher, so a version pin// exported in the caller's shell would be dropped without a word.const ignoredEnv = Object.keys(process.env).filter((k) =>(/^OH_(AGENT_SERVER|AUTOMATION)_/.test(k) ||- k === "OH_CANVAS_ENABLE_VSCODE") &&+ k === "OH_CANVAS_ENABLE_VSCODE" ||+ k === "MARS_WEB") &&!(k in env),);const warnings = [];if (ignoredEnv.length)warnings.push(- `Ignored ${ignoredEnv.join(", ")} from your shell: runs are isolated. Use --sdk-version/--sdk-ref/--sdk-path, --automation-version/--automation-ref/--automation-path or --vscode.`,+ `Ignored ${ignoredEnv.join(", ")} from your shell: runs are isolated. Use --sdk-version/--sdk-ref/--sdk-path, --automation-version/--automation-ref/--automation-path, --vscode or --mars-web.`,);// 4. Ports. The editor port is reserved only when this checkout's launcher@@ -722,14 +743,16 @@ async function cmdLaunch({ flags }) {warnings.push(`Could not ask scripts/dev-with-automation.mjs whether it serves VS Code (${editor.reason}); reserving the editor port as before.`,);+ const portOptions = { lockedCloud: lockedCloud !== undefined };const base = flags.port? intFlag(flags.port): await findPortBlock(intFlag(flags["port-from"], 18800),dir,editor.offset,+ portOptions,);- const ports = runPorts(base, editor.offset);+ const ports = runPorts(base, editor.offset, portOptions);if (flags.port) {const busy = [];for (const [name, port] of Object.entries(ports))@@ -780,9 +803,19 @@ async function cmdLaunch({ flags }) {pins: defaults().versions,overrides: Object.fromEntries(Object.entries(env).filter(([k]) =>- /^OH_(AGENT_SERVER_|AUTOMATION_|CANVAS_ENABLE_VSCODE$)/.test(k),+ /^(OH_(AGENT_SERVER_|AUTOMATION_|CANVAS_ENABLE_VSCODE$)|MARS_WEB$)/.test(+ k,+ ),),),+ ...(lockedCloud+ ? {+ lockedCloud: {+ cloud: lockedCloud,+ url: `http://127.0.0.1:${ports.lockedCloud}`,+ },+ }+ : {}),};spawnLauncher(run);saveRun(run);@@ -807,6 +840,7 @@ async function cmdLaunch({ flags }) {};run.readyAt = new Date().toISOString();saveRun(run);+ if (run.lockedCloud) await startLockedCloud(run, intFlag(flags.timeout, 600));let browser;if (!flags["no-browser"]) {@@ -838,6 +872,7 @@ async function cmdLaunch({ flags }) {revision,builtThisRun: built,ports,+ ...(run.lockedCloud ? { lockedCloud: run.lockedCloud } : {}),versions: run.versions,browser,next: [@@ -915,6 +950,102 @@ function spawnLauncher(run) {return child;}+// A page locked to one OpenHands Cloud host (F01.locked-cloud-first-run,+// F25.locked-cloud). bin/agent-canvas.mjs has no option for it; only+// scripts/static-server.mjs --lock-to-cloud has. So a --lock-to-cloud run+// serves the same build from a second static server on P+4, in its own+// process group, which `stop` ends with the run. The locked page talks only+// to that Cloud host, so it gets no session key.+async function startLockedCloud(run, timeoutSec) {+ const priv = join(run.dir, "private");+ const env = {};+ for (const name of PASS_ENV)+ if (process.env[name] !== undefined) env[name] = process.env[name];+ Object.assign(env, {+ HOME: join(priv, "home"),+ DO_NOT_TRACK: "1",+ // One bridge per stack at most: this page never hosts /mars/*.+ MARS_WEB: "0",+ });+ const logPath = join(priv, "locked-cloud.log");+ const logFd = openSync(logPath, "a", 0o600);+ const child = spawn(+ process.execPath,+ [+ join(repoRoot, "scripts", "static-server.mjs"),+ "--dir",+ join(repoRoot, "build"),+ "--host",+ "127.0.0.1",+ "--port",+ String(run.ports.lockedCloud),+ "--lock-to-cloud",+ run.lockedCloud.cloud,+ ],+ { cwd: repoRoot, env, detached: true, stdio: ["ignore", logFd, logFd] },+ );+ child.unref();+ run.lockedCloud.pgid = child.pid;+ saveRun(run);+ const deadline = Date.now() + timeoutSec * 1000;+ let last = "";+ for (;;) {+ if (!groupAlive(child.pid)) {+ throw new CliError("The locked-to-Cloud static server exited.", {+ code: 3,+ hint: "The stack is running; `control-openhands stop` it and retry.",+ extra: {+ run: run.dir,+ logTail: readFileSync(logPath, "utf8")+ .split("\n")+ .slice(-15)+ .join("\n"),+ },+ });+ }+ try {+ const response = await fetch(`${run.lockedCloud.url}/`, {+ signal: AbortSignal.timeout(4000),+ });+ const html = await response.text();+ last = `status=${response.status}`;+ if (response.ok && html.includes("__AGENT_CANVAS_LOCK_TO_CLOUD__"))+ return;+ } catch (error) {+ last = String(error.message);+ }+ if (Date.now() > deadline)+ throw new CliError(+ `The locked-to-Cloud page is not ready after ${timeoutSec}s (${last}).`,+ { code: 3, extra: { run: run.dir } },+ );+ await delay(500);+ }+}++async function stopLockedCloud(run) {+ const pgid = run.lockedCloud?.pgid;+ if (!groupAlive(pgid)) return { stopped: true };+ const cmd = commandLine(pgid);+ if (cmd && !cmd.includes("static-server.mjs")) {+ throw new CliError(+ `PID ${pgid} is no longer this run's locked-to-Cloud server (${cmd.slice(0, 80)}); refusing to signal it.`,+ { code: 3 },+ );+ }+ let forced = false;+ process.kill(-pgid, "SIGTERM");+ for (let i = 0; i < 20 && groupAlive(pgid); i += 1) await delay(500);+ if (groupAlive(pgid)) {+ process.kill(-pgid, "SIGKILL");+ forced = true;+ await delay(1000);+ }+ for (let i = 0; i < 20 && (await portOpen(run.ports.lockedCloud)); i += 1)+ await delay(500);+ return { stopped: !groupAlive(pgid), forced };+}+async function stopLauncher(run) {const pgid = run.launcherPgid;let forced = false;@@ -951,7 +1082,9 @@ async function stopLauncher(run) {}}// Give sockets a moment to close before callers check or reuse the ports.- for (const port of Object.values(run.ports)) {+ // The locked-to-Cloud page is not the launcher's: a restart keeps it.+ for (const [name, port] of Object.entries(run.ports)) {+ if (name === "lockedCloud") continue;for (let i = 0; i < 20 && (await portOpen(port)); i += 1) await delay(500);}return { stopped: !groupAlive(pgid), forced };@@ -1125,6 +1258,14 @@ async function cmdStatus({ flags }) {launcherAlive: groupAlive(run.launcherPgid),browserAlive: Boolean(daemonInfo(run)),ports: run.ports,+ ...(run.lockedCloud+ ? {+ lockedCloud: {+ ...run.lockedCloud,+ alive: groupAlive(run.lockedCloud.pgid),+ },+ }+ : {}),versions: run.versions,startedAt: run.startedAt,});@@ -1232,10 +1373,40 @@ async function cmdDoctor({ flags }) {automation.status === 200,`status=${automation.status}`,);+ if (run.overrides?.MARS_WEB === "1") {+ const mars = await http(run, "GET", "/mars/health", { auth: false });+ add(+ "Managed Agents web bridge mounted (--mars-web)",+ mars.status === 200 && mars.json?.ok === true,+ `GET /mars/health status=${mars.status} ${mars.text.slice(0, 80)}`,+ );+ }} catch (error) {add("HTTP checks", false, String(error.message));}}+ if (run.lockedCloud) {+ try {+ const response = await fetch(`${run.lockedCloud.url}/`, {+ signal: AbortSignal.timeout(4000),+ });+ const html = await response.text();+ const locked = html.match(/__AGENT_CANVAS_LOCK_TO_CLOUD__=([^;<]*)/);+ add(+ "locked-to-Cloud page serves the lock (--lock-to-cloud)",+ response.ok &&+ Boolean(locked) &&+ locked[1].includes(run.lockedCloud.cloud),+ `${run.lockedCloud.url}/ status=${response.status} lock=${locked?.[1] ?? "missing"}`,+ );+ } catch (error) {+ add(+ "locked-to-Cloud page serves the lock (--lock-to-cloud)",+ false,+ String(error.message),+ );+ }+ }if (!flags["skip-ui"]) {if (daemonInfo(run)) {try {@@ -1289,10 +1460,15 @@ async function cmdStop({ flags }) {const pgid = run.launcherPgid;const launcher = await stopLauncher(run);if (launcher.forced) result.forced = true;+ if (run.lockedCloud) {+ const locked = await stopLockedCloud(run);+ if (locked.forced) result.forced = true;+ }const ports = {};for (const [name, port] of Object.entries(run.ports))ports[name] = (await portOpen(port)) ? "still open" : "closed";- result.launcherStopped = !groupAlive(pgid);+ result.launcherStopped =+ !groupAlive(pgid) && !groupAlive(run.lockedCloud?.pgid);if (privatePurgeAllowed(result.launcherStopped, ports)) {releaseClaim(run);rmSync(tmuxPathFor(run.dir), { recursive: true, force: true });@@ -4598,6 +4774,7 @@ Examples:launch: `control-openhands launch [--public] [--new] [--print-run] [--port N | --port-from N] [--build auto|always|never] [--min-free-mb 2000][--no-browser] [--timeout SEC] [--sdk-path DIR | --sdk-ref REF | --sdk-version V][--automation-path DIR | --automation-ref REF | --automation-version V] [--run-id ID] [--vscode]+ [--mars-web] [--lock-to-cloud URL]Builds the checkout when build/verify-revision.txt does not match HEAD, thenstarts bin/agent-canvas.mjs with a private HOME, state dir, session key and@@ -4608,14 +4785,23 @@ ports, only when the checkout's launcher serves VS Code. Where that is opt-inis bundled (before #17660, or since #18048), it is always reserved and --vscodechanges nothing. Waits for authenticated settings, automation health and theSPA, then starts the browser daemon.+--mars-web starts the launcher with MARS_WEB=1, so the run's ingress hosts the+DigitalOcean Managed Agents web bridge (/mars/*) and Add Backend offers the+Providers tab; doctor checks /mars/health.+--lock-to-cloud URL also serves this build locked to that OpenHands Cloud host+(scripts/static-server.mjs --lock-to-cloud; bin/agent-canvas.mjs has no such+option) on P+4, listed as ports.lockedCloud and lockedCloud.url. The locked page+talks only to that Cloud host, never to the run's backend. \`browser goto+<lockedCloud.url>/\` opens it without --allow-external, doctor checks the lock is+injected, and stop ends it with the run.Idempotent: an alive current run is reused unless --new is given.--print-run prints only the run directory, forexport OH_VERIFY_RUN=$(control-openhands launch --new --print-run)Every other command uses --run, else $OH_VERIFY_RUN, else the only live run;with several live runs it refuses to guess (several agents on one machine).-Backend versions and VS Code come only from the flags: OH_AGENT_SERVER_*,-OH_AUTOMATION_* and OH_CANVAS_ENABLE_VSCODE in your shell are not forwarded-(launch warns). An Agent Server below+Backend versions, VS Code and the bridge come only from the flags:+OH_AGENT_SERVER_*, OH_AUTOMATION_*, OH_CANVAS_ENABLE_VSCODE and MARS_WEB in your+shell are not forwarded (launch warns). An Agent Server belowconfig/defaults.json compatibility.minimumAgentServer never getspast the UI's backend-compatibility gate.@@ -4628,6 +4814,8 @@ Examples:control-openhands launchcontrol-openhands launch --public --newcontrol-openhands launch --sdk-path ../software-agent-sdk --build always+ control-openhands launch --new --mars-web+ control-openhands launch --new --lock-to-cloud https://app.all-hands.dev`,doctor: `control-openhands doctor [--skip-ui]diff --git a/.agents/skills/verify-openhands/scripts/control-openhands.test.mjs b/.agents/skills/verify-openhands/scripts/control-openhands.test.mjsindex 1919d2214b..a5a00de488 100755--- a/.agents/skills/verify-openhands/scripts/control-openhands.test.mjs+++ b/.agents/skills/verify-openhands/scripts/control-openhands.test.mjs@@ -25,6 +25,7 @@ import { BUILD_INPUTS } from "./lib/build-inputs.mjs";import {editorOffset,launcherEnvFor,+ lockedCloudOrigin,portsAfterRestart,runPorts,} from "./lib/launcher-env.mjs";@@ -691,6 +692,53 @@ test("this checkout's launcher answers the editor probe, and --vscode opts in",assert.match(help.stdout, /OH_CANVAS_ENABLE_VSCODE/);});+test("--lock-to-cloud takes P+4, keeps it across a restart, and needs an http(s) URL", () => {+ const launcher = (offset) => ({ offset, source: "launcher" });+ const locked = runPorts(18800, null, { lockedCloud: true });+ assert.deepEqual(locked, {+ ingress: 18800,+ agentServer: 18801,+ automation: 18802,+ frontend: 18803,+ lockedCloud: 18804,+ });+ // The locked page is not the launcher's: whatever the editor answer, a+ // restart keeps its port.+ assert.equal(+ portsAfterRestart(locked, launcher(null)).ports.lockedCloud,+ 18804,+ );+ assert.equal(+ portsAfterRestart(locked, launcher(1000)).ports.lockedCloud,+ 18804,+ );+ assert.equal(+ portsAfterRestart(runPorts(18800, null), launcher(null)).ports.lockedCloud,+ undefined,+ );+ assert.equal(+ lockedCloudOrigin("https://app.all-hands.dev/"),+ "https://app.all-hands.dev",+ );+ assert.throws(() => lockedCloudOrigin("app.all-hands.dev"), /Cloud URL/);+ assert.throws(() => lockedCloudOrigin("ftp://example.com"), /http\(s\)/);+ // A bad or missing URL is a usage error before anything is built or started.+ for (const flags of [+ ["--lock-to-cloud", "ftp://example.com"],+ ["--lock-to-cloud"],+ ]) {+ const result = run(["launch", "--new", ...flags]);+ assert.equal(result.status, 2, JSON.stringify(result.json));+ assert.match(result.json.hint, /--lock-to-cloud https:/);+ }+ const help = spawnSync(process.execPath, [cli, "help", "launch"], {+ encoding: "utf8",+ });+ assert.match(help.stdout, /--mars-web/);+ assert.match(help.stdout, /MARS_WEB=1/);+ assert.match(help.stdout, /--lock-to-cloud URL/);+});+test("a restart follows the launcher's editor answer, or keeps its ports", () => {const without = runPorts(18800, null);const withEditor = runPorts(18800, 1000);diff --git a/.agents/skills/verify-openhands/scripts/lib/launcher-env.mjs b/.agents/skills/verify-openhands/scripts/lib/launcher-env.mjsindex f4b0f37014..f049cd1b1f 100644--- a/.agents/skills/verify-openhands/scripts/lib/launcher-env.mjs+++ b/.agents/skills/verify-openhands/scripts/lib/launcher-env.mjs@@ -121,18 +121,42 @@ export function editorOffset(repoRoot, env) {/*** A run's ports from its block base: ingress P, agent-server P+1, automation- * P+2, static frontend P+3, and the editor only when the launcher serves it.+ * P+2, static frontend P+3, the locked-to-Cloud page P+4 when the run serves+ * one (`launch --lock-to-cloud`), and the editor only when the launcher+ * serves it.*/-export function runPorts(base, offset) {+export function runPorts(base, offset, { lockedCloud = false } = {}) {return {ingress: base,agentServer: base + 1,automation: base + 2,frontend: base + 3,+ ...(lockedCloud ? { lockedCloud: base + 4 } : {}),...(offset === null ? {} : { vscode: base + 1 + offset }),};}+/**+ * The Cloud host a `launch --lock-to-cloud` page is locked to: an http(s)+ * origin, as `scripts/static-server.mjs --lock-to-cloud` takes it.+ * @returns {string} the origin, without a trailing slash+ */+export function lockedCloudOrigin(value) {+ let url;+ try {+ url = new URL(String(value));+ } catch {+ throw new Error(+ `--lock-to-cloud needs a Cloud URL, got ${JSON.stringify(value)}`,+ );+ }+ if (!["http:", "https:"].includes(url.protocol))+ throw new Error(+ `--lock-to-cloud needs an http(s) URL, got ${url.protocol}`,+ );+ return url.origin;+}+/*** A restarted run's ports. The block never moves, but the checkout may have* changed since launch, so the editor port follows the launcher's new answer@@ -147,7 +171,9 @@ export function portsAfterRestart(previous, editor) {ports: previous,warning: `Could not ask scripts/dev-with-automation.mjs whether it serves VS Code (${editor.reason}); keeping this run's ports.`,};- const ports = runPorts(previous.ingress, editor.offset);+ const ports = runPorts(previous.ingress, editor.offset, {+ lockedCloud: previous.lockedCloud !== undefined,+ });if (ports.vscode === previous.vscode) return { ports };if (ports.vscode === undefined)return {diff --git a/.pr/verify-launch-flags/launch-lock-to-cloud.png b/.pr/verify-launch-flags/launch-lock-to-cloud.pngnew file mode 100644index 0000000000..0d1a6140f0Binary files /dev/null and b/.pr/verify-launch-flags/launch-lock-to-cloud.png differdiff --git a/.pr/verify-launch-flags/launch-mars-web.png b/.pr/verify-launch-flags/launch-mars-web.pngnew file mode 100644index 0000000000..da320d5968Binary files /dev/null and b/.pr/verify-launch-flags/launch-mars-web.png differ