Skip to content
2 changes: 1 addition & 1 deletion agents/hermes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ RUN mkdir -p /sandbox/.nemoclaw/blueprints/0.1.0 \
RUN HERMES_HOME=/sandbox/.hermes /usr/local/bin/hermes doctor --fix \
&& node --experimental-strip-types /opt/nemoclaw-hermes-config/generate-config.ts \
&& if [ "$NEMOCLAW_MANAGED_IMAGE_CAPABILITY_UNION" = "1" ]; then \
/opt/hermes/.venv/bin/python -I -c 'import importlib.metadata as m, pathlib, yaml; config=yaml.safe_load(pathlib.Path("/sandbox/.hermes/config.yaml").read_text()); neutral={name: value for name, value in config["platforms"].items() if name != "api_server"}; assert len(neutral) == 30; assert all(value == {"enabled": False} for value in neutral.values()); assert m.version("microsoft-teams-apps") == "2.0.13.4"; assert m.version("aiohttp") == "3.14.1"'; \
/opt/hermes/.venv/bin/python -I -c 'import importlib.metadata as m, pathlib, yaml; config=yaml.safe_load(pathlib.Path("/sandbox/.hermes/config.yaml").read_text()); neutral={name: value for name, value in config["platforms"].items() if name != "api_server"}; assert len(neutral) == 30; assert all(value == {"enabled": False} for value in neutral.values()); assert m.version("microsoft-teams-apps") == "2.0.13.4"; assert m.version("aiohttp") == "3.14.3"'; \
GOOGLE_CHAT_PROJECT_ID=nemoclaw-hostile \
GOOGLE_CHAT_SUBSCRIPTION_NAME=projects/nemoclaw-hostile/subscriptions/nemoclaw-hostile \
GOOGLE_CHAT_SERVICE_ACCOUNT_JSON='{"type":"service_account","project_id":"nemoclaw-hostile"}' \
Expand Down
2 changes: 1 addition & 1 deletion ci/source-architecture-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"src/lib/cli/nemoclaw-oclif-command.ts": 103,
"src/lib/cli/terminal-style.ts": 45,
"src/lib/core/json-types.ts": 37,
"src/lib/core/ports.ts": 89,
"src/lib/core/ports.ts": 88,
"src/lib/core/shell-quote.ts": 26,
"src/lib/core/url-utils.ts": 28,
"src/lib/core/wait.ts": 35,
Expand Down
4 changes: 1 addition & 3 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ const { getGatewayReuseSnapshot, selectNamedGatewayForReuseIfNeeded } =
});

// biome-ignore format: keep src/lib/onboard.ts net-neutral for growth guardrail.
const { getSandboxReuseState, getSandboxRecreateObservation, repairRecordedSandbox } = sandboxReuse.createSandboxReuseHelpers({ runCaptureOpenshell, runOpenshell, getSandboxStateFromOutputs, note, getGatewayName: () => GATEWAY_NAME });
const { getSandboxReuseState, getSandboxRecreateObservation } = sandboxReuse.createSandboxReuseHelpers({ runCaptureOpenshell, getSandboxStateFromOutputs, getGatewayName: () => GATEWAY_NAME });

