diff --git a/ci/source-architecture-budget.json b/ci/source-architecture-budget.json index 6be126d9cfc..33d2386a7db 100644 --- a/ci/source-architecture-budget.json +++ b/ci/source-architecture-budget.json @@ -16,7 +16,7 @@ "src/lib/cli/terminal-style.ts": 43, "src/lib/core/json-types.ts": 37, "src/lib/core/ports.ts": 89, - "src/lib/core/shell-quote.ts": 28, + "src/lib/core/shell-quote.ts": 27, "src/lib/core/url-utils.ts": 30, "src/lib/core/wait.ts": 36, "src/lib/credentials/store.ts": 46, diff --git a/docs/manage-sandboxes/set-up-whatsapp.mdx b/docs/manage-sandboxes/set-up-whatsapp.mdx index 2c542c938bd..dc42c12afe8 100644 --- a/docs/manage-sandboxes/set-up-whatsapp.mdx +++ b/docs/manage-sandboxes/set-up-whatsapp.mdx @@ -35,20 +35,6 @@ If pairing exits with a gateway close such as `1008`, rerun the login command on Hermes dashboard pairing and the gateway share `/sandbox/.hermes/platforms/whatsapp/session`. After scanning a dashboard QR code, run `$$nemoclaw channels status --channel whatsapp` to confirm that the shared session is available to the gateway. - -If `channels status` reports credentials only under the legacy `profiles/dashboard-home` path, the sandbox has credentials from an image that wrote dashboard sessions to that path. -Rebuilding and pairing again writes new credentials to the shared path, but it leaves the legacy credentials in durable state, and sandbox startup treats that copy as migration input. -Clear every WhatsApp session path first with the supported removal command, then re-add the channel: - -```bash -$$nemoclaw channels remove whatsapp -$$nemoclaw channels add whatsapp -``` - -`channels remove` clears `/sandbox/.hermes/platforms/whatsapp`, the dashboard profile session at `/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session`, and the legacy migration source at `/sandbox/.hermes/dashboard-home/platforms/whatsapp/session`. -The sandbox must be running for that cleanup to succeed; `channels remove` refuses to proceed when it cannot reach the sandbox. -Pair again from the dashboard so the credentials are written to `/sandbox/.hermes/platforms/whatsapp/session`. -Rerun `$$nemoclaw channels status --channel whatsapp` and confirm that the gateway session path holds the credentials and that the report no longer lists a `profiles/dashboard-home` session. ## Protect Paired Session State diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index dc08a668186..b3454171a3b 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3002,7 +3002,6 @@ For QR-paired channels (today: WhatsApp), NemoClaw destructively clears the in-s - OpenClaw: `/sandbox/.openclaw//` (for example `/sandbox/.openclaw/whatsapp/`). - Hermes: `/sandbox/.hermes/platforms//` (for example `/sandbox/.hermes/platforms/whatsapp/`). - For WhatsApp, NemoClaw also clears the current Dashboard profile at `/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session/` and the legacy migration source at `/sandbox/.hermes/dashboard-home/platforms/whatsapp/session/`. The cleanup tries `openshell sandbox exec` first and falls back to SSH if the exec wrapper does not return the success sentinel. If both transports fail (the sandbox is stopped, the gateway is down, or SSH cannot reach it) the command refuses to proceed to the rebuild and asks you to start the sandbox and re-run, so a half-removed state cannot leave stale Baileys auth files behind for the next rebuild to restore. @@ -3073,23 +3072,8 @@ With `--channel`, it prints the detailed status for that channel. For an OpenClaw WhatsApp sandbox, `--channel whatsapp` probes the sandbox to separately report pairing/session state, the Noise WebSocket connection, inbound event delivery, and policy coverage. A paired channel with no observed inbound delivery exits non-zero with verdict `idle` so an unhealthy bridge cannot pass as healthy. The detailed WhatsApp probe stays focused on QR/session runtime diagnostics and does not include rendered-config comparison lines. -For a Hermes WhatsApp sandbox, `--channel whatsapp` first checks the shared gateway path and the `profiles/dashboard-home` path for `creds.json`. -The status compatibility probe has this contract: - -| Property | Contract | -|------|-------------| -| Owner | The NemoClaw WhatsApp status hook owns the probe. | -| Scope | The hook reads only `platforms.whatsapp.extra.session_path` from `/sandbox/.hermes/config.yaml` when the durable session path has no `creds.json`. The hook does not write the field or configure Hermes. | -| Validation | The value must be an absolute path under `/sandbox/.hermes` with no `.` or `..` segment. | -| Supported state | The durable Hermes WhatsApp session remains `/sandbox/.hermes/platforms/whatsapp/session`. The compatibility field is not a supported NemoClaw setup or session-storage control. | -| Support period | Keep the probe only while a supported Hermes image can place dashboard-paired credentials outside the durable path. | -| Retirement | [Issue #8947](https://github.com/NVIDIA/NemoClaw/issues/8947) tracks removal after every supported Hermes image uses the durable path for dashboard pairing and gateway startup. | - -After validation, the command checks the configured path and reports a `Session path override` signal. -An unsupported path produces a warning, and the report uses the default gateway path. -If the dashboard path has credentials and the gateway path is empty, the report tells you to run `$$nemoclaw channels remove whatsapp` and then `$$nemoclaw channels add whatsapp`, because a rebuild restores the legacy session instead of dropping it. -Pair again from the dashboard so credentials use `/sandbox/.hermes/platforms/whatsapp/session`. -Rerun `$$nemoclaw channels status --channel whatsapp`. +For a Hermes WhatsApp sandbox, `--channel whatsapp` checks only the shared gateway session path at `/sandbox/.hermes/platforms/whatsapp/session/creds.json`. +If the file is missing, pair with `hermes whatsapp` inside the sandbox and rerun `$$nemoclaw channels status --channel whatsapp`. NemoClaw does not treat a Hermes session file as live inbound-health evidence. For Telegram, `--channel telegram` probes the sandbox to report the gateway process, Bot API reachability, and inbound delivery alongside the config comparison. diff --git a/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.test.ts b/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.test.ts index d79b2cc8004..824ddd3ff8e 100644 --- a/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.test.ts +++ b/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.test.ts @@ -77,32 +77,6 @@ describe("evaluateWhatsappDiagnostics", () => { expect(report.hints.join(" ")).toMatch(/hermes whatsapp/); }); - it("guides legacy Hermes dashboard sessions through channel removal and re-pairing (#8184)", () => { - const report = evaluateWhatsappDiagnostics( - baseInput({ - agent: "hermes", - paired: false, - sessionLocations: { - gatewaySessionCreds: false, - dashboardSessionCreds: true, - }, - }), - ); - const session = report.signals.find((s) => s.label === "Session location"); - const pairing = report.signals.find((s) => s.label === "Pairing / session"); - const hints = report.hints.join(" "); - expect(report.verdict).toBe("unpaired"); - expect(session?.severity).toBe("warn"); - expect(session?.detail).toMatch(/dashboard-home has WhatsApp credentials/); - expect(pairing?.hint).toContain("`nemoclaw channels remove whatsapp`"); - expect(session?.hint).toContain("`nemoclaw channels add whatsapp`"); - expect(session?.hint).toMatch(/Pair again from the dashboard/); - expect(hints).toContain("/sandbox/.hermes/platforms/whatsapp/session"); - expect(hints).toContain("`nemoclaw channels status --channel whatsapp`"); - expect(hints).not.toContain("platforms.whatsapp.extra.session_path"); - expect(hints).not.toContain("profiles/dashboard-home/platforms/whatsapp/session"); - }); - it("keeps Hermes gateway session file evidence out of the live-health verdict", () => { const report = evaluateWhatsappDiagnostics( baseInput({ @@ -110,7 +84,6 @@ describe("evaluateWhatsappDiagnostics", () => { paired: null, sessionLocations: { gatewaySessionCreds: true, - dashboardSessionCreds: false, }, }), ); @@ -120,89 +93,6 @@ describe("evaluateWhatsappDiagnostics", () => { expect(session?.detail).toMatch(/gateway session path contains WhatsApp credentials/); }); - it("reports duplicate Hermes session paths without claiming live health (#8184)", () => { - const report = evaluateWhatsappDiagnostics( - baseInput({ - agent: "hermes", - paired: null, - sessionLocations: { - gatewaySessionCreds: true, - dashboardSessionCreds: true, - }, - }), - ); - const session = report.signals.find((s) => s.label === "Session location"); - expect(report.verdict).toBe("unknown"); - expect(session?.severity).toBe("info"); - expect(session?.detail).toBe("both Hermes session paths contain WhatsApp credentials"); - expect(session?.hint).toBe("use one active WhatsApp bridge for the paired account"); - }); - - it("accepts credentials found through the configured session path (#8718)", () => { - const report = evaluateWhatsappDiagnostics( - baseInput({ - agent: "hermes", - paired: null, - sessionLocations: { - gatewaySessionCreds: true, - dashboardSessionCreds: true, - gatewaySessionPathSource: "config", - }, - }), - ); - const session = report.signals.find((s) => s.label === "Session location"); - const override = report.signals.find((s) => s.label === "Session path override"); - expect(report.verdict).toBe("unknown"); - expect(session?.severity).toBe("ok"); - expect(session?.detail).toBe( - "the configured Hermes WhatsApp session path contains credentials", - ); - expect(override?.severity).toBe("info"); - expect(override?.detail).toContain("platforms.whatsapp.extra.session_path"); - }); - - it("stops repeating the repair command when the configured session path is empty (#8718)", () => { - const report = evaluateWhatsappDiagnostics( - baseInput({ - agent: "hermes", - paired: false, - sessionLocations: { - gatewaySessionCreds: false, - dashboardSessionCreds: true, - gatewaySessionPathSource: "config", - }, - }), - ); - const session = report.signals.find((s) => s.label === "Session location"); - expect(report.verdict).toBe("unpaired"); - expect(session?.severity).toBe("warn"); - expect(session?.detail).toBe( - "the configured Hermes WhatsApp session path has no WhatsApp credentials", - ); - expect(report.hints.join(" ")).not.toContain("--config-accept-new-path"); - expect(report.hints.join(" ")).toContain("hermes whatsapp"); - }); - - it("warns when the configured session path is not a supported sandbox path (#8718)", () => { - const report = evaluateWhatsappDiagnostics( - baseInput({ - agent: "hermes", - paired: false, - sessionLocations: { - gatewaySessionCreds: false, - dashboardSessionCreds: true, - gatewaySessionPathSource: "unsupported", - }, - }), - ); - const session = report.signals.find((s) => s.label === "Session location"); - const override = report.signals.find((s) => s.label === "Session path override"); - expect(session?.severity).toBe("warn"); - expect(session?.detail).toMatch(/dashboard-home has WhatsApp credentials/); - expect(override?.severity).toBe("warn"); - expect(override?.detail).toContain("not a supported session path"); - }); - it("returns idle when paired with a live WebSocket but no inbound event observed", () => { // This is the exact #4386 shape: pairing is fine, WebSocket is up, but // lastInboundAt is still null. We MUST NOT report this as healthy. diff --git a/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.ts b/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.ts index 694ced1aae3..54d5866584c 100644 --- a/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.ts +++ b/src/lib/messaging/channels/whatsapp/hooks/status-health-eval.ts @@ -85,16 +85,13 @@ export type WhatsappProbeInput = { presetOnGateway: boolean | null; // Whether the whatsapp channel is recorded in the registry messaging plan. channelEnabledInRegistry: boolean; - // Hermes runs the dashboard under a separate home. This probe records only - // whether the two expected credential files exist, never their contents. + // Hermes dashboard pairing and gateway startup share one canonical session + // path. This probe records only whether its credential file exists. sessionLocations?: WhatsappSessionLocations; }; export type WhatsappSessionLocations = { gatewaySessionCreds: boolean | null; - dashboardSessionCreds: boolean | null; - gatewaySessionPathSource?: "default" | "config" | "unsupported"; - gatewaySessionDir?: string; }; /** @@ -132,12 +129,6 @@ function isParseableTimestamp(value: string | null): value is string { return value !== null && Number.isFinite(Date.parse(value)); } -// A rebuild restores the legacy dashboard session instead of dropping it, so -// re-pairing alone leaves the sandbox holding two credential sets. Send the -// operator through `channels remove`, which clears every WhatsApp session path. -const HERMES_LEGACY_DASHBOARD_SESSION_HINT = - "Run `nemoclaw channels remove whatsapp` to clear every WhatsApp session path, then `nemoclaw channels add whatsapp`. Pair again from the dashboard so credentials are stored in `/sandbox/.hermes/platforms/whatsapp/session`. Rerun `nemoclaw channels status --channel whatsapp`."; - function pairingSignal(input: WhatsappProbeInput): DiagnosticSignal { if (!input.probeReachable) { return { @@ -155,15 +146,12 @@ function pairingSignal(input: WhatsappProbeInput): DiagnosticSignal { }; } if (input.paired === false) { - const dashboardOnly = hermesDashboardOnlySession(input); if (input.agent === "hermes") { return { label: "Pairing / session", severity: "warn", detail: "Hermes gateway session path has no WhatsApp credentials", - hint: dashboardOnly - ? HERMES_LEGACY_DASHBOARD_SESSION_HINT - : "run `hermes whatsapp` inside the sandbox to display a QR code", + hint: "run `hermes whatsapp` inside the sandbox to display a QR code", }; } const loginHint = @@ -184,98 +172,31 @@ function pairingSignal(input: WhatsappProbeInput): DiagnosticSignal { }; } -function hermesDashboardOnlySession(input: WhatsappProbeInput): boolean { - return ( - input.agent === "hermes" && - input.sessionLocations?.gatewaySessionCreds === false && - input.sessionLocations.dashboardSessionCreds === true && - input.sessionLocations.gatewaySessionPathSource !== "config" - ); -} - function sessionLocationSignal(input: WhatsappProbeInput): DiagnosticSignal | null { const locations = input.sessionLocations; if (!locations) return null; const gateway = locations.gatewaySessionCreds; - const dashboard = locations.dashboardSessionCreds; - if (locations.gatewaySessionPathSource === "config" && gateway !== null) { - const configuredPath = locations.gatewaySessionDir - ? ` at \`${locations.gatewaySessionDir}\`` - : ""; - return gateway - ? { - label: "Session location", - severity: "ok", - detail: `the configured Hermes WhatsApp session path${configuredPath} contains credentials`, - } - : { - label: "Session location", - severity: "warn", - detail: `the configured Hermes WhatsApp session path${configuredPath} has no WhatsApp credentials`, - hint: "pair WhatsApp again, or set `platforms.whatsapp.extra.session_path` to the session path that holds the credentials", - }; - } - if (gateway === false && dashboard === true) { - return { - label: "Session location", - severity: "warn", - detail: - "dashboard-home has WhatsApp credentials, but the Hermes gateway session path is empty", - hint: HERMES_LEGACY_DASHBOARD_SESSION_HINT, - }; - } - if (gateway === true && dashboard === false) { + if (gateway === true) { return { label: "Session location", severity: "ok", detail: "Hermes gateway session path contains WhatsApp credentials", }; } - if (gateway === false && dashboard === false) { - return { - label: "Session location", - severity: "info", - detail: "no WhatsApp credentials found in the Hermes gateway or dashboard session paths", - }; - } - if (gateway === true && dashboard === true) { + if (gateway === false) { return { label: "Session location", severity: "info", - detail: "both Hermes session paths contain WhatsApp credentials", - hint: "use one active WhatsApp bridge for the paired account", + detail: "the Hermes gateway session path has no WhatsApp credentials", }; } return { label: "Session location", severity: "info", - detail: "Hermes session paths could not be inspected", + detail: "the Hermes gateway session path could not be inspected", }; } -function sessionPathOverrideSignal(input: WhatsappProbeInput): DiagnosticSignal | null { - const source = input.sessionLocations?.gatewaySessionPathSource; - if (source === "config") { - return { - label: "Session path override", - severity: "info", - detail: - "the gateway session check used the path set in `platforms.whatsapp.extra.session_path`", - hint: "remove the override after Hermes uses one WhatsApp session path for dashboard pairing and gateway startup", - }; - } - if (source === "unsupported") { - return { - label: "Session path override", - severity: "warn", - detail: - "`platforms.whatsapp.extra.session_path` is not a supported session path, so the gateway session check used the default path", - hint: "set `platforms.whatsapp.extra.session_path` to an absolute path under `/sandbox/.hermes` that has no `.` or `..` segment", - }; - } - return null; -} - function websocketSignal(input: WhatsappProbeInput): DiagnosticSignal { if (input.heartbeatParseError) { return { @@ -519,13 +440,6 @@ function buildHints(verdict: WhatsappVerdict, input: WhatsappProbeInput): string ); break; case "unpaired": - if (hermesDashboardOnlySession(input)) { - hints.push( - "Hermes dashboard pairing wrote credentials under dashboard-home, but the gateway reads the default platforms path.", - HERMES_LEGACY_DASHBOARD_SESSION_HINT, - ); - break; - } hints.push( input.agent === "hermes" ? "Run `hermes whatsapp` inside the sandbox and scan the QR with your phone." @@ -556,12 +470,10 @@ function buildHints(verdict: WhatsappVerdict, input: WhatsappProbeInput): string export function evaluateWhatsappDiagnostics(input: WhatsappProbeInput): WhatsappDiagnosticReport { const sessionSignal = sessionLocationSignal(input); - const overrideSignal = sessionPathOverrideSignal(input); const signals: DiagnosticSignal[] = [ configCoverageSignal(input), pairingSignal(input), ...(sessionSignal ? [sessionSignal] : []), - ...(overrideSignal ? [overrideSignal] : []), bridgeProcessSignal(input), websocketSignal(input), inboundSignal(input), diff --git a/src/lib/messaging/channels/whatsapp/hooks/status-health.test.ts b/src/lib/messaging/channels/whatsapp/hooks/status-health.test.ts index 72df8dbe024..e63f014dca7 100644 --- a/src/lib/messaging/channels/whatsapp/hooks/status-health.test.ts +++ b/src/lib/messaging/channels/whatsapp/hooks/status-health.test.ts @@ -100,54 +100,13 @@ function openclawJson(wa: Record | null): string { return JSON.stringify(openclawPayload(wa)); } -function hermesSessionProbeOutput(options: { - gatewaySessionCreds: boolean; - dashboardSessionCreds: boolean; -}): string { +function hermesSessionProbeOutput(gatewaySessionCreds: boolean): string { return [ "NEMOCLAW_HERMES_WHATSAPP_SESSION_V1", - `GATEWAY_SESSION=${options.gatewaySessionCreds ? "present" : "missing"}`, - `DASHBOARD_SESSION=${options.dashboardSessionCreds ? "present" : "missing"}`, + `GATEWAY_SESSION=${gatewaySessionCreds ? "present" : "missing"}`, ].join("\n"); } -const HERMES_DEFAULT_SESSION_DIR = "/sandbox/.hermes/platforms/whatsapp/session"; -const HERMES_DASHBOARD_SESSION_DIR = - "/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session"; - -function hermesExec(options: { - readonly configuredSessionPath?: unknown; - readonly configuredSessionProbeFails?: boolean; - readonly configProbeStdout?: string; - readonly credsDirs: readonly string[]; -}) { - const hasCreds = (credsFile: string) => - options.credsDirs.some((dir) => credsFile === `${dir}/creds.json`); - return vi.fn((_sandbox: string, command: string, _timeout: number): ExecResult => { - return command.startsWith("python3 -c ") - ? options.configProbeStdout !== undefined - ? { status: 0, stdout: options.configProbeStdout, stderr: "" } - : options.configuredSessionPath === undefined - ? { status: 1, stdout: "", stderr: "config unavailable" } - : { - status: 0, - stdout: `NEMOCLAW_HERMES_WHATSAPP_CONFIG_V1\n${JSON.stringify(options.configuredSessionPath)}`, - stderr: "", - } - : options.configuredSessionProbeFails && - command.includes(`gateway='${HERMES_DASHBOARD_SESSION_DIR}/creds.json'`) - ? { status: 1, stdout: "", stderr: "configured session probe unavailable" } - : { - status: 0, - stdout: hermesSessionProbeOutput({ - gatewaySessionCreds: hasCreds(/gateway='([^']*)'/.exec(command)?.[1] ?? ""), - dashboardSessionCreds: hasCreds(/dashboard='([^']*)'/.exec(command)?.[1] ?? ""), - }), - stderr: "", - }; - }); -} - const HEALTHY_WA: WaFixture = { configured: true, statusState: "linked", @@ -429,13 +388,10 @@ describe("whatsapp.statusHealth openclaw CLI probe", () => { expect(reportOf(run())?.verdict).toBeDefined(); }); - it("guides the Hermes dashboard-only session split through re-pairing (#8184)", () => { + it("reports an unpaired Hermes sandbox from the canonical session path", () => { const exec = makeExec({ status: 0, - stdout: hermesSessionProbeOutput({ - gatewaySessionCreds: false, - dashboardSessionCreds: true, - }), + stdout: hermesSessionProbeOutput(false), stderr: "", }); const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( @@ -443,166 +399,20 @@ describe("whatsapp.statusHealth openclaw CLI probe", () => { ); const report = reportOf(result); const command = String(exec.mock.calls[0]?.[1] ?? ""); - const hint = report?.signals.find((s) => s.label === "Session location")?.hint; expect(report?.verdict).toBe("unpaired"); - expect(hint).toContain("`nemoclaw channels remove whatsapp`"); - expect(hint).toContain("`nemoclaw channels add whatsapp`"); - expect(hint).toMatch(/Pair again from the dashboard/); - expect(hint).toContain("/sandbox/.hermes/platforms/whatsapp/session"); - expect(hint).toContain("`nemoclaw channels status --channel whatsapp`"); - expect(hint).not.toContain("platforms.whatsapp.extra.session_path"); - expect(command).toContain("/sandbox/.hermes/platforms/whatsapp/session/creds.json"); - expect(command).toContain( - "/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session/creds.json", + expect(report?.signals.find((s) => s.label === "Pairing / session")?.hint).toContain( + "hermes whatsapp", ); + expect(command).toContain("/sandbox/.hermes/platforms/whatsapp/session/creds.json"); + expect(command).not.toContain("profiles/dashboard-home"); + expect(command).not.toContain("platforms.whatsapp.extra.session_path"); expect(command).not.toMatch(/(^|[;&|]\s*)(cat|grep|find|ls)\b/); }); - // Keep these configured-path compatibility assertions only for the support period tracked by - // #8947. The default constant above remains the supported durable session location. - it.each([ - { - label: "path outside the Hermes config directory", - sessionPath: "/etc/hermes/session", - }, - { - label: "path with a parent-directory segment", - sessionPath: "/sandbox/.hermes/../../etc/session", - }, - { - label: "path carrying shell syntax", - sessionPath: "/sandbox/.hermes/session'; touch /tmp/pwned; '", - }, - { - label: "non-string value", - sessionPath: 42, - }, - ])("keeps the durable session path for an unsupported compatibility value: $label (#8947)", ({ - sessionPath, - }) => { - const exec = hermesExec({ - configuredSessionPath: sessionPath, - credsDirs: [HERMES_DASHBOARD_SESSION_DIR], - }); - const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( - context({ ...BASE_INPUTS, agent: "hermes" }), - ); - const report = reportOf(result); - const probeCommands = exec.mock.calls - .map((call) => String(call[1] ?? "")) - .filter((command) => !command.startsWith("python3 -c ")); - expect(report?.verdict).toBe("unpaired"); - expect(report?.signals.find((s) => s.label === "Session path override")?.severity).toBe("warn"); - expect(probeCommands).toHaveLength(1); - expect(probeCommands[0]).toContain(`gateway='${HERMES_DEFAULT_SESSION_DIR}/creds.json'`); - expect(probeCommands[0]).not.toContain(String(sessionPath)); - }); - - it("reads the Hermes config only when the default session path is empty (#8718)", () => { - const exec = hermesExec({ - configuredSessionPath: HERMES_DASHBOARD_SESSION_DIR, - credsDirs: [HERMES_DEFAULT_SESSION_DIR], - }); - const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( - context({ ...BASE_INPUTS, agent: "hermes" }), - ); - const report = reportOf(result); - expect(exec.mock.calls.map((call) => String(call[1] ?? ""))).toHaveLength(1); - expect(report?.signals.find((s) => s.label === "Session path override")).toBeUndefined(); - }); - - it("keeps unrelated Hermes config values out of the report (#8718)", () => { - const exec = hermesExec({ - configuredSessionPath: HERMES_DASHBOARD_SESSION_DIR, - credsDirs: [HERMES_DASHBOARD_SESSION_DIR], - }); - const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( - context({ ...BASE_INPUTS, agent: "hermes" }), - ); - expect(stringifyReport(result)).not.toContain("sk-do-not-leak-this"); - expect(exec.mock.calls.map((call) => String(call[1] ?? "")).join("\n")).not.toContain( - "cat /sandbox/.hermes/config.yaml", - ); - }); - - it("keeps default diagnostics when the configured Hermes session probe fails (#8718)", () => { - const exec = hermesExec({ - configuredSessionPath: HERMES_DASHBOARD_SESSION_DIR, - configuredSessionProbeFails: true, - credsDirs: [HERMES_DASHBOARD_SESSION_DIR], - }); - const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( - context({ ...BASE_INPUTS, agent: "hermes" }), - ); - const report = reportOf(result); - - expect(report?.verdict).toBe("unpaired"); - expect(report?.signals.find((s) => s.label === "Session path override")).toBeUndefined(); - expect(report?.signals.find((s) => s.label === "Session location")?.hint).toContain( - "channels add whatsapp", - ); - expect(exec).toHaveBeenCalledTimes(3); - }); - - it("keeps Hermes fallback probes within one timeout budget (#8718)", () => { - const exec = hermesExec({ - configuredSessionPath: HERMES_DASHBOARD_SESSION_DIR, - credsDirs: [HERMES_DASHBOARD_SESSION_DIR], - }); - createWhatsappStatusHealthHook({ executeSandboxCommand: exec, timeoutMs: 8_000 })( - context({ ...BASE_INPUTS, agent: "hermes" }), - ); - const probeTimeouts = exec.mock.calls.map((call) => Number(call[2])); - - expect(probeTimeouts).toEqual([4_000, 2_000, 2_000]); - expect(probeTimeouts.reduce((total, timeout) => total + timeout, 0)).toBeLessThanOrEqual(8_000); - }); - - it("rejects a config probe response that carries unrelated values (#8718)", () => { - const secret = "sk-do-not-cross-the-sandbox-boundary"; - const exec = hermesExec({ - configProbeStdout: [ - "NEMOCLAW_HERMES_WHATSAPP_CONFIG_V1", - JSON.stringify(HERMES_DASHBOARD_SESSION_DIR), - JSON.stringify({ api_key: secret }), - ].join("\n"), - credsDirs: [HERMES_DASHBOARD_SESSION_DIR], - }); - const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( - context({ ...BASE_INPUTS, agent: "hermes" }), - ); - const report = reportOf(result); - const probeCommands = exec.mock.calls.map((call) => String(call[1] ?? "")); - - expect(report?.verdict).toBe("unpaired"); - expect(stringifyReport(result)).not.toContain(secret); - expect(probeCommands).toHaveLength(2); - expect(probeCommands[0]).toContain(`gateway='${HERMES_DEFAULT_SESSION_DIR}/creds.json'`); - }); - - it("falls back to the default session path when the Hermes config cannot be read (#8718)", () => { - const exec = hermesExec({ credsDirs: [HERMES_DASHBOARD_SESSION_DIR] }); - const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( - context({ ...BASE_INPUTS, agent: "hermes" }), - ); - const report = reportOf(result); - expect(report?.verdict).toBe("unpaired"); - expect(report?.signals.find((s) => s.label === "Session location")?.hint).toContain( - "channels add whatsapp", - ); - expect(report?.signals.find((s) => s.label === "Session location")?.hint).not.toContain( - "platforms.whatsapp.extra.session_path", - ); - expect(report?.signals.find((s) => s.label === "Session path override")).toBeUndefined(); - }); - it("does not treat a Hermes gateway session file as live inbound health", () => { const exec = makeExec({ status: 0, - stdout: hermesSessionProbeOutput({ - gatewaySessionCreds: true, - dashboardSessionCreds: false, - }), + stdout: hermesSessionProbeOutput(true), stderr: "", }); const result = createWhatsappStatusHealthHook({ executeSandboxCommand: exec })( @@ -616,18 +426,17 @@ describe("whatsapp.statusHealth openclaw CLI probe", () => { it.each([ { label: "missing sentinel", - stdout: ["GATEWAY_SESSION=missing", "DASHBOARD_SESSION=present"].join("\n"), + stdout: "GATEWAY_SESSION=missing", }, { label: "missing gateway session line", - stdout: ["NEMOCLAW_HERMES_WHATSAPP_SESSION_V1", "DASHBOARD_SESSION=present"].join("\n"), + stdout: "NEMOCLAW_HERMES_WHATSAPP_SESSION_V1", }, { - label: "invalid dashboard session value", + label: "invalid gateway session value", stdout: [ "NEMOCLAW_HERMES_WHATSAPP_SESSION_V1", - "GATEWAY_SESSION=missing", - "DASHBOARD_SESSION=yes", + "GATEWAY_SESSION=yes", ].join("\n"), }, ])("reports probe_failed for malformed Hermes probe output: $label", ({ stdout }) => { @@ -638,7 +447,7 @@ describe("whatsapp.statusHealth openclaw CLI probe", () => { const report = reportOf(result); expect(report?.verdict).toBe("probe_failed"); expect(report?.signals.find((s) => s.label === "Session location")).toBeUndefined(); - expect(stringifyReport(result)).not.toContain("platforms.whatsapp.extra.session_path"); + expect(stringifyReport(result)).not.toContain("profiles/dashboard-home"); }); it.each([ diff --git a/src/lib/messaging/channels/whatsapp/hooks/status-health.ts b/src/lib/messaging/channels/whatsapp/hooks/status-health.ts index 3d73ecea20d..b962b6b5e1d 100644 --- a/src/lib/messaging/channels/whatsapp/hooks/status-health.ts +++ b/src/lib/messaging/channels/whatsapp/hooks/status-health.ts @@ -8,28 +8,12 @@ * command via the status-hook runner, so no whatsapp-specific code lives in * the generic status orchestrator. * - * For Hermes, the probe reads only fixed boolean evidence about the two known - * WhatsApp session paths: + * For Hermes, the probe reads only fixed boolean evidence about the canonical + * WhatsApp session path: * * /sandbox/.hermes/platforms/whatsapp/session/creds.json - * /sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session/creds.json - * * It never reads credential file contents or lists session directories. * - * The documented repair for a dashboard-only session points - * `platforms.whatsapp.extra.session_path` at another directory, so the default - * gateway path stays empty while the gateway reads credentials elsewhere. When - * the default path holds no credentials, a sandbox-local parser reads that - * key and returns only its JSON value. The host never receives the complete - * Hermes config. The probe then re-checks the configured directory so the - * repair can be confirmed instead of reported as an unresolved split. - * - * This is a bounded compatibility probe for Hermes dashboard pairing that can - * write credentials under profiles/dashboard-home while the gateway reads the - * default session path. Remove the dashboard profile branch after Hermes uses - * one shared WhatsApp session path for both dashboard pairing and gateway - * startup. - * * The probe reads OpenClaw's authoritative live status JSON: * * openclaw channels status --channel whatsapp --json --timeout @@ -56,7 +40,6 @@ * state-string enums, and epoch timestamps make it into the report. */ -import { shellQuote } from "../../../../core/shell-quote"; import type { MessagingHookHandler, MessagingHookRegistration } from "../../../hooks/types"; import type { MessagingSerializableValue } from "../../../manifest"; import { @@ -78,13 +61,6 @@ export const WHATSAPP_STATUS_HEALTH_HOOK_HANDLER_ID = "whatsapp.statusHealth"; // inheriting that hang. const DEFAULT_TIMEOUT_MS = 8_000; const HERMES_SESSION_PROBE_SENTINEL = "NEMOCLAW_HERMES_WHATSAPP_SESSION_V1"; -const HERMES_CONFIG_PROBE_SENTINEL = "NEMOCLAW_HERMES_WHATSAPP_CONFIG_V1"; -const HERMES_CONFIG_PATH = "/sandbox/.hermes/config.yaml"; -const HERMES_DEFAULT_SESSION_DIR = "/sandbox/.hermes/platforms/whatsapp/session"; -const HERMES_DASHBOARD_SESSION_DIR = - "/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session"; -const HERMES_SESSION_PATH_KEYS = ["platforms", "whatsapp", "extra", "session_path"] as const; -const HERMES_SESSION_DIR_PATTERN = /^\/sandbox\/\.hermes\/[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/; /** WhatsApp uses the generic channel-health hook options unchanged. */ export type WhatsappStatusHealthHookOptions = ChannelStatusHealthHookOptions; @@ -244,45 +220,8 @@ function runHermesSessionProbe( sandboxName: string, timeoutMs: number, ): ProbeResult { - const configuredProbeTimeoutMs = Math.floor(timeoutMs / 4); - const configProbeTimeoutMs = Math.floor(timeoutMs / 4); - const defaultProbeTimeoutMs = timeoutMs - configProbeTimeoutMs - configuredProbeTimeoutMs; - const defaultLocations = probeHermesSessionDirs( - execute, - sandboxName, - HERMES_DEFAULT_SESSION_DIR, - defaultProbeTimeoutMs, - ); - if (!defaultLocations) return PROBE_UNREACHABLE; - if (defaultLocations.gatewaySessionCreds !== false) { - return hermesProbeResult(defaultLocations, "default"); - } - - // The default-path check, config read, and configured-path check share one - // caller-supplied timeout budget. For sub-millisecond fallback budgets, keep - // the successful default result instead of starting an unbounded extra probe. - if (configProbeTimeoutMs < 1 || configuredProbeTimeoutMs < 1) { - return hermesProbeResult(defaultLocations, "default"); - } - const configured = readHermesConfiguredSessionDir(execute, sandboxName, configProbeTimeoutMs); - if (configured.source !== "config") { - return hermesProbeResult(defaultLocations, configured.source); - } - const configuredLocations = probeHermesSessionDirs( - execute, - sandboxName, - configured.dir, - configuredProbeTimeoutMs, - ); - if (!configuredLocations) return hermesProbeResult(defaultLocations, "default"); - return hermesProbeResult(configuredLocations, "config", configured.dir); -} - -function hermesProbeResult( - locations: WhatsappSessionLocations, - gatewaySessionPathSource: HermesSessionPathSource, - gatewaySessionDir?: string, -): ProbeResult { + const locations = probeHermesSession(execute, sandboxName, timeoutMs); + if (!locations) return PROBE_UNREACHABLE; const gatewaySession = locations.gatewaySessionCreds === true; return { probeReachable: true, @@ -290,23 +229,18 @@ function hermesProbeResult( bridgeProcessAlive: null, heartbeat: null, recentLogSignals: [], - sessionLocations: { - ...locations, - gatewaySessionPathSource, - ...(gatewaySessionDir === undefined ? {} : { gatewaySessionDir }), - }, + sessionLocations: locations, }; } -function probeHermesSessionDirs( +function probeHermesSession( execute: NonNullable, sandboxName: string, - gatewaySessionDir: string, timeoutMs: number, ): WhatsappSessionLocations | null { let exec: ReturnType; try { - exec = execute(sandboxName, hermesSessionProbeCommand(gatewaySessionDir), timeoutMs); + exec = execute(sandboxName, hermesSessionProbeCommand(), timeoutMs); } catch { return null; } @@ -314,71 +248,11 @@ function probeHermesSessionDirs( return parseHermesSessionProbe(String(exec.stdout ?? "")); } -type HermesSessionPathSource = NonNullable; - -function readHermesConfiguredSessionDir( - execute: NonNullable, - sandboxName: string, - timeoutMs: number, -): { readonly dir: string; readonly source: HermesSessionPathSource } { - const fallback = { dir: HERMES_DEFAULT_SESSION_DIR, source: "default" } as const; - let exec: ReturnType; - try { - exec = execute(sandboxName, hermesConfiguredSessionPathCommand(), timeoutMs); - } catch { - return fallback; - } - if (!exec || exec.status !== 0) return fallback; - const configured = parseHermesConfiguredSessionPath(String(exec.stdout ?? "")); - if (configured === undefined || configured === null) return fallback; - if (!isSupportedHermesSessionDir(configured)) { - return { dir: HERMES_DEFAULT_SESSION_DIR, source: "unsupported" }; - } - if (configured === HERMES_DEFAULT_SESSION_DIR) return fallback; - return { dir: configured, source: "config" }; -} - -function hermesConfiguredSessionPathCommand(): string { - const script = [ - "import json", - "from pathlib import Path", - "import yaml", - `config = yaml.safe_load(Path(${JSON.stringify(HERMES_CONFIG_PATH)}).read_text(encoding=\"utf-8\"))`, - "def child(value, key):", - " return value.get(key) if isinstance(value, dict) else None", - "node = config", - ...HERMES_SESSION_PATH_KEYS.map((key) => `node = child(node, ${JSON.stringify(key)})`), - `print(${JSON.stringify(HERMES_CONFIG_PROBE_SENTINEL)})`, - "print(json.dumps(node))", - ].join("\n"); - return `python3 -c ${shellQuote(script)}`; -} - -function parseHermesConfiguredSessionPath(stdout: string): unknown { - const lines = stdout - .split(/\r?\n/) - .map((line) => line.trim()) - .filter(Boolean); - if (lines.length !== 2 || lines[0] !== HERMES_CONFIG_PROBE_SENTINEL) return undefined; - try { - return JSON.parse(lines[1]); - } catch { - return undefined; - } -} - -function isSupportedHermesSessionDir(value: unknown): value is string { - if (typeof value !== "string" || !HERMES_SESSION_DIR_PATTERN.test(value)) return false; - return value.split("/").every((segment) => segment !== "." && segment !== ".."); -} - -function hermesSessionProbeCommand(gatewaySessionDir: string): string { +function hermesSessionProbeCommand(): string { return [ - `gateway=${shellQuote(`${gatewaySessionDir}/creds.json`)}`, - `dashboard=${shellQuote(`${HERMES_DASHBOARD_SESSION_DIR}/creds.json`)}`, + 'gateway="/sandbox/.hermes/platforms/whatsapp/session/creds.json"', `printf '%s\\n' '${HERMES_SESSION_PROBE_SENTINEL}'`, 'if [ -f "$gateway" ]; then printf "%s\\n" "GATEWAY_SESSION=present"; else printf "%s\\n" "GATEWAY_SESSION=missing"; fi', - 'if [ -f "$dashboard" ]; then printf "%s\\n" "DASHBOARD_SESSION=present"; else printf "%s\\n" "DASHBOARD_SESSION=missing"; fi', ].join("; "); } @@ -389,9 +263,8 @@ function parseHermesSessionProbe(stdout: string): WhatsappSessionLocations | nul .filter(Boolean); if (!lines.includes(HERMES_SESSION_PROBE_SENTINEL)) return null; const gateway = readProbeBoolean(lines, "GATEWAY_SESSION"); - const dashboard = readProbeBoolean(lines, "DASHBOARD_SESSION"); - if (gateway === null || dashboard === null) return null; - return { gatewaySessionCreds: gateway, dashboardSessionCreds: dashboard }; + if (gateway === null) return null; + return { gatewaySessionCreds: gateway }; } function readProbeBoolean(lines: readonly string[], key: string): boolean | null { diff --git a/src/lib/messaging/channels/whatsapp/manifest.ts b/src/lib/messaging/channels/whatsapp/manifest.ts index e125a39091d..1853cf907ad 100644 --- a/src/lib/messaging/channels/whatsapp/manifest.ts +++ b/src/lib/messaging/channels/whatsapp/manifest.ts @@ -11,7 +11,7 @@ export const whatsappManifest = { enrollmentHelp: "WhatsApp Web pairs via QR code scanned with your phone — no host-side token. After the sandbox is running, run `openshell term` and then use `openclaw channels login --channel whatsapp` for OpenClaw or `hermes whatsapp` for Hermes to display the QR.", enrollmentNotes: [ - "After pairing, run `nemoclaw channels status --channel whatsapp`. OpenClaw reports inbound delivery evidence; Hermes reports gateway and dashboard session-path diagnostics.", + "After pairing, run `nemoclaw channels status --channel whatsapp`. OpenClaw reports inbound delivery evidence; Hermes reports the shared gateway session path.", ], supportedAgents: ["openclaw", "hermes"], auth: {