Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e617b42
fix(cli): report the dashboard bind a sandbox was created with
Dongni-Yang Sep 3, 2026
8602f34
fix(cli): record the bind the forward was started with
Dongni-Yang Sep 3, 2026
7a8ebd1
merge: resolve conflicts with main
github-actions[bot] Sep 3, 2026
07b5d38
fix(cli): record the dashboard bind at every forward launch
Dongni-Yang Sep 8, 2026
0376480
fix(cli): print a usable dashboard URL and record the reused-sandbox …
Dongni-Yang Sep 8, 2026
999a7a2
fix(cli): never start an undisclosed wide dashboard forward
Dongni-Yang Sep 8, 2026
f99b1c9
fix(cli): start a dashboard forward only when its record will describ…
Dongni-Yang Sep 8, 2026
5f585dd
fix(onboard): put the bind record back when a reused forward does not…
Dongni-Yang Sep 8, 2026
d7e0309
fix(onboard): record a bind before every launch that changes exposure…
Dongni-Yang Sep 8, 2026
bafb6ca
fix(onboard): clear or restore a recorded bind whose forward never st…
Dongni-Yang Sep 8, 2026
c829cdf
Merge upstream/main into fix/10861-report-actual-dashboard-bind
Dongni-Yang Sep 8, 2026
54e6f60
test(onboard): register the reuse harness's registry write
Dongni-Yang Sep 8, 2026
fdb1cce
docs(dashboard): state the host forward bind a remote CHAT_UI_URL cre…
Dongni-Yang Sep 9, 2026
fe4625f
docs(hermes): use the literal CLI name on the single-variant quicksta…
Dongni-Yang Sep 9, 2026
57f0591
Merge remote-tracking branch 'upstream/main' into fix/10861-report-ac…
Dongni-Yang Sep 9, 2026
01907ea
docs(dashboard): describe the recovery bind rule and what status repo…
Dongni-Yang Sep 9, 2026
47057b8
fix(dashboard): record the bind where the forward starts (#10861)
Dongni-Yang Sep 9, 2026
86de168
docs(dashboard): make Run Sandboxes the owner of the CHAT_UI_URL guid…
Dongni-Yang Sep 9, 2026
9de4014
Merge upstream/main into fix/10861-report-actual-dashboard-bind
Dongni-Yang Sep 10, 2026
894aaa5
fix(dashboard): record the bind only for the dashboard forward (#10861)
Dongni-Yang Sep 10, 2026
a11f5fe
docs(dashboard): describe the bind under the explicit remote-bind opt…
Dongni-Yang Sep 10, 2026
b21bd41
docs(dashboard): describe the bind record under the opt-in rule in co…
Dongni-Yang Sep 10, 2026
b821212
merge: reconcile dashboard bind reporting with main
rsliter Sep 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions src/lib/actions/sandbox/forward-recovery-dashboard-bind-record.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { beforeEach, describe, expect, it, vi } from "vitest";

const mocks = vi.hoisted(() => ({
captureOpenshell: vi.fn(),
runOpenshell: vi.fn((_args: string[], _options?: unknown) => ({ status: 0 })),
getSandbox: vi.fn(),
updateSandbox: vi.fn(() => true),
isLocalForwardReachable: vi.fn(() => false),
launchForwardService: vi.fn(),
}));

vi.mock("../../adapters/openshell/forward-service", async (importOriginal) => ({
...(await importOriginal<typeof import("../../adapters/openshell/forward-service")>()),
launchForwardService: mocks.launchForwardService,
}));
vi.mock("../../adapters/openshell/resolve", () => ({
resolveOpenshell: () => "/usr/local/bin/openshell",
}));
vi.mock("../../adapters/openshell/runtime", () => ({
captureOpenshell: mocks.captureOpenshell,
runOpenshell: mocks.runOpenshell,
isCommandTimeout: () => false,
}));
vi.mock("../../agent/runtime", () => ({
getSessionAgent: () => ({ forward_ports: [18789], forwardPort: 18789 }),
hasGatewayRuntime: () => true,
}));
vi.mock("../../state/registry", () => ({
getSandbox: mocks.getSandbox,
updateSandbox: mocks.updateSandbox,
}));
vi.mock("./hermes-dashboard-recovery", () => ({
getHermesDashboardRecoveryConfig: () => null,
ensureHermesDashboardPortForwardIfEnabled: vi.fn(() => null),
}));
vi.mock("./forward-health", async (importOriginal) => ({
...(await importOriginal<typeof import("./forward-health")>()),
isLocalForwardReachable: mocks.isLocalForwardReachable,
}));

import { ensureSandboxPortForward, ensureSandboxPortForwardForPort } from "./forward-recovery";

const SANDBOX = { name: "hm", agent: "hermes", dashboardPort: 18789 };

beforeEach(() => {
vi.clearAllMocks();
vi.unstubAllEnvs();
mocks.runOpenshell.mockReturnValue({ status: 0 });
// An empty forward list for the legacy-migration probe that runs before a
// launch; `clearAllMocks` keeps return values, so set it for every test.
mocks.captureOpenshell.mockReturnValue({ status: 0, output: "SANDBOX BIND PORT PID STATUS" });
mocks.updateSandbox.mockReturnValue(true);
mocks.getSandbox.mockReturnValue(SANDBOX);
// Not reachable until the launch runs, so every test below exercises the
// path that actually creates a forward.
mocks.isLocalForwardReachable.mockReturnValue(false);
mocks.launchForwardService.mockImplementation(() => {
mocks.isLocalForwardReachable.mockReturnValue(true);
});
});

describe("the recorded dashboard bind follows the forward (#10861)", () => {
it("records the loopback bind when recovery re-creates the forward without an opt-in", () => {
expect(ensureSandboxPortForward("hm", { isWsl: false })).toBe(true);

expect(mocks.launchForwardService).toHaveBeenCalledOnce();
expect(mocks.updateSandbox).toHaveBeenCalledWith("hm", { dashboardBindAddress: "127.0.0.1" });
});

it("records the wide bind when the operator opted in and the sandbox was prepared for it", () => {
vi.stubEnv("NEMOCLAW_DASHBOARD_BIND", "0.0.0.0");
mocks.getSandbox.mockReturnValue({ ...SANDBOX, dashboardRemoteBindPrepared: true });

expect(ensureSandboxPortForward("hm", { isWsl: false })).toBe(true);

expect(mocks.updateSandbox).toHaveBeenCalledWith("hm", { dashboardBindAddress: "0.0.0.0" });
});

it("leaves the record alone when the forward is already reachable", () => {
mocks.isLocalForwardReachable.mockReturnValue(true);

expect(ensureSandboxPortForward("hm", { isWsl: false })).toBe(true);

expect(mocks.launchForwardService).not.toHaveBeenCalled();
expect(mocks.updateSandbox).not.toHaveBeenCalled();
});

it("does not record a bind for a forward that is not the dashboard's", () => {
expect(ensureSandboxPortForwardForPort("hm", 8642, { expectedBind: "127.0.0.1" })).toBe(true);

expect(mocks.launchForwardService).toHaveBeenCalledOnce();
expect(mocks.updateSandbox).not.toHaveBeenCalled();
});

it("keeps the forward up and warns when the record cannot be written", () => {
const stderr = vi.spyOn(console, "error").mockImplementation(() => undefined);
mocks.updateSandbox.mockReturnValue(false);

expect(ensureSandboxPortForward("hm", { isWsl: false })).toBe(true);

expect(stderr).toHaveBeenCalledWith(expect.stringContaining("could not be recorded"));
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it("keeps the forward up and warns when recording the bind throws", () => {
const stderr = vi.spyOn(console, "error").mockImplementation(() => undefined);
mocks.updateSandbox.mockImplementation(() => {
throw new Error("disk full");
});

expect(ensureSandboxPortForward("hm", { isWsl: false })).toBe(true);

expect(stderr).toHaveBeenCalledWith(expect.stringContaining("recording it for 'hm' failed"));
});
});
39 changes: 32 additions & 7 deletions src/lib/actions/sandbox/forward-recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export function ensureSandboxPortForward(
return ensureSandboxPortForwardForPort(sandboxName, port, {
forwardTarget: allInterfaceBindRequired ? `0.0.0.0:${port}` : String(port),
expectedBind: allInterfaceBindRequired ? "0.0.0.0" : "127.0.0.1",
recordDashboardBind: true,
afterSuccess: options.afterSuccess,
beforeStart: () =>
(!remoteBindRequested ||
Expand Down Expand Up @@ -352,6 +353,20 @@ export function isSandboxPortForwardHealthy(
return true;
}

/** Persist the bind a dashboard forward was just started with; a failed write must not fail the forward. */
function recordDashboardBindAddress(sandboxName: string, port: number, bindAddress: string): void {
try {
if (registry.updateSandbox(sandboxName, { dashboardBindAddress: bindAddress })) return;
console.error(
` Warning: the dashboard forward for port ${String(port)} is bound on ${bindAddress}, but that could not be recorded for '${sandboxName}'; \`dashboard-url\` may report a stale address until the next onboard.`,
);
} catch (error) {
console.error(
` Warning: the dashboard forward for port ${String(port)} is bound on ${bindAddress}, but recording it for '${sandboxName}' failed: ${error instanceof Error ? error.message : String(error)}`,
);
}
}

export function ensureSandboxPortForwardForPort(
sandboxName: string,
port: number,
Expand All @@ -360,14 +375,23 @@ export function ensureSandboxPortForwardForPort(
forwardTarget?: string;
expectedBind?: string;
beforeStart?: () => boolean;
/**
* Record the bind this call establishes as the sandbox's dashboard bind.
* Only the dashboard caller sets this; messaging and declared-port
* forwards share this function and must not overwrite that field.
*/
recordDashboardBind?: boolean;
} = {},
): boolean {
const {
afterSuccess = () => true,
forwardTarget = String(port),
expectedBind,
beforeStart = () => true,
recordDashboardBind = false,
} = options;
const bindAddress =
expectedBind ?? (forwardTarget.startsWith("0.0.0.0:") ? "0.0.0.0" : "127.0.0.1");
const acceptSuccessfulForward = () => {
let accepted = false;
try {
Expand All @@ -388,14 +412,15 @@ export function ensureSandboxPortForwardForPort(
const executable = resolveOpenshell();
if (!executable) throw new Error("OpenShell is unavailable");
launchForwardService(
forwardServiceTarget(
executable,
gatewayName,
sandboxName,
port,
expectedBind ?? (forwardTarget.startsWith("0.0.0.0:") ? "0.0.0.0" : "127.0.0.1"),
),
forwardServiceTarget(executable, gatewayName, sandboxName, port, bindAddress),
);
// The record follows the forward, not the sandbox. Onboarding writes it
// when it starts the first forward; every later re-creation — restart,
// connect, gateway recovery — decides the bind again from the current
// environment, and a record left from onboarding would report the bind
// that used to be true (#10861). Only a launch writes: on the healthy
// path above nothing was created, and the listener may not be ours.
if (recordDashboardBind) recordDashboardBindAddress(sandboxName, port, bindAddress);
return acceptSuccessfulForward();
} catch (error) {
console.error(
Expand Down
19 changes: 19 additions & 0 deletions src/lib/actions/sandbox/status-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,11 @@ describe("showSandboxStatus flow", () => {
chatUiUrl: "",
sandboxEntry: { dashboardRemoteBindPrepared: true },
},
{
caseLabel: "a recorded wide bind (#10861)",
chatUiUrl: "",
sandboxEntry: { dashboardBindAddress: "0.0.0.0" },
},
])("omits port forward guidance for $caseLabel (#8465)", async ({ chatUiUrl, sandboxEntry }) => {
vi.stubEnv("SSH_CONNECTION", "203.0.113.9 51000 198.51.100.2 22");
vi.stubEnv("CHAT_UI_URL", chatUiUrl);
Expand All @@ -844,6 +849,20 @@ describe("showSandboxStatus flow", () => {
expect(output).not.toContain("Remote access: run");
});

it("keeps the port forward guidance when the recorded bind is loopback despite a prepared remote bind (#10861)", async () => {
vi.stubEnv("SSH_CONNECTION", "203.0.113.9 51000 198.51.100.2 22");
vi.stubEnv("CHAT_UI_URL", "");
const harness = createStatusFlowHarness({
gatewayRunning: true,
sandboxEntry: { dashboardRemoteBindPrepared: true, dashboardBindAddress: "127.0.0.1" },
});

await expect(harness.showSandboxStatus("alpha")).resolves.toBeUndefined();

const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n");
expect(output).toContain("Remote access: run");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
});

it("omits dashboard guidance over SSH when the gateway is stopped (#8465)", async () => {
vi.stubEnv("SSH_CONNECTION", "203.0.113.9 51000 198.51.100.2 22");
const harness = createStatusFlowHarness({ gatewayRunning: false });
Expand Down
13 changes: 10 additions & 3 deletions src/lib/actions/sandbox/status-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,16 @@ function printDashboardRemoteAccessHint(context: SandboxStatusTextContext): void
const { sandboxName, sb } = context;
const dashboardPort = sb?.dashboardPort;
if (!dashboardPort) return;
const accessUrl = sb?.dashboardRemoteBindPrepared
? `http://0.0.0.0:${dashboardPort}`
: process.env.CHAT_UI_URL;
// The recorded bind is the only durable answer: CHAT_UI_URL decided it at
// onboard time and later commands rarely carry it, so reading the live
// environment reports a loopback bind for a sandbox exposed on every
// interface (#10861). Rows written before that field fall back as before.
const recordedBindAddress = sb?.dashboardBindAddress;
const accessUrl = recordedBindAddress
? `http://${recordedBindAddress}:${dashboardPort}`
: sb?.dashboardRemoteBindPrepared
? `http://0.0.0.0:${dashboardPort}`
: process.env.CHAT_UI_URL;
if (!buildSshForwardHintLines({ port: dashboardPort, accessUrl })) return;
console.log(
` Remote access: run \`${CLI_NAME} ${shellQuote(sandboxName)} dashboard-url\` for SSH port forward instructions.`,
Expand Down
120 changes: 120 additions & 0 deletions src/lib/dashboard-url-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,126 @@ describe("dashboard-url command helpers", () => {
expect(sinks.out).toEqual(["http://172.22.1.1:19000/#token=secret-token"]);
});

it("keeps the URL usable and discloses a recorded wide bind instead of printing 0.0.0.0 (#10861)", () => {
const sinks = makeSinks();

runDashboardUrlCommand(
"alpha",
{ quiet: false },
{
fetchToken: () => "secret-token",
getSandbox: () => ({
agent: "openclaw",
dashboardPort: 19000,
dashboardBindAddress: "0.0.0.0",
}),
getAccessUrl: () => "http://127.0.0.1:19000",
env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" },
log: sinks.log,
error: sinks.error,
},
);

expect(sinks.out).toEqual([
" Dashboard URL:",
" http://127.0.0.1:19000/#token=secret-token",
" Bound on all interfaces (0.0.0.0:19000): reachable from other hosts at this host's address.",
]);
});

it("discloses a recorded wide bind in the session-auth branch too (#10861)", () => {
const sinks = makeSinks();

runDashboardUrlCommand(
"alpha",
{ quiet: false },
{
fetchToken: () => "secret-token",
getSandbox: () => ({
agent: "hermes",
dashboardPort: 18790,
dashboardBindAddress: "0.0.0.0",
}),
getAgentDashboardAuth: () => "session",
getAccessUrl: () => "http://127.0.0.1:18790",
env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" },
log: sinks.log,
error: sinks.error,
},
);

expect(sinks.out).toEqual([
" Dashboard URL:",
" http://127.0.0.1:18790/",
" Bound on all interfaces (0.0.0.0:18790): reachable from other hosts at this host's address.",
]);
});

it("keeps the SSH forward hint for a recorded loopback bind (#10861)", () => {
const sinks = makeSinks();

runDashboardUrlCommand(
"alpha",
{ quiet: false },
{
fetchToken: () => "secret-token",
getSandbox: () => ({
agent: "openclaw",
dashboardPort: 19000,
dashboardBindAddress: "127.0.0.1",
}),
getAccessUrl: () => "http://127.0.0.1:19000",
env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" },
log: sinks.log,
error: sinks.error,
},
);

expect(sinks.out).toContain(" ssh -L 19000:127.0.0.1:19000 spark@<host>");
expect(sinks.out.join("\n")).not.toContain("Bound on all interfaces");
});

it("prints only the usable URL in quiet mode for a recorded wide bind (#10861)", () => {
const sinks = makeSinks();

runDashboardUrlCommand(
"alpha",
{ quiet: true },
{
fetchToken: () => "secret-token",
getSandbox: () => ({
agent: "openclaw",
dashboardPort: 19000,
dashboardBindAddress: "0.0.0.0",
}),
getAccessUrl: () => "http://127.0.0.1:19000",
env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" },
log: sinks.log,
error: sinks.error,
},
);

expect(sinks.out).toEqual(["http://127.0.0.1:19000/#token=secret-token"]);
});

it("keeps the recomputed access URL for a row with no recorded bind", () => {
const sinks = makeSinks();

runDashboardUrlCommand(
"alpha",
{ quiet: true },
{
fetchToken: () => "secret-token",
getSandbox: () => ({ agent: "openclaw", dashboardPort: 19000 }),
getAccessUrl: () => "http://172.22.1.1:19000",
log: sinks.log,
error: sinks.error,
},
);

expect(sinks.out).toEqual(["http://172.22.1.1:19000/#token=secret-token"]);
});

it("prints a human label and warning outside quiet mode", () => {
const sinks = makeSinks();
runDashboardUrlCommand(
Expand Down
Loading