-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(sandbox): name the quarantined gateway relaunch and its repair #7816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
ef77c5b
fix(sandbox): name the quarantined gateway relaunch and its repair
yanyunl1991 fb60fb9
fix(sandbox): report the recovery layer without changing the result s…
yanyunl1991 d48edec
test(sandbox): assert the probe repair output, not the options shape
yanyunl1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/lib/actions/sandbox/gateway-restart-quarantine-repair.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { | ||
| classifyGatewayRestartFailure, | ||
| gatewayIntegrityRepairLines, | ||
| isGatewayIntegrityRepairLayer, | ||
| printGatewayRestartFailure, | ||
| } from "./gateway-restart"; | ||
|
|
||
| // The exact lines the in-sandbox Hermes supervisor emits when it stops | ||
| // attempting relaunch. `scripts/managed-gateway-control.py` allowlists these | ||
| // before forwarding them to the host as `NEMOCLAW_START_LOG=` lines. | ||
| const QUARANTINE_LINES = [ | ||
| "[gateway] CRITICAL: 5 exits in 60s window — Hermes relaunch is quarantined until sandbox recreation; check /tmp/gateway.log", | ||
| "[SECURITY] Hermes automatic respawn is quarantined until MCP integrity is restored by rebuilding the sandbox", | ||
| "[gateway] CRITICAL: exact Hermes replacement could not be stopped; managed supervisor is quarantined without another launch", | ||
| "[CRITICAL] Unproven Hermes gateway child exited; managed supervisor remains quarantined until sandbox recreation", | ||
| "[CRITICAL] Newly launched Hermes gateway pid 4242 failed exact role identity capture; quarantining the managed startup supervisor without signaling the unproven child", | ||
| ] as const; | ||
|
|
||
| // Verbatim controller output captured on a Hermes sandbox whose protected | ||
| // `config.yaml` was edited outside a supported command, then restarted. | ||
| const REPORTED_RESTART_OUTPUT = [ | ||
| "GATEWAY_HEALTH_TIMEOUT", | ||
| "NEMOCLAW_CONTROL_STAGE=await-replacement", | ||
| "NEMOCLAW_SUPERVISOR_PID=42", | ||
| "NEMOCLAW_GATEWAY_PID=0", | ||
| "NEMOCLAW_START_LOG=[gateway] Hermes gateway respawned (pid 18424)", | ||
| "NEMOCLAW_START_LOG=[SECURITY] Hermes automatic respawn is quarantined until MCP integrity is restored by rebuilding the sandbox", | ||
| ].join("\n"); | ||
|
|
||
| function classify(stdout: string) { | ||
| return classifyGatewayRestartFailure({ status: 1, stdout, stderr: "" }); | ||
| } | ||
|
|
||
| function captureStderr(run: () => void): string[] { | ||
| const lines: string[] = []; | ||
| const spy = vi.spyOn(console, "error").mockImplementation((value?: unknown) => { | ||
| lines.push(String(value)); | ||
| }); | ||
| run(); | ||
| spy.mockRestore(); | ||
| return lines; | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe("supervisor relaunch quarantine classification (#7801)", () => { | ||
| it.each(QUARANTINE_LINES)("classifies %s as a relaunch quarantine", (line) => { | ||
| expect(classify(line)).toMatchObject({ layer: "relaunch quarantined" }); | ||
| }); | ||
|
|
||
| it("classifies the reported restart output as a quarantine, not a health timeout", () => { | ||
| expect(classify(REPORTED_RESTART_OUTPUT)).toMatchObject({ layer: "relaunch quarantined" }); | ||
| }); | ||
|
|
||
| it("prefers the quarantine over the MCP drift it is reported through", () => { | ||
| const output = [ | ||
| "HERMES_MCP_CONFIG_DRIFT", | ||
| "[SECURITY] Hermes automatic respawn is quarantined until MCP integrity is restored by rebuilding the sandbox", | ||
| ].join("\n"); | ||
| expect(classify(output)).toMatchObject({ layer: "relaunch quarantined" }); | ||
| }); | ||
|
|
||
| it("keeps the pre-existing layers for output without a quarantine line", () => { | ||
| expect(classify("GATEWAY_HEALTH_TIMEOUT")).toMatchObject({ layer: "health timeout" }); | ||
| expect(classify("HERMES_MCP_CONFIG_DRIFT")).toMatchObject({ | ||
| layer: "MCP reconciliation refusal", | ||
| }); | ||
| expect(classify("GATEWAY_CONFIG_HASH_MISMATCH")).toMatchObject({ | ||
| layer: "config hash mismatch", | ||
| }); | ||
| expect(classify("SUPERVISOR_NOT_RUNNING")).toMatchObject({ layer: "supervisor not running" }); | ||
| }); | ||
|
|
||
| it("ignores an unrelated line that merely mentions the supervisor", () => { | ||
| expect(classify("[gateway] Hermes gateway respawned (pid 18424)")).toMatchObject({ | ||
| layer: "launch failure", | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("integrity repair guidance (#7801)", () => { | ||
| it("treats both deterministic integrity refusals as repairable layers", () => { | ||
| expect(isGatewayIntegrityRepairLayer("relaunch quarantined")).toBe(true); | ||
| expect(isGatewayIntegrityRepairLayer("config hash mismatch")).toBe(true); | ||
| expect(isGatewayIntegrityRepairLayer("health timeout")).toBe(false); | ||
| expect(isGatewayIntegrityRepairLayer("launch failure")).toBe(false); | ||
| expect(isGatewayIntegrityRepairLayer(null)).toBe(false); | ||
| expect(isGatewayIntegrityRepairLayer(undefined)).toBe(false); | ||
| }); | ||
|
|
||
| it.each([ | ||
| "relaunch quarantined", | ||
| "config hash mismatch", | ||
| ] as const)("names the supported repair command for %s", (layer) => { | ||
| const lines = gatewayIntegrityRepairLines("repro-7801", layer).join("\n"); | ||
| expect(lines).toContain("nemoclaw repro-7801 rebuild --yes"); | ||
| expect(lines).toContain("Retrying the restart cannot clear it."); | ||
| expect(lines).toContain("nemoclaw repro-7801 config set"); | ||
| }); | ||
|
|
||
| it("describes the two refusals differently", () => { | ||
| const quarantined = gatewayIntegrityRepairLines("alpha", "relaunch quarantined")[0]; | ||
| const drifted = gatewayIntegrityRepairLines("alpha", "config hash mismatch")[0]; | ||
| expect(quarantined).not.toEqual(drifted); | ||
| expect(drifted).toContain("integrity hash"); | ||
| expect(quarantined).toContain("quarantined"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("printGatewayRestartFailure repair guidance (#7801)", () => { | ||
| it("appends the repair to a quarantined restart failure", () => { | ||
| const lines = captureStderr(() => | ||
| printGatewayRestartFailure("repro-7801", "relaunch quarantined", REPORTED_RESTART_OUTPUT), | ||
| ).join("\n"); | ||
| expect(lines).toContain("Failure layer: relaunch quarantined"); | ||
| expect(lines).toContain("nemoclaw repro-7801 rebuild --yes"); | ||
| }); | ||
|
|
||
| it("still prints the repair when the controller returned no detail", () => { | ||
| const lines = captureStderr(() => | ||
| printGatewayRestartFailure("repro-7801", "config hash mismatch", ""), | ||
| ).join("\n"); | ||
| expect(lines).toContain("nemoclaw repro-7801 rebuild --yes"); | ||
| }); | ||
|
|
||
| it("leaves retryable failure layers without a rebuild instruction", () => { | ||
| const timeout = captureStderr(() => | ||
| printGatewayRestartFailure("repro-7801", "health timeout", "GATEWAY_HEALTH_TIMEOUT"), | ||
| ).join("\n"); | ||
| const launch = captureStderr(() => | ||
| printGatewayRestartFailure("repro-7801", "launch failure", "GATEWAY_FAILED"), | ||
| ).join("\n"); | ||
| expect(timeout).not.toContain("rebuild --yes"); | ||
| expect(launch).not.toContain("rebuild --yes"); | ||
| }); | ||
|
|
||
| it("keeps the MCP reconciliation remediation it already emitted", () => { | ||
| const lines = captureStderr(() => | ||
| printGatewayRestartFailure("repro-7801", "MCP reconciliation refusal", "mcp-integrity"), | ||
| ).join("\n"); | ||
| expect(lines).toContain("nemoclaw repro-7801 mcp restart"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.