From c1c6a05e63e07ee20de9329d0b30bf471c6420c1 Mon Sep 17 00:00:00 2001 From: harjoth Date: Tue, 14 Jul 2026 19:30:46 -0700 Subject: [PATCH 1/2] fix(inference): converge Hermes Dashboard profile on inference set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `nemoclaw inference set` for a Hermes sandbox updated the main config and reported "Inference route synced", but the Web Dashboard runs from an isolated HERMES_HOME under /sandbox/.hermes/dashboard-home that is only seeded at container startup. An in-place switch therefore left Dashboard Chat and its /api/model/info endpoint on the previous model while every other status surface reported the new one. After the main in-sandbox config syncs, converge the Dashboard profile onto the switched model by running `hermes config set model.default` and `providers..default_model` under the Dashboard HERMES_HOME — mirroring the reporter-verified recovery. The step is best-effort and gated: an absent Dashboard profile (Dashboard disabled) is a no-op, and a convergence failure prints a warning and withholds the success line so `inference set` does not claim a route it did not fully apply. Verified with a red-green unit test at the sandbox-exec dep boundary; live end-to-end (running Hermes + Dashboard + vLLM) was not exercised. Fixes #6893 Co-Authored-By: Claude Fable 5 Signed-off-by: harjoth --- docs/reference/troubleshooting.mdx | 17 ++++ .../actions/inference-set-gateway-restart.ts | 12 ++- .../actions/inference-set-hermes-run.test.ts | 85 +++++++++++++++++++ src/lib/actions/inference-set.test-support.ts | 6 ++ src/lib/actions/inference-set.ts | 40 +++++++++ src/lib/sandbox/config.ts | 66 ++++++++++++++ 6 files changed, 225 insertions(+), 1 deletion(-) diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index 9c7387d47ca..a3d51ea5d26 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -2598,6 +2598,23 @@ The Hermes entrypoint supervisor remains responsible for the gateway, dashboard, In the OpenShell-managed topology, that nonroot supervisor repairs failed auxiliaries continuously, recovers a gateway after four consecutive failed listener or HTTP health checks, and quarantines relaunch after five exits within 60 seconds until the sandbox is recreated. The host only repairs the host-side OpenShell forwards after the supervised processes pass health checks. +### Dashboard Chat keeps serving the previous model after a model switch + +The Hermes Web Dashboard runs from an isolated profile under `/sandbox/.hermes/dashboard-home/`, seeded at container startup and kept separate from the main Hermes config. +`nemohermes inference set` converges this Dashboard profile onto the new model along with the main config, so Dashboard Chat and its `/api/model/info` endpoint report the switched model. +If the Dashboard profile is absent because the Dashboard is disabled, the convergence is a no-op. + +When convergence fails, `inference set` prints a warning, withholds the `Inference route synced` success line, and Dashboard Chat may keep using the previous model. +Re-run the switch or restart the gateway to converge the Dashboard profile: + +```bash +nemohermes inference set --provider --model --sandbox +``` + +```bash +nemohermes hermes gateway restart +``` + ### Port 8642 in a browser shows a blank page or `Cannot GET /` `nemohermes onboard` forwards port `8642`, but Hermes serves an OpenAI-compatible API at that port, not a chat dashboard. diff --git a/src/lib/actions/inference-set-gateway-restart.ts b/src/lib/actions/inference-set-gateway-restart.ts index a7e56632172..cfe0046ea31 100644 --- a/src/lib/actions/inference-set-gateway-restart.ts +++ b/src/lib/actions/inference-set-gateway-restart.ts @@ -20,6 +20,13 @@ interface InferenceResultForGateway { model: string; primaryModelRef: string; inSandboxConfigSynced: boolean; + /** + * Hermes only: whether the isolated Web Dashboard profile converged onto the + * switched model (#6893). Undefined for agents without a Dashboard profile, + * treated as converged. When explicitly false the success line is withheld so + * `inference set` does not claim a route it did not fully apply. + */ + dashboardConverged?: boolean; } export interface InferenceMutation { @@ -101,7 +108,10 @@ export function finalizeInferenceMutation( deps.appendAuditEntry(auditEntry); } - if (result.inSandboxConfigSynced && !openClawGatewayRestartRequired) { + // A Hermes switch whose Web Dashboard profile did not converge is not fully + // applied, so withhold the success line (the caller already warned) (#6893). + const hermesDashboardStale = agentName === "hermes" && result.dashboardConverged === false; + if (result.inSandboxConfigSynced && !openClawGatewayRestartRequired && !hermesDashboardStale) { deps.log( agentName === "hermes" ? ` Inference route synced for '${result.sandboxName}': ${result.model}` diff --git a/src/lib/actions/inference-set-hermes-run.test.ts b/src/lib/actions/inference-set-hermes-run.test.ts index 4d19276c136..5d5363c46d0 100644 --- a/src/lib/actions/inference-set-hermes-run.test.ts +++ b/src/lib/actions/inference-set-hermes-run.test.ts @@ -380,3 +380,88 @@ describe("runInferenceSet Hermes routing", () => { expect(deps.calls.writeSandboxConfig).not.toHaveBeenCalled(); }); }); + +describe("runInferenceSet Hermes Web Dashboard convergence (#6893)", () => { + function hermesDeps( + overrides: Partial[0]> = {}, + ): ReturnType { + return createDeps({ + config: { + model: { default: "old-model", provider: "custom", base_url: "https://inference.local/v1" }, + }, + entry: { name: "hermes", agent: "hermes", provider: "vllm-local", model: "old-model" }, + defaultSandbox: "hermes", + target: HERMES_TARGET, + session: baseSession({ agent: "hermes", sandboxName: "hermes" }), + ...overrides, + }); + } + + const syncedLine = (deps: ReturnType): boolean => + deps.calls.log.mock.calls.some((c) => String(c[0]).includes("Inference route synced")); + + it("converges the isolated Dashboard profile after a successful switch", async () => { + const deps = hermesDeps(); + + const result = await runInferenceSet( + { provider: "vllm-local", model: "nemotron-ultra", sandboxName: "hermes", noVerify: true }, + deps, + ); + + // The regression on main: this call never happens, so Dashboard Chat stays + // on the previous model while every other surface reports the new one. + expect(deps.calls.convergeHermesDashboardModel).toHaveBeenCalledWith( + "hermes", + "/sandbox/.hermes", + "vllm-local", + "nemotron-ultra", + ); + expect(result.dashboardConverged).toBe(true); + expect(syncedLine(deps)).toBe(true); + }); + + it("still reports synced when no Dashboard profile is present", async () => { + const deps = hermesDeps({ dashboardConverge: { status: "absent" } }); + + const result = await runInferenceSet( + { provider: "vllm-local", model: "nemotron-ultra", sandboxName: "hermes", noVerify: true }, + deps, + ); + + expect(deps.calls.convergeHermesDashboardModel).toHaveBeenCalledTimes(1); + expect(result.dashboardConverged).toBe(true); + expect(syncedLine(deps)).toBe(true); + }); + + it("withholds the success line and warns when Dashboard convergence fails", async () => { + const deps = hermesDeps({ + dashboardConverge: { status: "failed", detail: "exec exited 1" }, + }); + + const result = await runInferenceSet( + { provider: "vllm-local", model: "nemotron-ultra", sandboxName: "hermes", noVerify: true }, + deps, + ); + + expect(result.dashboardConverged).toBe(false); + expect(syncedLine(deps)).toBe(false); + expect( + deps.calls.log.mock.calls.some((c) => String(c[0]).includes("did not converge onto")), + ).toBe(true); + }); + + it("does not touch the Dashboard path for OpenClaw switches", async () => { + const deps = createDeps({ + config: { models: { mode: "merge", providers: {} } }, + entry: { name: "alpha", agent: "openclaw", provider: "nvidia-prod", model: "old" }, + defaultSandbox: "alpha", + }); + + await runInferenceSet( + { provider: "nvidia-prod", model: "nvidia/nemotron-3-super-v3", sandboxName: "alpha" }, + deps, + ); + + expect(deps.calls.convergeHermesDashboardModel).not.toHaveBeenCalled(); + }); +}); diff --git a/src/lib/actions/inference-set.test-support.ts b/src/lib/actions/inference-set.test-support.ts index 6e19b36d265..9a3a60595f5 100644 --- a/src/lib/actions/inference-set.test-support.ts +++ b/src/lib/actions/inference-set.test-support.ts @@ -83,6 +83,7 @@ export function createDeps(options: { localReachable?: boolean; contextWindow?: number | null; shieldsMutable?: boolean; + dashboardConverge?: ReturnType; prepareRunOpenshell?: () => void; rewriteConfigUrlsWithDnsPinning?: (value: ConfigValue) => Promise; restartSandboxGateway?: InferenceSetDeps["restartSandboxGateway"]; @@ -92,6 +93,7 @@ export function createDeps(options: { captureOpenshell: ReturnType; writeSandboxConfig: ReturnType; recomputeSandboxConfigHash: ReturnType; + convergeHermesDashboardModel: ReturnType; updateSandbox: ReturnType; readSandboxConfig: ReturnType; updateSession: ReturnType; @@ -124,6 +126,9 @@ export function createDeps(options: { })), writeSandboxConfig: vi.fn(), recomputeSandboxConfigHash: vi.fn(), + convergeHermesDashboardModel: vi.fn( + () => options.dashboardConverge ?? { status: "converged" as const }, + ), updateSandbox: vi.fn(() => true), readSandboxConfig: vi.fn(() => options.config), updateSession: vi.fn((mutator: (value: Session) => Session | void) => { @@ -169,6 +174,7 @@ export function createDeps(options: { readSandboxConfig: calls.readSandboxConfig, writeSandboxConfig: calls.writeSandboxConfig, recomputeSandboxConfigHash: calls.recomputeSandboxConfigHash, + convergeHermesDashboardModel: calls.convergeHermesDashboardModel, prepareRunOpenshell: calls.prepareRunOpenshell, captureOpenshell: calls.captureOpenshell, appendAuditEntry: calls.appendAuditEntry, diff --git a/src/lib/actions/inference-set.ts b/src/lib/actions/inference-set.ts index c0eb2886569..7be548dff11 100644 --- a/src/lib/actions/inference-set.ts +++ b/src/lib/actions/inference-set.ts @@ -29,6 +29,8 @@ import { } from "../openshell-gateway-endpoint-guard"; import { type AgentConfigTarget, + convergeHermesDashboardModel, + type HermesDashboardConvergeResult, readSandboxConfig, recomputeSandboxConfigHash, resolveAgentConfig, @@ -90,6 +92,7 @@ export interface InferenceSetResult { configChanged: boolean; sessionUpdated: boolean; inSandboxConfigSynced: boolean; + dashboardConverged: boolean; } export interface InferenceSetDeps extends InferenceGatewayRestartDeps { @@ -110,6 +113,12 @@ export interface InferenceSetDeps extends InferenceGatewayRestartDeps { config: ConfigObject, ) => void; recomputeSandboxConfigHash: (sandboxName: string, target: AgentConfigTarget) => void; + convergeHermesDashboardModel: ( + sandboxName: string, + configDir: string, + provider: string, + model: string, + ) => HermesDashboardConvergeResult; prepareRunOpenshell: () => void; captureOpenshell: ( args: string[], @@ -212,6 +221,7 @@ function defaultDeps(): InferenceSetDeps { readSandboxConfig, writeSandboxConfig, recomputeSandboxConfigHash, + convergeHermesDashboardModel, prepareRunOpenshell: () => { getOpenshellBinary(); }, @@ -866,6 +876,35 @@ async function runInferenceSetWithoutHostLock( ` Run '${CLI_NAME} ${sandboxName} rebuild' to finish applying the model inside the sandbox.`, ); } + + // #6893: the Hermes Web Dashboard runs from an isolated HERMES_HOME and does + // not pick up an in-place model switch, so Dashboard Chat keeps serving the + // previous model even though every other status surface reports the new one. + // Converge that profile too before claiming success. Best-effort and gated on + // the main config having synced first: a Dashboard that was never enabled + // resolves to "absent" (no-op), and only a real convergence failure downgrades + // the success message. + let dashboardConverged = true; + if (agentName === "hermes" && inSandboxConfigSynced) { + const dashboardResult = deps.convergeHermesDashboardModel( + sandboxName, + target.configDir, + provider, + model, + ); + if (dashboardResult.status === "failed") { + dashboardConverged = false; + deps.log( + ` Warning: updated the Hermes config for '${sandboxName}', but the Web Dashboard ` + + `profile did not converge onto '${model}': ${dashboardResult.detail}`, + ); + deps.log( + ` Dashboard Chat may keep using the previous model. Re-run '${CLI_NAME} inference set' ` + + `or run '${CLI_NAME} ${sandboxName} hermes gateway restart'.`, + ); + } + } + const sessionUpdated = updateMatchingOnboardSession( sandboxName, provider, @@ -890,6 +929,7 @@ async function runInferenceSetWithoutHostLock( configChanged: patched.changed, sessionUpdated, inSandboxConfigSynced, + dashboardConverged, }, }, deps, diff --git a/src/lib/sandbox/config.ts b/src/lib/sandbox/config.ts index 0f96b1cdebd..e6f585487b8 100644 --- a/src/lib/sandbox/config.ts +++ b/src/lib/sandbox/config.ts @@ -163,6 +163,12 @@ const HERMES_STRICT_HASH_FILE = "/etc/nemoclaw/hermes.config-hash"; const HERMES_RUNTIME_CONFIG_GUARD = "/usr/local/lib/nemoclaw/hermes-runtime-config-guard.py"; const HERMES_PYTHON = "/opt/hermes/.venv/bin/python"; const HERMES_RESTART_SEAL_STATE = "/run/nemoclaw/hermes-restart-seal.json"; +// The Hermes Web Dashboard runs from an isolated HERMES_HOME under this subdir of +// the main config dir, seeded at container startup. An in-place `inference set` +// updates only the main config, so the Dashboard profile must be converged +// separately (#6893). +const HERMES_DASHBOARD_HOME_SUBDIR = "dashboard-home"; +const HERMES_DASHBOARD_CONVERGE_TIMEOUT_MS = 30_000; const MAX_OPENCLAW_CONFIG_BYTES = 16 * 1024 * 1024; const CONFIG_CAPTURE_MAX_BUFFER = MAX_OPENCLAW_CONFIG_BYTES + 1024 * 1024; const OPENCLAW_CONFIG_GUARD_TIMEOUT_MS = 6 * 60 * 1000; @@ -574,6 +580,65 @@ function writeSandboxConfig( } } +export type HermesDashboardConvergeResult = + | { status: "converged" } + | { status: "absent" } + | { status: "failed"; detail: string }; + +/** + * Converge the isolated Hermes Web Dashboard profile onto a switched model. + * + * `nemoclaw inference set` writes only the main Hermes config; the Dashboard runs + * from a separate HERMES_HOME under `/dashboard-home`, seeded at + * container startup. An in-place switch therefore leaves Dashboard Chat and its + * `/api/model/info` endpoint on the previous model (#6893). This mirrors the + * reporter-verified recovery — `hermes config set model.default` and + * `providers..default_model` under the Dashboard HERMES_HOME — and + * no-ops when the Dashboard profile is absent (Dashboard disabled). + * + * `provider` and `model` are pre-validated by the `inference set` caller + * (`assertSupportedProvider` allowlist + `isSafeModelId`), so they are safe as a + * config dotpath segment and value; they are still passed as distinct argv + * elements, never interpolated into a shell string. + */ +function convergeHermesDashboardModel( + sandboxName: string, + configDir: string, + provider: string, + model: string, +): HermesDashboardConvergeResult { + const dashboardHome = `${configDir.replace(/\/+$/, "")}/${HERMES_DASHBOARD_HOME_SUBDIR}`; + try { + // Probe via an always-exit-0 shell so an absent profile is a clean "skip" + // rather than an exec that throws and reads as a failure. + const probe = privilegedSandboxExec( + sandboxName, + [ + "sh", + "-c", + `if [ -d ${shellQuote(dashboardHome)} ]; then echo present; else echo absent; fi`, + ], + { timeout: HERMES_DASHBOARD_CONVERGE_TIMEOUT_MS }, + ); + if (!probe.trim().endsWith("present")) { + return { status: "absent" }; + } + for (const key of ["model.default", `providers.${provider}.default_model`]) { + privilegedSandboxExec( + sandboxName, + ["env", `HERMES_HOME=${dashboardHome}`, "hermes", "config", "set", key, model], + { timeout: HERMES_DASHBOARD_CONVERGE_TIMEOUT_MS }, + ); + } + return { status: "converged" }; + } catch (error) { + return { + status: "failed", + detail: error instanceof Error && error.message ? error.message : String(error), + }; + } +} + function buildRecomputeSandboxConfigHashScript(target: AgentConfigTarget): string | null { // OpenClaw and Hermes write and refresh both hashes inside one fd-pinned sealed // transaction. A second pathname-based hash pass would reopen the race that @@ -1212,6 +1277,7 @@ export { configGet, configRotateToken, configSet, + convergeHermesDashboardModel, DEFAULT_AGENT_CONFIG, extractDotpath, findClobberingAncestor, From d9667b1dc0e777a9bd4fee2e14b7a7cd9510243d Mon Sep 17 00:00:00 2001 From: harjoth Date: Tue, 14 Jul 2026 20:13:50 -0700 Subject: [PATCH 2/2] refactor(inference): address review on Hermes dashboard convergence Respond to CodeRabbit review on #6897: - Use a pure-argv `test -d` presence probe via dockerSpawnSync instead of an `sh -c` string, matching the argv-over-shell convention for this security-boundary file. A non-0/1 status (e.g. Docker's 125) or a spawn error is now classified as a convergence failure rather than a silent skip. - Report result.dashboardConverged as boolean | undefined: undefined when convergence was not attempted (non-Hermes agent, or the main config never synced), so the result never claims a Dashboard state it did not establish. - Add direct unit tests for convergeHermesDashboardModel covering the absent / converged / probe-failure / spawn-error / write-failure paths, asserting the exact argv (provider and model as discrete elements, never shell-interpolated) and that failures carry only the underlying message. Co-Authored-By: Claude Fable 5 Signed-off-by: harjoth --- src/lib/actions/inference-set.ts | 15 +- src/lib/sandbox/config.ts | 29 ++-- .../sandbox/hermes-dashboard-converge.test.ts | 140 ++++++++++++++++++ 3 files changed, 167 insertions(+), 17 deletions(-) create mode 100644 src/lib/sandbox/hermes-dashboard-converge.test.ts diff --git a/src/lib/actions/inference-set.ts b/src/lib/actions/inference-set.ts index 7be548dff11..ba023f11a04 100644 --- a/src/lib/actions/inference-set.ts +++ b/src/lib/actions/inference-set.ts @@ -92,7 +92,12 @@ export interface InferenceSetResult { configChanged: boolean; sessionUpdated: boolean; inSandboxConfigSynced: boolean; - dashboardConverged: boolean; + /** + * Hermes only: whether the isolated Web Dashboard profile converged onto the + * switched model (#6893). Undefined when convergence was not attempted — a + * non-Hermes agent, or a Hermes switch whose main config never synced. + */ + dashboardConverged?: boolean; } export interface InferenceSetDeps extends InferenceGatewayRestartDeps { @@ -884,7 +889,11 @@ async function runInferenceSetWithoutHostLock( // the main config having synced first: a Dashboard that was never enabled // resolves to "absent" (no-op), and only a real convergence failure downgrades // the success message. - let dashboardConverged = true; + // Undefined when convergence was not attempted (non-Hermes agent, or the main + // config never synced), true when the Dashboard converged or was absent, and + // false only on a real convergence failure — so the result never claims a + // Dashboard state it did not establish. + let dashboardConverged: boolean | undefined; if (agentName === "hermes" && inSandboxConfigSynced) { const dashboardResult = deps.convergeHermesDashboardModel( sandboxName, @@ -892,8 +901,8 @@ async function runInferenceSetWithoutHostLock( provider, model, ); + dashboardConverged = dashboardResult.status !== "failed"; if (dashboardResult.status === "failed") { - dashboardConverged = false; deps.log( ` Warning: updated the Hermes config for '${sandboxName}', but the Web Dashboard ` + `profile did not converge onto '${model}': ${dashboardResult.detail}`, diff --git a/src/lib/sandbox/config.ts b/src/lib/sandbox/config.ts index e6f585487b8..f248f3e2aa2 100644 --- a/src/lib/sandbox/config.ts +++ b/src/lib/sandbox/config.ts @@ -608,21 +608,22 @@ function convergeHermesDashboardModel( model: string, ): HermesDashboardConvergeResult { const dashboardHome = `${configDir.replace(/\/+$/, "")}/${HERMES_DASHBOARD_HOME_SUBDIR}`; + // Presence probe as a pure argv `test -d` (this security-boundary file prefers + // argv over shell construction). `dockerSpawnSync` returns the exit status + // rather than throwing, so an absent profile (`test` exits 1) is a clean skip + // and only a genuine exec error (spawn failure, signal, or a non-0/1 status + // such as Docker's 125 for a missing container) is a convergence failure. + const probe = dockerSpawnSync( + privilegedSandboxExecArgv(sandboxName, ["test", "-d", dashboardHome], false, true), + { encoding: "utf-8", timeout: HERMES_DASHBOARD_CONVERGE_TIMEOUT_MS }, + ); + if (probe.error) return { status: "failed", detail: probe.error.message }; + if (probe.signal) return { status: "failed", detail: `probe terminated by ${probe.signal}` }; + if (probe.status === 1) return { status: "absent" }; + if (probe.status !== 0) { + return { status: "failed", detail: `dashboard probe exited ${String(probe.status)}` }; + } try { - // Probe via an always-exit-0 shell so an absent profile is a clean "skip" - // rather than an exec that throws and reads as a failure. - const probe = privilegedSandboxExec( - sandboxName, - [ - "sh", - "-c", - `if [ -d ${shellQuote(dashboardHome)} ]; then echo present; else echo absent; fi`, - ], - { timeout: HERMES_DASHBOARD_CONVERGE_TIMEOUT_MS }, - ); - if (!probe.trim().endsWith("present")) { - return { status: "absent" }; - } for (const key of ["model.default", `providers.${provider}.default_model`]) { privilegedSandboxExec( sandboxName, diff --git a/src/lib/sandbox/hermes-dashboard-converge.test.ts b/src/lib/sandbox/hermes-dashboard-converge.test.ts new file mode 100644 index 00000000000..c85408363fb --- /dev/null +++ b/src/lib/sandbox/hermes-dashboard-converge.test.ts @@ -0,0 +1,140 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +// Direct coverage for convergeHermesDashboardModel (#6893). This exercises the +// helper's own probe parsing, argv construction, and error classification — +// the security-boundary logic that the inference-set tests only reach through a +// mocked dependency. Both the presence probe and the model writes run through +// the real code path with only the docker-exec adapter and the argv builder +// replaced, so the assertions pin the exact argv (no shell interpolation of +// provider/model) and prove failures are classified without leaking anything +// beyond the underlying error message. + +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +const dockerExecPath = require.resolve("../adapters/docker/exec"); +const privilegedExecPath = require.resolve("./privileged-exec"); +const configModulePath = require.resolve("./config"); + +type SpawnResult = { status: number | null; signal: string | null; error?: Error }; + +const dockerExec = require(dockerExecPath) as { + dockerSpawnSync: (...args: unknown[]) => SpawnResult; + dockerExecFileSync: (...args: unknown[]) => string; +}; +const privilegedExec = require(privilegedExecPath) as { + privilegedSandboxExecArgv: (...args: unknown[]) => string[]; +}; + +const realSpawn = dockerExec.dockerSpawnSync; +const realExecFile = dockerExec.dockerExecFileSync; +const realArgv = privilegedExec.privilegedSandboxExecArgv; + +type ConvergeFn = ( + sandboxName: string, + configDir: string, + provider: string, + model: string, +) => { status: "converged" | "absent" | "failed"; detail?: string }; + +function loadConverge(): ConvergeFn { + delete require.cache[configModulePath]; + return (require(configModulePath) as { convergeHermesDashboardModel: ConvergeFn }) + .convergeHermesDashboardModel; +} + +beforeEach(() => { + // Pass the command through as the "argv" so the docker-exec spies receive the + // exact command array the helper built, without a live registry/container. + privilegedExec.privilegedSandboxExecArgv = (...args: unknown[]) => args[1] as string[]; +}); + +afterEach(() => { + dockerExec.dockerSpawnSync = realSpawn; + dockerExec.dockerExecFileSync = realExecFile; + privilegedExec.privilegedSandboxExecArgv = realArgv; + vi.restoreAllMocks(); +}); + +const DASHBOARD_HOME = "/sandbox/.hermes/dashboard-home"; + +describe("convergeHermesDashboardModel (#6893)", () => { + it("probes with a pure argv `test -d` and skips a switch when the profile is absent", () => { + const spawn = vi.fn((..._args: unknown[]) => ({ status: 1, signal: null })); + const execFile = vi.fn((..._args: unknown[]) => ""); + dockerExec.dockerSpawnSync = spawn; + dockerExec.dockerExecFileSync = execFile; + + const result = loadConverge()("hermes", "/sandbox/.hermes", "vllm-local", "nemotron-ultra"); + + expect(result).toEqual({ status: "absent" }); + expect(spawn.mock.calls[0][0]).toEqual(["test", "-d", DASHBOARD_HOME]); + expect(execFile).not.toHaveBeenCalled(); + }); + + it("converges by writing model.default and providers..default_model as argv", () => { + dockerExec.dockerSpawnSync = vi.fn((..._args: unknown[]) => ({ status: 0, signal: null })); + const execFile = vi.fn((..._args: unknown[]) => ""); + dockerExec.dockerExecFileSync = execFile; + + const result = loadConverge()("hermes", "/sandbox/.hermes/", "vllm-local", "nemotron-ultra"); + + expect(result).toEqual({ status: "converged" }); + // Provider and model are discrete argv elements under the Dashboard + // HERMES_HOME — never interpolated into a shell string. + expect(execFile.mock.calls[0][0]).toEqual([ + "env", + `HERMES_HOME=${DASHBOARD_HOME}`, + "hermes", + "config", + "set", + "model.default", + "nemotron-ultra", + ]); + expect(execFile.mock.calls[1][0]).toEqual([ + "env", + `HERMES_HOME=${DASHBOARD_HOME}`, + "hermes", + "config", + "set", + "providers.vllm-local.default_model", + "nemotron-ultra", + ]); + }); + + it("classifies a non-0/1 probe status (e.g. Docker 125) as a failure without a switch", () => { + const execFile = vi.fn((..._args: unknown[]) => ""); + dockerExec.dockerSpawnSync = vi.fn((..._args: unknown[]) => ({ status: 125, signal: null })); + dockerExec.dockerExecFileSync = execFile; + + const result = loadConverge()("hermes", "/sandbox/.hermes", "vllm-local", "nemotron-ultra"); + + expect(result.status).toBe("failed"); + expect(result.detail).toContain("125"); + expect(execFile).not.toHaveBeenCalled(); + }); + + it("classifies a spawn error as a failure and surfaces only the error message", () => { + dockerExec.dockerSpawnSync = vi.fn(() => ({ + status: null, + signal: null, + error: new Error("docker not found"), + })); + dockerExec.dockerExecFileSync = vi.fn((..._args: unknown[]) => ""); + + const result = loadConverge()("hermes", "/sandbox/.hermes", "vllm-local", "nemotron-ultra"); + + expect(result).toEqual({ status: "failed", detail: "docker not found" }); + }); + + it("classifies a failed model write as a failure carrying the underlying message", () => { + dockerExec.dockerSpawnSync = vi.fn((..._args: unknown[]) => ({ status: 0, signal: null })); + dockerExec.dockerExecFileSync = vi.fn(() => { + throw new Error("hermes config set exited 1"); + }); + + const result = loadConverge()("hermes", "/sandbox/.hermes", "vllm-local", "nemotron-ultra"); + + expect(result).toEqual({ status: "failed", detail: "hermes config set exited 1" }); + }); +});