const {
executeSandboxCommandForVerification,
Expand Down Expand Up @@ -4380,7 +4380,6 @@ async function runOnboard(opts: OnboardOptions = {}): Promise<void> {
stringSetsEqual,
removeSandboxFromRegistry: registry.removeSandboxWithReceipt.bind(registry),
restoreSandboxRegistryEntryIfMissing: registry.restoreSandboxEntryIfMissing.bind(registry),
repairRecordedSandbox,
ensureValidatedWebSearchCredential,
isBackToSelection,
configureWebSearch,
Expand Down Expand Up @@ -4653,7 +4652,6 @@ module.exports = {
parseSandboxStatus,
preflightAuthoritativeRebuildTarget,
pruneStaleSandboxEntry,
repairRecordedSandbox,
recoverGatewayRuntime,
buildChain,
buildControlUiUrls,
Expand Down
1 change: 0 additions & 1 deletion src/lib/onboard/machine/core-flow-phases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ function createPhases(
left.length === right.length && left.every((item) => right.includes(item)),
removeSandboxFromRegistry: vi.fn(() => null),
restoreSandboxRegistryEntryIfMissing: vi.fn(() => false),
repairRecordedSandbox: vi.fn(),
ensureValidatedWebSearchCredential: vi.fn(async () => null),
isBackToSelection: () => false,
configureWebSearch: vi.fn(async () => null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describe("sandbox create intent machine boundary", () => {
expect(resolveSandboxCreateIntent).toHaveBeenCalledTimes(1);
expect(calls.startStep).not.toHaveBeenCalled();
expect(calls.removeSandbox).not.toHaveBeenCalled();
expect(calls.repairSandbox).not.toHaveBeenCalled();
expect(calls.createSandbox).not.toHaveBeenCalled();
});

Expand Down
23 changes: 9 additions & 14 deletions src/lib/onboard/machine/handlers/sandbox-dcode-selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe("handleSandboxState live DCode selection", () => {
);
});

it("repairs a not-ready DCode sandbox before recreating for mode drift (#6478)", async () => {
it("rejects not-ready DCode repair without journal authority (#6478)", async () => {
const session = completedSession();
const { deps, calls } = createDeps({
getSandboxReuseState: () => "not_ready",
Expand All @@ -133,20 +133,15 @@ describe("handleSandboxState live DCode selection", () => {
}),
});

await handleSandboxState({
...dcodeOptions(deps),
requestedDcodeAutoApprovalMode: "thread-opt-in",
});
await expect(
handleSandboxState({
...dcodeOptions(deps),
requestedDcodeAutoApprovalMode: "thread-opt-in",
}),
).rejects.toThrow("journal-bound recreate transaction");

expect(calls.repairSandbox).toHaveBeenCalledWith("saved");
expect(calls.repairEvent).toHaveBeenCalledWith("state.repair.completed", {
state: "sandbox",
metadata: { repair: "recorded-sandbox-cleanup", sandboxName: "saved" },
});
expect(calls.createSandbox.mock.calls[0]?.at(-1)).toMatchObject({
recreate: true,
dcodeAutoApprovalMode: "thread-opt-in",
});
expect(calls.repairEvent).not.toHaveBeenCalled();
expect(calls.createSandbox).not.toHaveBeenCalled();
});

it("rejects malformed recorded DCode auto-approval state (#6478)", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ it("journals not-ready repair on the selected non-default gateway (#6492)", asyn
gatewayName: "nemoclaw-31818",
});

expect(calls.repairSandbox).not.toHaveBeenCalled();
expect(createSandbox).toHaveBeenCalledOnce();
const createIntent = createSandbox.mock.calls[0]?.at(-1);
expect(createIntent).toMatchObject({
Expand Down Expand Up @@ -388,6 +387,5 @@ it("rejects an active recreate journal on a different gateway authority (#6492)"
).rejects.toThrow(/journaled gateway.*does not match the selected gateway authority/i);
expect(getSandboxRecreateObservation).not.toHaveBeenCalled();
expect(calls.createSandbox).not.toHaveBeenCalled();
expect(calls.repairSandbox).not.toHaveBeenCalled();
expect(calls.removeSandbox).not.toHaveBeenCalled();
});
13 changes: 11 additions & 2 deletions src/lib/onboard/machine/handlers/sandbox-resume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ function resumeDeps(overrides: Partial<SandboxResumeDeps> = {}): SandboxResumeDe
return {
note: vi.fn(),
removeSandboxFromRegistry: vi.fn(() => null),
repairRecordedSandbox: vi.fn(),
recordRepairEvent: vi.fn(async () => undefined),
...overrides,
};
}
Expand Down Expand Up @@ -256,4 +254,15 @@ describe("applySandboxResumeDecision (#7194)", () => {
expect(await applySandboxResumeDecision({ kind: "reuse" }, "saved", deps)).toBeNull();
expect(deps.removeSandboxFromRegistry).not.toHaveBeenCalled();
});

it("rejects not-ready repair without a journal-bound recreate transaction", async () => {
const deps = resumeDeps();

await expect(
applySandboxResumeDecision({ kind: "repair-and-recreate" }, "saved", deps),
).rejects.toThrow("journal-bound recreate transaction");

expect(deps.note).not.toHaveBeenCalled();
expect(deps.removeSandboxFromRegistry).not.toHaveBeenCalled();
});
});
34 changes: 3 additions & 31 deletions src/lib/onboard/machine/handlers/sandbox-resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,6 @@ export function mcpRegistryRemovalBlockReason(
export interface SandboxResumeDeps {
note(message: string): void;
removeSandboxFromRegistry(sandboxName: string): SandboxRemovalReceipt | null;
repairRecordedSandbox(sandboxName: string | null): void;
recordRepairEvent(
type: "state.repair.started" | "state.repair.completed" | "state.repair.failed",
options?: {
state?: "sandbox";
error?: string | null;
metadata?: Record<string, unknown> | null;
},
): Promise<unknown>;
}

function canReuseSandbox(signals: SandboxResumeSignals): boolean {
Expand Down Expand Up @@ -295,26 +286,6 @@ export function decideSandboxResume(signals: SandboxResumeSignals): SandboxResum
};
}

async function repairRecordedSandbox(
sandboxName: string | null,
deps: SandboxResumeDeps,
): Promise<void> {
deps.note(` [resume] Recorded sandbox '${sandboxName}' exists but is not ready; recreating it.`);
const metadata = { repair: "recorded-sandbox-cleanup", sandboxName };
await deps.recordRepairEvent("state.repair.started", { state: "sandbox", metadata });
try {
deps.repairRecordedSandbox(sandboxName);
} catch (error) {
await deps.recordRepairEvent("state.repair.failed", {
state: "sandbox",
error: error instanceof Error ? error.message : String(error),
metadata,
});
throw error;
}
await deps.recordRepairEvent("state.repair.completed", { state: "sandbox", metadata });
}

/**
* Apply a resume decision and return the removal receipt (if any) so the
* caller can restore the durable registry row, including its baseline
Expand All @@ -326,8 +297,9 @@ export async function applySandboxResumeDecision(
deps: SandboxResumeDeps,
): Promise<SandboxRemovalReceipt | null> {
if (decision.kind === "repair-and-recreate") {
await repairRecordedSandbox(sandboxName, deps);
return null;
throw new Error(
"Cannot repair a recorded not-ready sandbox without a journal-bound recreate transaction.",
);
}
if (decision.kind !== "recreate") return null;
deps.note(decision.note);
Expand Down
20 changes: 18 additions & 2 deletions src/lib/onboard/machine/handlers/sandbox-test-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { vi } from "vitest";

import type { SandboxMessagingPlan } from "../../../messaging/manifest";
import { decisionSelected } from "../../../state/onboard-checkpoint-decision";
import { deriveCheckpointFromSession } from "../../../state/onboard-checkpoint-migrate";
import type { CheckpointProviderBinding } from "../../../state/onboard-checkpoint-types";
import { createSession, type Session, type SessionUpdates } from "../../../state/onboard-session";
import type { BaselineExclusionEntry, SandboxRemovalReceipt } from "../../../state/registry";
Expand Down Expand Up @@ -84,6 +86,22 @@ type MessagingChannelConfig = Record<string, string>;
type SandboxGpuConfig = { sandboxGpuEnabled: boolean; mode: string };
type ResourceProfile = { cpu: string; memory: string };

export function selectTestGatewayAuthority(session: Session): void {
session.checkpoint = {
...deriveCheckpointFromSession(session),
gatewayAuthority: decisionSelected({
gatewayName: "nemoclaw",
gatewayPort: 8080,
mode: "nemoclaw-managed",
source: "standalone",
endpoint: null,
stateDir: null,
supervisor: null,
requiredCapabilities: [],
}),
};
}

export function createDeps(
overrides: Partial<
SandboxStateOptions<
Expand All @@ -109,7 +127,6 @@ export function createDeps(
clearPlanEnv: vi.fn(),
removeSandbox: vi.fn((): SandboxRemovalReceipt | null => null),
restoreSandboxRegistryEntryIfMissing: vi.fn(() => false),
repairSandbox: vi.fn(),
validateBrave: vi.fn(async () => "brave-key"),
isBackToSelection: vi.fn(() => false),
configureWebSearch: vi.fn(async () => null as WebSearchConfig | null),
Expand Down Expand Up @@ -230,7 +247,6 @@ export function createDeps(
left.length === right.length && left.every((value) => right.includes(value)),
removeSandboxFromRegistry: calls.removeSandbox,
restoreSandboxRegistryEntryIfMissing: calls.restoreSandboxRegistryEntryIfMissing,
repairRecordedSandbox: calls.repairSandbox,
ensureValidatedWebSearchCredential: calls.validateBrave,
isBackToSelection: calls.isBackToSelection,
configureWebSearch: calls.configureWebSearch,
Expand Down
83 changes: 34 additions & 49 deletions src/lib/onboard/machine/handlers/sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
baseOptions,
createDeps,
makeMinimalPlan,
selectTestGatewayAuthority,
withEnv,
withTelegramCredentialHash,
} from "./sandbox-test-fixtures";
Expand Down Expand Up @@ -849,13 +850,21 @@ describe("handleSandboxState", () => {
it("marks web search changed when recreate implicitly enables Tavily", async () => {
const session = createSession({ sandboxName: "saved" });
session.steps.sandbox.status = "complete";
const { deps } = createDeps({
getSandboxReuseState: () => "not_ready",
configureWebSearch: vi.fn(async () => ({
fetchEnabled: true as const,
provider: "tavily" as const,
})),
});
selectTestGatewayAuthority(session);
const { deps } = createDeps(
{
getSandboxReuseState: () => "not_ready",
getSandboxRecreateObservation: () => ({
state: "not_ready",
liveIdentityFingerprint: "a".repeat(64),
}),
configureWebSearch: vi.fn(async () => ({
fetchEnabled: true as const,
provider: "tavily" as const,
})),
},
session,
);

const result = await handleSandboxState({
...baseOptions(deps, session),
Expand Down Expand Up @@ -890,49 +899,17 @@ describe("handleSandboxState", () => {
expect(calls.createSandbox).toHaveBeenCalled();
});

it("repairs not-ready resumed sandboxes before recreation", async () => {
it("fails closed when not-ready repair lacks a journal-bound source", async () => {
const session = createSession({ sandboxName: "saved" });
session.steps.sandbox.status = "complete";
const { deps, calls } = createDeps({ getSandboxReuseState: () => "not_ready" });

await handleSandboxState({ ...baseOptions(deps, session), resume: true, sandboxName: "saved" });

expect(calls.repairEvent).toHaveBeenCalledWith("state.repair.started", {
state: "sandbox",
metadata: { repair: "recorded-sandbox-cleanup", sandboxName: "saved" },
});
expect(calls.repairSandbox).toHaveBeenCalledWith("saved");
expect(calls.repairEvent).toHaveBeenCalledWith("state.repair.completed", {
state: "sandbox",
metadata: { repair: "recorded-sandbox-cleanup", sandboxName: "saved" },
});
expect(calls.createSandbox).toHaveBeenCalled();
});

it("records failed sandbox repair events before propagating repair errors", async () => {
const session = createSession({ sandboxName: "saved" });
session.steps.sandbox.status = "complete";
const { deps, calls } = createDeps({
getSandboxReuseState: () => "not_ready",
repairRecordedSandbox: vi.fn(() => {
throw new Error("cleanup failed");
}),
});

await expect(
handleSandboxState({ ...baseOptions(deps, session), resume: true, sandboxName: "saved" }),
).rejects.toThrow("cleanup failed");
).rejects.toThrow("journal-bound recreate transaction");

expect(calls.repairEvent).toHaveBeenCalledWith("state.repair.started", {
state: "sandbox",
metadata: { repair: "recorded-sandbox-cleanup", sandboxName: "saved" },
});
expect(calls.repairEvent).toHaveBeenCalledWith("state.repair.failed", {
state: "sandbox",
error: "cleanup failed",
metadata: { repair: "recorded-sandbox-cleanup", sandboxName: "saved" },
});
expect(calls.repairEvent).not.toHaveBeenCalledWith("state.repair.completed", expect.anything());
expect(calls.repairEvent).not.toHaveBeenCalled();
expect(calls.removeSandbox).not.toHaveBeenCalled();
expect(calls.createSandbox).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -1056,7 +1033,6 @@ describe("handleSandboxState", () => {
).rejects.toThrow("Tavily credential rejected");

expect(calls.removeSandbox).not.toHaveBeenCalled();
expect(calls.repairSandbox).not.toHaveBeenCalled();
expect(calls.createSandbox).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -1110,12 +1086,20 @@ describe("handleSandboxState", () => {
webSearchConfig: { fetchEnabled: true },
});
session.steps.sandbox.status = "complete";
selectTestGatewayAuthority(session);
const backToSelection = Object.freeze({ kind: "NEMOCLAW_BACK_TO_SELECTION" });
const { deps, calls } = createDeps({
getSandboxReuseState: () => "not_ready",
ensureValidatedWebSearchCredential: vi.fn(async () => backToSelection),
isBackToSelection: vi.fn((value: unknown) => value === backToSelection),
});
const { deps, calls } = createDeps(
{
getSandboxReuseState: () => "not_ready",
getSandboxRecreateObservation: () => ({
state: "not_ready",
liveIdentityFingerprint: "a".repeat(64),
}),
ensureValidatedWebSearchCredential: vi.fn(async () => backToSelection),
isBackToSelection: vi.fn((value: unknown) => value === backToSelection),
},
session,
);

const result = await handleSandboxState({
...baseOptions(deps, session),
Expand Down Expand Up @@ -1143,6 +1127,7 @@ describe("handleSandboxState", () => {
{
resolved: expect.any(Object),
recreate: true,
recreateTransaction: expect.any(Object),
toolDisclosure: "progressive",
observabilityEnabled: false,
endpointSource: null,
Expand Down
1 change: 0 additions & 1 deletion src/lib/onboard/machine/handlers/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ export interface SandboxStateOptions<
stringSetsEqual(left: string[], right: string[]): boolean;
removeSandboxFromRegistry(sandboxName: string): SandboxRemovalReceipt | null;
restoreSandboxRegistryEntryIfMissing(receipt: SandboxRemovalReceipt): boolean;
repairRecordedSandbox(sandboxName: string | null): void;
ensureValidatedWebSearchCredential(config: WebSearchConfig): Promise<unknown>;
isBackToSelection(value: unknown): boolean;
configureWebSearch(
Expand Down
Loading
Loading