-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(rebuild): verify Hermes post-restore health #7117
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
595ace9
fix(rebuild): verify Hermes post-restore health
apurvvkumaria f3b1429
test(rebuild): isolate gateway verification
jyaunches cccf322
merge: sync PR 7117 with main
jyaunches 8b1e31c
docs(rebuild): clarify identity verification
jyaunches 6b80397
test(rebuild): cover gateway refusal states
jyaunches f12c7f7
test(rebuild): cover unavailable health probe
jyaunches ad06b2e
merge: sync PR 7117 with main
jyaunches c21c793
test(rebuild): update post-restore fixture
jyaunches 0604cf8
merge: sync PR 7117 with main
jyaunches 381ea10
merge: sync PR 7117 with main
jyaunches 8afd836
test(rebuild): prove non-OpenClaw path succeeds
apurvvkumaria 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
181 changes: 181 additions & 0 deletions
181
src/lib/actions/sandbox/rebuild-hermes-post-restore.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,181 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { | ||
| createRebuildFlowHarness, | ||
| resetRebuildFlowTestEnvironment, | ||
| restoreRebuildFlowTestEnvironment, | ||
| } from "../../../../test/helpers/rebuild-flow-harness"; | ||
|
|
||
| describe("Hermes rebuild post-restore verification", () => { | ||
| beforeEach(resetRebuildFlowTestEnvironment); | ||
| afterEach(restoreRebuildFlowTestEnvironment); | ||
|
|
||
| it("fails instead of reporting readiness when restored state leaves the gateway down (#7084)", async () => { | ||
| const mcpEntry = { | ||
| server: "blender", | ||
| providerName: "nemoclaw-mcp-alpha-blender", | ||
| }; | ||
| const harness = createRebuildFlowHarness({ | ||
| agentName: "hermes", | ||
| checkAndRecoverSandboxProcesses: () => ({ | ||
| checked: true, | ||
| wasRunning: false, | ||
| recovered: false, | ||
| forwardRecovered: false, | ||
| }), | ||
| mcpPreparation: { | ||
| entries: [mcpEntry], | ||
| detachedProviderEntries: [mcpEntry], | ||
| scrubbedAdapterEntries: [mcpEntry], | ||
| }, | ||
| sandboxEntry: { agent: "hermes" }, | ||
| }); | ||
| harness.restoreMcpBridgesAfterRebuildSpy.mockRejectedValueOnce( | ||
| new Error("gateway unavailable"), | ||
| ); | ||
|
|
||
| await expect( | ||
| harness.rebuildSandbox("alpha", ["--yes"], { throwOnError: true }), | ||
| ).rejects.toThrow("Hermes post-restore verification failed"); | ||
|
|
||
| const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n"); | ||
| expect(output).toContain("rebuilt but some post-restore steps were incomplete"); | ||
| expect(output).toContain("Hermes gateway health was not verified after state restore"); | ||
| expect(output).toContain("MCP bridge definitions were preserved but not fully refreshed"); | ||
| expect(output).not.toContain("rebuilt successfully"); | ||
| expect(harness.restoreMcpBridgesAfterRebuildSpy).toHaveBeenCalledWith("alpha", [mcpEntry]); | ||
| }); | ||
|
|
||
| it("accepts restored MCP configuration only after final gateway recovery (#7084)", async () => { | ||
| const mcpEntry = { | ||
| server: "blender", | ||
| providerName: "nemoclaw-mcp-alpha-blender", | ||
| }; | ||
| const harness = createRebuildFlowHarness({ | ||
| agentName: "hermes", | ||
| checkAndRecoverSandboxProcesses: () => ({ | ||
| checked: true, | ||
| wasRunning: false, | ||
| recovered: true, | ||
| forwardRecovered: true, | ||
| }), | ||
| mcpPreparation: { | ||
| entries: [mcpEntry], | ||
| detachedProviderEntries: [mcpEntry], | ||
| scrubbedAdapterEntries: [mcpEntry], | ||
| }, | ||
| sandboxEntry: { agent: "hermes" }, | ||
| }); | ||
|
|
||
| await expect( | ||
| harness.rebuildSandbox("alpha", ["--yes"], { throwOnError: true }), | ||
| ).resolves.toBeUndefined(); | ||
|
|
||
| expect(harness.restoreMcpBridgesAfterRebuildSpy).toHaveBeenCalledWith("alpha", [mcpEntry]); | ||
| expect(harness.restoreMcpBridgesAfterRebuildSpy.mock.invocationCallOrder[0]).toBeLessThan( | ||
| harness.checkAndRecoverSandboxProcessesSpy.mock.invocationCallOrder[0], | ||
| ); | ||
| expect(harness.logSpy).toHaveBeenCalledWith( | ||
| expect.stringContaining("Hermes gateway recovered after state restore"), | ||
| ); | ||
| }); | ||
|
|
||
| it("returns a failed rebuild when managed Hermes MCP restoration is incomplete (#7084)", async () => { | ||
| const mcpEntry = { | ||
| server: "blender", | ||
| providerName: "nemoclaw-mcp-alpha-blender", | ||
| }; | ||
| const harness = createRebuildFlowHarness({ | ||
| agentName: "hermes", | ||
| mcpPreparation: { | ||
| entries: [mcpEntry], | ||
| detachedProviderEntries: [mcpEntry], | ||
| scrubbedAdapterEntries: [mcpEntry], | ||
| }, | ||
| sandboxEntry: { agent: "hermes" }, | ||
| }); | ||
| harness.restoreMcpBridgesAfterRebuildSpy.mockRejectedValueOnce(new Error("reload failed")); | ||
|
|
||
| await expect( | ||
| harness.rebuildSandbox("alpha", ["--yes"], { throwOnError: true }), | ||
| ).rejects.toThrow("Hermes post-restore verification failed"); | ||
|
|
||
| const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n"); | ||
| expect(output).toContain("MCP bridge definitions were preserved but not fully refreshed"); | ||
| expect(output).not.toContain("rebuilt successfully"); | ||
| }); | ||
|
|
||
| it("fails when the final gateway check refuses MCP reconciliation (#7084)", async () => { | ||
| const mcpEntry = { | ||
| server: "blender", | ||
| providerName: "nemoclaw-mcp-alpha-blender", | ||
| }; | ||
| const harness = createRebuildFlowHarness({ | ||
| agentName: "hermes", | ||
| checkAndRecoverSandboxProcesses: () => ({ | ||
| checked: true, | ||
| wasRunning: true, | ||
| recovered: false, | ||
| forwardRecovered: false, | ||
| mcpReconciliationRefused: true, | ||
| }), | ||
| mcpPreparation: { | ||
| entries: [mcpEntry], | ||
| detachedProviderEntries: [mcpEntry], | ||
| scrubbedAdapterEntries: [mcpEntry], | ||
| }, | ||
| sandboxEntry: { agent: "hermes" }, | ||
| }); | ||
|
|
||
| await expect( | ||
| harness.rebuildSandbox("alpha", ["--yes"], { throwOnError: true }), | ||
| ).rejects.toThrow("Hermes post-restore verification failed"); | ||
|
|
||
| expect(harness.restoreMcpBridgesAfterRebuildSpy).toHaveBeenCalledWith("alpha", [mcpEntry]); | ||
| expect(harness.logSpy).not.toHaveBeenCalledWith( | ||
| expect.stringContaining("rebuilt successfully"), | ||
| ); | ||
| }); | ||
|
|
||
| it("fails before recovery when recreated Hermes identity is missing (#7084)", async () => { | ||
| const harness = createRebuildFlowHarness({ | ||
| agentName: "hermes", | ||
| sessionAgentName: null, | ||
| sandboxEntry: { agent: "hermes" }, | ||
| }); | ||
|
|
||
| await expect( | ||
| harness.rebuildSandbox("alpha", ["--yes"], { throwOnError: true }), | ||
| ).rejects.toThrow( | ||
| "Recreated sandbox agent identity did not match the authoritative rebuild target", | ||
| ); | ||
|
|
||
| expect(harness.checkAndRecoverSandboxProcessesSpy).not.toHaveBeenCalled(); | ||
| expect(harness.restoreMcpBridgesAfterRebuildSpy).not.toHaveBeenCalled(); | ||
| expect(harness.logSpy).not.toHaveBeenCalledWith( | ||
| expect.stringContaining("rebuilt successfully"), | ||
| ); | ||
| }); | ||
|
|
||
| it("fails before recovery when recreated Hermes identity mismatches (#7084)", async () => { | ||
| const harness = createRebuildFlowHarness({ | ||
| agentName: "hermes", | ||
| sessionAgentName: "langchain-deepagents-code", | ||
| sandboxEntry: { agent: "hermes" }, | ||
| }); | ||
|
|
||
| await expect( | ||
| harness.rebuildSandbox("alpha", ["--yes"], { throwOnError: true }), | ||
| ).rejects.toThrow( | ||
| "Recreated sandbox agent identity did not match the authoritative rebuild target", | ||
| ); | ||
|
|
||
| expect(harness.checkAndRecoverSandboxProcessesSpy).not.toHaveBeenCalled(); | ||
| expect(harness.restoreMcpBridgesAfterRebuildSpy).not.toHaveBeenCalled(); | ||
| expect(harness.logSpy).not.toHaveBeenCalledWith( | ||
| expect.stringContaining("rebuilt successfully"), | ||
| ); | ||
| }); | ||
| }); | ||
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,67 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { CLI_NAME } from "../../cli/branding"; | ||
| import * as processRecovery from "./process-recovery"; | ||
|
|
||
| export type HermesPostRestoreGatewayState = | ||
| | "not-applicable" | ||
| | "healthy" | ||
| | "recovered" | ||
| | "unverified"; | ||
|
|
||
| type GatewayRecoveryObservation = { | ||
| checked: boolean; | ||
| wasRunning: boolean | null; | ||
| recovered: boolean; | ||
| forwardRecoveryFailed?: boolean; | ||
| secretBoundaryRefused?: boolean; | ||
| mcpReconciliationRefused?: boolean; | ||
| }; | ||
|
|
||
| interface HermesPostRestoreGatewayDeps { | ||
| checkAndRecoverSandboxProcesses?: ( | ||
| sandboxName: string, | ||
| options: { quiet: boolean }, | ||
| ) => GatewayRecoveryObservation; | ||
| } | ||
|
|
||
| /** | ||
| * Re-prove Hermes gateway health after workspace state restoration. | ||
| * | ||
| * Inner onboarding verifies the fresh image before rebuild restores the prior | ||
| * state. That restore can still stop or wedge the gateway, so its earlier | ||
| * readiness message is not authoritative for rebuild completion. | ||
| */ | ||
| export function ensureHermesGatewayAfterStateRestore( | ||
| sandboxName: string, | ||
| agentName: string, | ||
| deps: HermesPostRestoreGatewayDeps = {}, | ||
| ): HermesPostRestoreGatewayState { | ||
| if (agentName !== "hermes") return "not-applicable"; | ||
| const checkAndRecover = | ||
| deps.checkAndRecoverSandboxProcesses ?? processRecovery.checkAndRecoverSandboxProcesses; | ||
| const observation: GatewayRecoveryObservation = checkAndRecover(sandboxName, { quiet: true }); | ||
| if ( | ||
| !observation.checked || | ||
| observation.forwardRecoveryFailed === true || | ||
| observation.secretBoundaryRefused === true || | ||
| observation.mcpReconciliationRefused === true | ||
| ) { | ||
| return "unverified"; | ||
| } | ||
| if (observation.wasRunning === true) return "healthy"; | ||
| if (observation.recovered) return "recovered"; | ||
| return "unverified"; | ||
| } | ||
|
|
||
| export function printHermesGatewayRestoreRecovery( | ||
| sandboxName: string, | ||
| state: HermesPostRestoreGatewayState, | ||
| writeLine: (message: string) => void = console.log, | ||
| ): void { | ||
| if (state !== "unverified") return; | ||
| writeLine( | ||
| ` Hermes gateway health was not verified after state restore — run \`${CLI_NAME} ${sandboxName} recover\` before relying on this sandbox`, | ||
| ); | ||
| } |
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
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.