From 9c7961895336621199285f894b1535693d59066a Mon Sep 17 00:00:00 2001 From: Yanyun Liao Date: Mon, 26 Oct 2026 11:53:03 +0800 Subject: [PATCH 1/3] fix(onboard): keep custom route metadata in the review checkpoint Before the configuration review, onboarding records the selected provider and model so an interrupted review can resume. It did not record the endpoint URL, API family, or credential variable name. After Ctrl-C at the review of an OpenAI-compatible endpoint, resume checked the saved route against the shared gateway route, found an incomplete custom route, and exited 1 with a remove-and-re-onboard hint although no sandbox existed. Record the same secret-free route identity that the resume gate checks. Exit onboarding still clears these fields. Fixes #13654 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Yanyun Liao --- docs/reference/commands.mdx | 2 +- .../handlers/provider-inference.test.ts | 3 + .../machine/handlers/provider-inference.ts | 17 +- .../handlers/provider-review-recovery.test.ts | 176 ++++++++++++++++++ src/lib/onboard/runtime-boundary.test.ts | 15 +- src/lib/onboard/runtime-boundary.ts | 3 + src/lib/state/onboard-session.test.ts | 2 + 7 files changed, 212 insertions(+), 6 deletions(-) diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index b3f05053427..0103d5f8554 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -539,7 +539,7 @@ The host observes through any same-device pending state and verifies the final s -Before the configuration review, NemoClaw records the sandbox name and the selected provider and model as an incomplete choice. If onboarding stops at the review prompt, an interactive `--resume` run shows the prompt again. A non-interactive `--resume` run reuses the recorded choice and continues to inference setup. After you choose **Apply configuration**, NemoClaw records the choice before inference setup starts. If inference setup fails, `--resume` reuses the accepted provider, model, and sandbox name. If you choose **Exit onboarding**, onboarding exits with a nonzero status and clears those recorded choices. Run `$$nemoclaw onboard` to make new choices after exit. During a resume without terminal input, `--yes` or `NEMOCLAW_YES=1` also selects non-interactive resume behavior. For a new or fresh session, `--yes` and `NEMOCLAW_YES=1` accept supported confirmations but do not replace `--non-interactive`. If onboarding returns without reaching the final `complete` state, the command exits with status `1`. When that result is resumable, NemoClaw keeps the session `in_progress` at its last checkpoint instead of marking it failed, so correct the reported condition and run `$$nemoclaw onboard --resume`. +Before the configuration review, NemoClaw records the sandbox name and the selected provider and model as an incomplete choice. For a custom endpoint, the choice also includes the endpoint URL, the API family, and the name of the credential environment variable, but not the credential value. If onboarding stops at the review prompt, an interactive `--resume` run shows the prompt again. A non-interactive `--resume` run reuses the recorded choice and continues to inference setup. After you choose **Apply configuration**, NemoClaw records the choice before inference setup starts. If inference setup fails, `--resume` reuses the accepted provider, model, and sandbox name. If you choose **Exit onboarding**, onboarding exits with a nonzero status and clears those recorded choices. Run `$$nemoclaw onboard` to make new choices after exit. During a resume without terminal input, `--yes` or `NEMOCLAW_YES=1` also selects non-interactive resume behavior. For a new or fresh session, `--yes` and `NEMOCLAW_YES=1` accept supported confirmations but do not replace `--non-interactive`. If onboarding returns without reaching the final `complete` state, the command exits with status `1`. When that result is resumable, NemoClaw keeps the session `in_progress` at its last checkpoint instead of marking it failed, so correct the reported condition and run `$$nemoclaw onboard --resume`. diff --git a/src/lib/onboard/machine/handlers/provider-inference.test.ts b/src/lib/onboard/machine/handlers/provider-inference.test.ts index 38ded54f286..b9c7d1284dd 100644 --- a/src/lib/onboard/machine/handlers/provider-inference.test.ts +++ b/src/lib/onboard/machine/handlers/provider-inference.test.ts @@ -69,6 +69,9 @@ describe("handleProviderInferenceState", () => { expect(calls.startStep).toHaveBeenNthCalledWith(2, "provider_selection", { provider: "nvidia-prod", model: "nvidia/test", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "NVIDIA_INFERENCE_API_KEY", + preferredInferenceApi: "openai-responses", }); expect(calls.startStep).toHaveBeenNthCalledWith(3, "inference", { provider: "nvidia-prod", diff --git a/src/lib/onboard/machine/handlers/provider-inference.ts b/src/lib/onboard/machine/handlers/provider-inference.ts index f9c3f3bf18e..38ae6ed72a6 100644 --- a/src/lib/onboard/machine/handlers/provider-inference.ts +++ b/src/lib/onboard/machine/handlers/provider-inference.ts @@ -273,7 +273,13 @@ export interface ProviderInferenceStateOptions { ) => Promise; startRecordedStep( stepName: string, - updates?: { provider?: string | null; model?: string | null }, + updates?: { + provider?: string | null; + model?: string | null; + endpointUrl?: string | null; + credentialEnv?: string | null; + preferredInferenceApi?: string | null; + }, ): Promise; recordStepComplete(stepName: string, updates: SessionUpdates): Promise; recordStepRejected(stepName: string): Promise; @@ -1230,7 +1236,9 @@ interface ConfigurationReviewInput { agent: Agent; provider: string; model: string; + endpointUrl: string | null; credentialEnv: string | null; + preferredInferenceApi: string | null; hermesAuthMethod: HermesAuthMethod | null; webSearchConfig: WebSearchConfig | null; hermesToolGateways: string[]; @@ -1269,9 +1277,14 @@ async function reviewProviderConfiguration( // claiming that provider registration or inference setup completed. await deps.checkpointSandboxIdentity(sandboxName, input.agent); if (needsSelectionRecovery && !selectionRecoveryStarted) { + // Resume checks this route against the shared gateway route before it + // shows the review again, so keep the same secret-free route identity. await deps.startRecordedStep("provider_selection", { provider: input.provider, model: input.model, + endpointUrl: input.endpointUrl, + credentialEnv: input.credentialEnv, + preferredInferenceApi: input.preferredInferenceApi, }); selectionRecoveryStarted = true; } @@ -2255,7 +2268,9 @@ export async function handleProviderInferenceState({ agent, provider, model, + endpointUrl, credentialEnv, + preferredInferenceApi, hermesAuthMethod, webSearchConfig, hermesToolGateways, diff --git a/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts b/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts index 77b039979b6..ec4df0e6c08 100644 --- a/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts +++ b/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts @@ -3,6 +3,10 @@ import { describe, expect, it, vi } from "vitest"; +import { + checkGatewayRouteCompatibility, + type CurrentGatewayRouteCompatibilityCheck, +} from "../../../inference/gateway-route-compatibility"; import { createSession, type SessionUpdates } from "../../../state/onboard-session"; import { createProviderReviewDeps } from "../../setup-inference"; import { handleProviderInferenceState } from "./provider-inference"; @@ -24,6 +28,9 @@ describe("provider inference review recovery", () => { expect(calls.startStep).toHaveBeenCalledWith("provider_selection", { provider: "nvidia-prod", model: "nvidia/test", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "NVIDIA_INFERENCE_API_KEY", + preferredInferenceApi: "openai-responses", }); expect(calls.rejected).toHaveBeenCalledWith("provider_selection"); expect(calls.exit).toHaveBeenCalledWith(1); @@ -220,6 +227,9 @@ describe("provider inference review recovery", () => { expect(calls.startStep).toHaveBeenCalledWith("provider_selection", { provider: "nvidia-prod", model: "nvidia/test", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "NVIDIA_INFERENCE_API_KEY", + preferredInferenceApi: "openai-responses", }); expect(calls.resolveHostLocalInferenceStartupSelection).not.toHaveBeenCalled(); expect(calls.prepareLocalProviderForInference).not.toHaveBeenCalled(); @@ -261,6 +271,9 @@ describe("provider inference review recovery", () => { expect(calls.startStep).toHaveBeenCalledWith("provider_selection", { provider: "ollama-local", model: "qwen3.5:9b", + endpointUrl: "http://127.0.0.1:11435/v1", + credentialEnv: null, + preferredInferenceApi: "openai-responses", }); expect(calls.prepareLocalProviderForInference).not.toHaveBeenCalled(); expect(calls.setupInference).not.toHaveBeenCalled(); @@ -312,6 +325,9 @@ describe("provider inference review recovery", () => { expect(calls.startStep).toHaveBeenCalledWith("provider_selection", { provider: "nvidia-prod", model: "nvidia/test", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "NVIDIA_INFERENCE_API_KEY", + preferredInferenceApi: "openai-responses", }); expect(calls.setupInference).toHaveBeenCalled(); }); @@ -394,4 +410,164 @@ describe("provider inference review recovery", () => { model: "qwen3.5:9b", }); }); + + describe("compatible-endpoint route metadata (#13654)", () => { + const compatibleSelection = { + ...baseSelection, + provider: "compatible-endpoint", + model: "nvidia/nemotron-3.5-super-vl-120b-a12b", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }; + + function interruptedCompatibleSession( + route: { endpointUrl: string | null; preferredInferenceApi: string | null } = { + endpointUrl: compatibleSelection.endpointUrl, + preferredInferenceApi: compatibleSelection.preferredInferenceApi, + }, + ) { + const session = createSession({ + sandboxName: "dcode-resume", + provider: compatibleSelection.provider, + model: compatibleSelection.model, + endpointUrl: route.endpointUrl, + credentialEnv: route.endpointUrl ? compatibleSelection.credentialEnv : null, + preferredInferenceApi: route.preferredInferenceApi, + sandboxPromptProgress: { + sandboxName: true, + webSearch: false, + messaging: false, + resourceProfile: false, + }, + }); + session.steps.provider_selection.status = "failed"; + return session; + } + + // The real check with no other registered sandbox: the only way to fail + // is a requested custom route without endpoint or API-family metadata. + const checkRouteOnEmptyGateway = vi.fn((request) => + checkGatewayRouteCompatibility({ ...request, sandboxes: [] }), + ); + + it("checkpoints the endpoint, API family, and credential name before review", async () => { + const prompt = vi.fn(async (): Promise => { + throw new Error("interrupted at review"); + }); + const { deps, calls } = createDeps({ + isNonInteractive: () => false, + setupNim: vi.fn(async () => ({ ...compatibleSelection })), + prompt, + }); + + await expect( + handleProviderInferenceState({ ...baseOptions(deps), sandboxName: "dcode-resume" }), + ).rejects.toThrow("interrupted at review"); + + expect(calls.startStep).toHaveBeenCalledWith("provider_selection", { + provider: "compatible-endpoint", + model: "nvidia/nemotron-3.5-super-vl-120b-a12b", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }); + expect(calls.startStep.mock.invocationCallOrder.at(-1)).toBeLessThan( + prompt.mock.invocationCallOrder[0], + ); + expect(calls.setupInference).not.toHaveBeenCalled(); + }); + + it("shows the review again on interactive resume of the interrupted selection", async () => { + const prompt = vi.fn(async () => "1"); + const { deps, calls } = createDeps({ + isNonInteractive: () => false, + prompt, + checkGatewayRouteCompatibility: checkRouteOnEmptyGateway, + isInferenceRouteReady: vi.fn(() => false), + }); + + await handleProviderInferenceState({ + ...baseOptions(deps, interruptedCompatibleSession()), + resume: true, + sandboxName: "dcode-resume", + }); + + expect(checkRouteOnEmptyGateway).toHaveBeenCalledWith( + expect.objectContaining({ + route: expect.objectContaining({ + provider: "compatible-endpoint", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }), + }), + ); + expect(calls.exit).not.toHaveBeenCalled(); + expect(calls.setupNim).not.toHaveBeenCalled(); + expect(prompt).toHaveBeenCalledOnce(); + expect(calls.setupInference).toHaveBeenCalledWith( + "dcode-resume", + "nvidia/nemotron-3.5-super-vl-120b-a12b", + "compatible-endpoint", + "https://integrate.api.nvidia.com/v1", + "COMPATIBLE_API_KEY", + null, + [], + expect.any(Object), + ); + }); + + it("continues to inference setup on non-interactive resume of the interrupted selection", async () => { + const prompt = vi.fn(async () => "1"); + const { deps, calls } = createDeps({ + isNonInteractive: () => true, + prompt, + checkGatewayRouteCompatibility: checkRouteOnEmptyGateway, + isInferenceRouteReady: vi.fn(() => false), + }); + + await handleProviderInferenceState({ + ...baseOptions(deps, interruptedCompatibleSession()), + resume: true, + sandboxName: "dcode-resume", + }); + + expect(calls.exit).not.toHaveBeenCalled(); + expect(prompt).not.toHaveBeenCalled(); + expect(calls.setupInference).toHaveBeenCalledWith( + "dcode-resume", + "nvidia/nemotron-3.5-super-vl-120b-a12b", + "compatible-endpoint", + "https://integrate.api.nvidia.com/v1", + "COMPATIBLE_API_KEY", + null, + [], + expect.any(Object), + ); + }); + + it("still refuses a session saved without that metadata", async () => { + const prompt = vi.fn(async () => "1"); + const { deps, calls } = createDeps({ + isNonInteractive: () => false, + prompt, + checkGatewayRouteCompatibility: checkRouteOnEmptyGateway, + }); + + await expect( + handleProviderInferenceState({ + ...baseOptions( + deps, + interruptedCompatibleSession({ endpointUrl: null, preferredInferenceApi: null }), + ), + resume: true, + sandboxName: "dcode-resume", + }), + ).rejects.toThrow("exit 1"); + + expect(prompt).not.toHaveBeenCalled(); + expect(calls.setupInference).not.toHaveBeenCalled(); + }); + }); }); diff --git a/src/lib/onboard/runtime-boundary.test.ts b/src/lib/onboard/runtime-boundary.test.ts index 64a4605bbf4..3cb477d08eb 100644 --- a/src/lib/onboard/runtime-boundary.test.ts +++ b/src/lib/onboard/runtime-boundary.test.ts @@ -200,18 +200,25 @@ describe("OnboardRuntimeBoundary", () => { await boundary.startRecordedStep("provider_selection", { sandboxName: "review-interrupted", - provider: "ollama-local", - model: "qwen3.5:9b", + provider: "compatible-endpoint", + model: "nvidia/nemotron-3.5-super-vl-120b-a12b", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", }); await boundary.recordStepFailed( "provider_selection", "Onboarding exited before the step completed.", ); + // #13654: resume needs the custom route identity, not only provider/model. expect(harness.getSession()).toMatchObject({ sandboxName: "review-interrupted", - provider: "ollama-local", - model: "qwen3.5:9b", + provider: "compatible-endpoint", + model: "nvidia/nemotron-3.5-super-vl-120b-a12b", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", steps: { provider_selection: { status: "failed" } }, }); }); diff --git a/src/lib/onboard/runtime-boundary.ts b/src/lib/onboard/runtime-boundary.ts index 98cb0b017e4..4a6059b80d6 100644 --- a/src/lib/onboard/runtime-boundary.ts +++ b/src/lib/onboard/runtime-boundary.ts @@ -73,6 +73,9 @@ export class OnboardRuntimeBoundary { sandboxName?: string | null; provider?: string | null; model?: string | null; + endpointUrl?: string | null; + credentialEnv?: string | null; + preferredInferenceApi?: string | null; } = {}, ): Promise { const runtime = this.getRuntime(); diff --git a/src/lib/state/onboard-session.test.ts b/src/lib/state/onboard-session.test.ts index e6810d28d39..ad05c50ff13 100644 --- a/src/lib/state/onboard-session.test.ts +++ b/src/lib/state/onboard-session.test.ts @@ -263,6 +263,7 @@ describe("onboard session", () => { model: "qwen3.5:9b", endpointUrl: "http://127.0.0.1:11435/v1", credentialEnv: "NEMOCLAW_OLLAMA_PROXY_TOKEN", + preferredInferenceApi: "openai-completions", sandboxName: "rejected-review", sandboxPromptProgress: { sandboxName: true, @@ -300,6 +301,7 @@ describe("onboard session", () => { model: null, endpointUrl: null, credentialEnv: null, + preferredInferenceApi: null, sandboxName: null, sandboxPromptProgress: { sandboxName: false }, lastStepStarted: null, From f5092c1b4432102426899ea70c32aacd1728115e Mon Sep 17 00:00:00 2001 From: Yanyun Liao Date: Tue, 27 Oct 2026 09:42:16 +0800 Subject: [PATCH 2/3] test(onboard): cover review resume for the other custom-route providers compatible-anthropic-endpoint goes through the same shared-route check as compatible-endpoint, so pin that its review checkpoint keeps the endpoint, API family, and credential name and that resume shows the review again. llama-cpp-local resumes through the native-local discovery preflight; pin its checkpoint metadata and that path. Refs #13654 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Yanyun Liao --- .../handlers/provider-review-recovery.test.ts | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts b/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts index ec4df0e6c08..60b653ef7a9 100644 --- a/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts +++ b/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts @@ -7,6 +7,10 @@ import { checkGatewayRouteCompatibility, type CurrentGatewayRouteCompatibilityCheck, } from "../../../inference/gateway-route-compatibility"; +import { + LLAMA_CPP_CREDENTIAL_ENV, + LLAMA_CPP_HOST_OPENAI_BASE_URL, +} from "../../../inference/llama-cpp/contract"; import { createSession, type SessionUpdates } from "../../../state/onboard-session"; import { createProviderReviewDeps } from "../../setup-inference"; import { handleProviderInferenceState } from "./provider-inference"; @@ -570,4 +574,137 @@ describe("provider inference review recovery", () => { expect(calls.setupInference).not.toHaveBeenCalled(); }); }); + + describe("compatible-anthropic-endpoint route metadata (#13654)", () => { + const anthropicRoute = { + provider: "compatible-anthropic-endpoint", + model: "claude-sonnet-proxy", + endpointUrl: "https://anthropic-proxy.example.test", + credentialEnv: "COMPATIBLE_ANTHROPIC_API_KEY", + preferredInferenceApi: "anthropic-messages", + }; + const checkRouteOnEmptyGateway = vi.fn((request) => + checkGatewayRouteCompatibility({ ...request, sandboxes: [] }), + ); + + it("checkpoints the endpoint, API family, and credential name before review", async () => { + const prompt = vi.fn(async (): Promise => { + throw new Error("interrupted at review"); + }); + const { deps, calls } = createDeps({ + isNonInteractive: () => false, + setupNim: vi.fn(async () => ({ ...baseSelection, ...anthropicRoute })), + prompt, + }); + + await expect( + handleProviderInferenceState({ ...baseOptions(deps), sandboxName: "anthropic-resume" }), + ).rejects.toThrow("interrupted at review"); + + expect(calls.startStep).toHaveBeenCalledWith("provider_selection", anthropicRoute); + expect(calls.setupInference).not.toHaveBeenCalled(); + }); + + it("shows the review again on interactive resume of the interrupted selection", async () => { + const prompt = vi.fn(async () => "1"); + const { deps, calls } = createDeps({ + isNonInteractive: () => false, + prompt, + checkGatewayRouteCompatibility: checkRouteOnEmptyGateway, + isInferenceRouteReady: vi.fn(() => false), + }); + const session = createSession({ + sandboxName: "anthropic-resume", + ...anthropicRoute, + sandboxPromptProgress: { + sandboxName: true, + webSearch: false, + messaging: false, + resourceProfile: false, + }, + }); + session.steps.provider_selection.status = "failed"; + + await handleProviderInferenceState({ + ...baseOptions(deps, session), + resume: true, + sandboxName: "anthropic-resume", + }); + + expect(checkRouteOnEmptyGateway).toHaveBeenCalledWith( + expect.objectContaining({ route: expect.objectContaining(anthropicRoute) }), + ); + expect(calls.exit).not.toHaveBeenCalled(); + expect(prompt).toHaveBeenCalledOnce(); + expect(calls.setupInference).toHaveBeenCalledWith( + "anthropic-resume", + anthropicRoute.model, + anthropicRoute.provider, + anthropicRoute.endpointUrl, + anthropicRoute.credentialEnv, + null, + [], + expect.any(Object), + ); + }); + }); + + // llama-cpp-local is native local inference for OpenClaw, so resume uses + // the native discovery preflight, not the shared custom-route check. + it("checkpoints llama-cpp-local route metadata and resumes through the native preflight (#13654)", async () => { + const llamaRoute = { + provider: "llama-cpp-local", + model: "local-gguf", + endpointUrl: LLAMA_CPP_HOST_OPENAI_BASE_URL, + credentialEnv: LLAMA_CPP_CREDENTIAL_ENV, + preferredInferenceApi: "openai-completions", + }; + const interrupted = createDeps({ + isNonInteractive: () => false, + setupNim: vi.fn(async () => ({ ...baseSelection, ...llamaRoute })), + prompt: vi.fn(async (): Promise => { + throw new Error("interrupted at review"); + }), + }); + await expect( + handleProviderInferenceState({ + ...baseOptions(interrupted.deps), + sandboxName: "llama-resume", + }), + ).rejects.toThrow("interrupted at review"); + expect(interrupted.calls.startStep).toHaveBeenCalledWith("provider_selection", llamaRoute); + + const prompt = vi.fn(async () => "1"); + const { deps, calls } = createDeps({ + isNonInteractive: () => false, + prompt, + isInferenceRouteReady: vi.fn(() => false), + }); + const session = createSession({ + sandboxName: "llama-resume", + ...llamaRoute, + sandboxPromptProgress: { + sandboxName: true, + webSearch: false, + messaging: false, + resourceProfile: false, + }, + }); + session.steps.provider_selection.status = "failed"; + + await handleProviderInferenceState({ + ...baseOptions(deps, session), + resume: true, + sandboxName: "llama-resume", + }); + + expect(calls.preflightGatewayRouteDiscovery).toHaveBeenCalledWith( + expect.objectContaining({ + route: expect.objectContaining(llamaRoute), + nativeLocalSelection: true, + }), + ); + expect(calls.exit).not.toHaveBeenCalled(); + expect(prompt).toHaveBeenCalledOnce(); + }); }); From ee8d0c92f0f455465701a52b158576464526ac65 Mon Sep 17 00:00:00 2001 From: Yanyun Liao Date: Tue, 27 Oct 2026 11:07:44 +0800 Subject: [PATCH 3/3] fix(onboard): recover review sessions saved without custom route metadata Write the started review step and its route context in one session mutation, so an interruption cannot keep provider_selection started without the endpoint, API family, and credential name. An interrupted review saved by an earlier release has a custom provider but no endpoint or API family. Interactive resume now asks for the provider and model again instead of failing at the gateway route check. Non-interactive resume keeps failing closed. Document both paths and the --fresh recovery. Refs #13654 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Yanyun Liao --- docs/reference/commands.mdx | 2 +- .../machine/handlers/provider-inference.ts | 22 +++++++++ .../handlers/provider-review-recovery.test.ts | 46 ++++++++++++++++- src/lib/onboard/machine/runtime.ts | 14 ++++-- src/lib/onboard/runtime-boundary.test.ts | 34 ++++++++++++- src/lib/onboard/runtime-boundary.ts | 6 +-- .../state/onboard-session-step-start.test.ts | 49 +++++++++++++++++++ src/lib/state/onboard-session.ts | 6 ++- 8 files changed, 167 insertions(+), 12 deletions(-) create mode 100644 src/lib/state/onboard-session-step-start.test.ts diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index d622c4b8be3..180c8316459 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -543,7 +543,7 @@ The host observes through any same-device pending state and verifies the final s -Before the configuration review, NemoClaw records the sandbox name and the selected provider and model as an incomplete choice. For a custom endpoint, the choice also includes the endpoint URL, the API family, and the name of the credential environment variable, but not the credential value. If onboarding stops at the review prompt, an interactive `--resume` run shows the prompt again. A non-interactive `--resume` run reuses the recorded choice and continues to inference setup. After you choose **Apply configuration**, NemoClaw records the choice before inference setup starts. If inference setup fails, `--resume` reuses the accepted provider, model, and sandbox name. If you choose **Exit onboarding**, onboarding exits with a nonzero status and clears those recorded choices. Run `$$nemoclaw onboard` to make new choices after exit. During a resume without terminal input, `--yes` or `NEMOCLAW_YES=1` also selects non-interactive resume behavior. For a new or fresh session, `--yes` and `NEMOCLAW_YES=1` accept supported confirmations but do not replace `--non-interactive`. If onboarding returns without reaching the final `complete` state, the command exits with status `1`. When that result is resumable, NemoClaw keeps the session `in_progress` at its last checkpoint instead of marking it failed, so correct the reported condition and run `$$nemoclaw onboard --resume`. +Before the configuration review, NemoClaw records the sandbox name and the selected provider and model as an incomplete choice. For a custom endpoint, the choice also includes the endpoint URL, the API family, and the name of the credential environment variable, but not the credential value. If onboarding stops at the review prompt, an interactive `--resume` run shows the prompt again. A custom-endpoint choice recorded by an earlier NemoClaw release has no endpoint URL or API family. An interactive `--resume` run asks you to choose the provider and model again. A non-interactive `--resume` run stops with an incomplete custom-route error. In that case, run `$$nemoclaw onboard --fresh` and make the selection again. No sandbox exists yet at this point, so you do not need to remove one. A non-interactive `--resume` run reuses the recorded choice and continues to inference setup. After you choose **Apply configuration**, NemoClaw records the choice before inference setup starts. If inference setup fails, `--resume` reuses the accepted provider, model, and sandbox name. If you choose **Exit onboarding**, onboarding exits with a nonzero status and clears those recorded choices. Run `$$nemoclaw onboard` to make new choices after exit. During a resume without terminal input, `--yes` or `NEMOCLAW_YES=1` also selects non-interactive resume behavior. For a new or fresh session, `--yes` and `NEMOCLAW_YES=1` accept supported confirmations but do not replace `--non-interactive`. If onboarding returns without reaching the final `complete` state, the command exits with status `1`. When that result is resumable, NemoClaw keeps the session `in_progress` at its last checkpoint instead of marking it failed, so correct the reported condition and run `$$nemoclaw onboard --resume`. diff --git a/src/lib/onboard/machine/handlers/provider-inference.ts b/src/lib/onboard/machine/handlers/provider-inference.ts index 534c8739794..07384205c23 100644 --- a/src/lib/onboard/machine/handlers/provider-inference.ts +++ b/src/lib/onboard/machine/handlers/provider-inference.ts @@ -15,6 +15,7 @@ import { type CurrentGatewayRouteCompatibilityCheck, type CurrentGatewayRouteDiscoveryPreflight, type GatewayRouteDiscoveryConstraints, + gatewayRouteIdentityConflictReasons, isAdvisoryGatewayRouteConflict, } from "../../../inference/gateway-route-compatibility"; import { withModelRouterPortLifecycleLock } from "../../../inference/gateway-route-mutation-lock"; @@ -1095,6 +1096,18 @@ function reviewRecoveryState(session: Session | null, sandboxName: string | null ); } +function hasIncompleteCustomRoute(session: Session | null): boolean { + if (!session) return false; + const route = { + provider: session.provider, + model: session.model, + endpointUrl: session.endpointUrl, + credentialEnv: session.credentialEnv, + preferredInferenceApi: session.preferredInferenceApi, + }; + return gatewayRouteIdentityConflictReasons(route, route).includes("incomplete-custom-route"); +} + function canResumeProviderSelection( forceProviderSelection: boolean, effectiveResume: boolean, @@ -1103,6 +1116,7 @@ function canResumeProviderSelection( interruptedReview: boolean, provider: string | null, model: string | null, + interactive: boolean, ): boolean { // An interrupted Station review has a provider/model but no validated model // identity yet. Retry selection so its checkpoint can bind that identity. @@ -1113,6 +1127,12 @@ function canResumeProviderSelection( ) { return false; } + // Review checkpoints from earlier releases kept only provider and model, so + // a custom route cannot pass the gateway check. Ask again interactively; + // non-interactive resume keeps failing closed at that check. + if (interactive && interruptedReview && hasIncompleteCustomRoute(session)) { + return false; + } return ( !forceProviderSelection && effectiveResume && @@ -1561,6 +1581,7 @@ export async function handleProviderInferenceState({ reviewRecoveryState(session, sandboxName), provider, model, + !deps.isNonInteractive(), ); const initialHostLocalPolicyRoute = resolveInitialHostLocalPolicyRoute({ resumeProviderSelection: initialResumeProviderSelection, @@ -1611,6 +1632,7 @@ export async function handleProviderInferenceState({ completeRecoveredReviewSelectionAfterInference, provider, model, + !deps.isNonInteractive(), ); const earlyManagedHostLocalLifecycleSelection = resolveEarlyManagedHostLocalLifecycleSelection({ resumeProviderSelection, diff --git a/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts b/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts index 60b653ef7a9..4f224753f25 100644 --- a/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts +++ b/src/lib/onboard/machine/handlers/provider-review-recovery.test.ts @@ -551,11 +551,55 @@ describe("provider inference review recovery", () => { ); }); - it("still refuses a session saved without that metadata", async () => { + it("asks for the provider again when an earlier release saved no route metadata", async () => { const prompt = vi.fn(async () => "1"); + const setupNim = vi.fn(async () => ({ ...compatibleSelection })); const { deps, calls } = createDeps({ isNonInteractive: () => false, prompt, + setupNim, + checkGatewayRouteCompatibility: checkRouteOnEmptyGateway, + isInferenceRouteReady: vi.fn(() => false), + }); + + await handleProviderInferenceState({ + ...baseOptions( + deps, + interruptedCompatibleSession({ endpointUrl: null, preferredInferenceApi: null }), + ), + resume: true, + sandboxName: "dcode-resume", + }); + + expect(calls.exit).not.toHaveBeenCalled(); + expect(setupNim).toHaveBeenCalledOnce(); + expect(calls.startStep).toHaveBeenCalledWith("provider_selection", { + provider: "compatible-endpoint", + model: "nvidia/nemotron-3.5-super-vl-120b-a12b", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }); + expect(calls.startStep.mock.invocationCallOrder.at(-1)).toBeLessThan( + calls.setupInference.mock.invocationCallOrder[0], + ); + expect(calls.setupInference).toHaveBeenCalledWith( + "dcode-resume", + "nvidia/nemotron-3.5-super-vl-120b-a12b", + "compatible-endpoint", + "https://integrate.api.nvidia.com/v1", + "COMPATIBLE_API_KEY", + null, + [], + expect.any(Object), + ); + }); + + it("still refuses a non-interactive resume of a session saved without that metadata", async () => { + const prompt = vi.fn(async () => "1"); + const { deps, calls } = createDeps({ + isNonInteractive: () => true, + prompt, checkGatewayRouteCompatibility: checkRouteOnEmptyGateway, }); diff --git a/src/lib/onboard/machine/runtime.ts b/src/lib/onboard/machine/runtime.ts index 18c71fb0d9b..e21c8e4588e 100644 --- a/src/lib/onboard/machine/runtime.ts +++ b/src/lib/onboard/machine/runtime.ts @@ -31,7 +31,7 @@ export interface OnboardRuntimeDeps { createSession(overrides?: Partial): Session; saveSession(session: Session): Session; updateSession(mutator: (session: Session) => Session | void): Session; - markStepStarted(stepName: string): Session; + markStepStarted(stepName: string, updates?: SessionUpdates): Session; markStepComplete(stepName: string, updates?: SessionUpdates): Session; markStepSkipped(stepName: string): Session; markStepRejected?(stepName: string): Session; @@ -151,8 +151,16 @@ export class OnboardRuntime { return session; } - async markStepStarted(stepName: string): Promise { - return this.deps.markStepStarted(stepName); + async markStepStarted(stepName: string, updates: SessionUpdates = {}): Promise { + const fields = Object.keys(this.deps.filterSafeUpdates(updates)); + const updated = this.deps.markStepStarted(stepName, updates); + if (fields.length > 0) { + this.emit("context.updated", updated, { + step: stepName, + metadata: { fields }, + }); + } + return updated; } async markStepComplete(stepName: string, updates: SessionUpdates = {}): Promise { diff --git a/src/lib/onboard/runtime-boundary.test.ts b/src/lib/onboard/runtime-boundary.test.ts index 3cb477d08eb..19509b1b189 100644 --- a/src/lib/onboard/runtime-boundary.test.ts +++ b/src/lib/onboard/runtime-boundary.test.ts @@ -28,9 +28,11 @@ function createRuntimeHarness(overrides: Partial = {}) { let session: Session | null = createSession(overrides); const events: OnboardMachineEvent[] = []; const stepCalls: string[] = []; + const writes: Session[] = []; const updateSession = (mutator: (value: Session) => Session | void): Session => { const current = session ? cloneSession(session) : createSession(); session = cloneSession(mutator(current) ?? current); + writes.push(cloneSession(session)); return cloneSession(session); }; const deps: OnboardRuntimeDeps = { @@ -41,11 +43,12 @@ function createRuntimeHarness(overrides: Partial = {}) { return cloneSession(session); }, updateSession, - markStepStarted: (stepName) => { + markStepStarted: (stepName, updates: SessionUpdates = {}) => { stepCalls.push("markStepStarted"); return updateSession((current) => { const step = current.steps[stepName]; if (!step) return current; + Object.assign(current, filterSafeUpdates(updates)); step.status = "in_progress"; step.startedAt = "2026-05-27T00:00:00.000Z"; step.completedAt = null; @@ -97,6 +100,7 @@ function createRuntimeHarness(overrides: Partial = {}) { createRuntime: () => new OnboardRuntime(deps), events, stepCalls, + writes, getSession: () => cloneSession(session ?? createSession()), }; } @@ -223,6 +227,34 @@ describe("OnboardRuntimeBoundary", () => { }); }); + it("writes the started review step and its route context in one session write (#13654)", async () => { + const harness = createRuntimeHarness(); + const boundary = new OnboardRuntimeBoundary({ + toSessionUpdates: (updates) => filterSafeUpdates(updates as SessionUpdates) as SessionUpdates, + maybeForceE2eStepFailure: () => undefined, + createRuntime: harness.createRuntime, + }); + + await boundary.startRecordedStep("provider_selection", { + provider: "compatible-endpoint", + model: "nvidia/nemotron-3.5-super-vl-120b-a12b", + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }); + + // An interruption after any write must never leave the started step + // without its route context, so the start is exactly one write. + expect(harness.writes).toHaveLength(1); + expect(harness.writes[0]).toMatchObject({ + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + steps: { provider_selection: { status: "in_progress" } }, + }); + expect(harness.events.filter((event) => event.type === "context.updated")).toHaveLength(1); + }); + it("applies each explicit transition exactly once", async () => { const harness = createRuntimeHarness(); const boundary = new OnboardRuntimeBoundary({ diff --git a/src/lib/onboard/runtime-boundary.ts b/src/lib/onboard/runtime-boundary.ts index 4a6059b80d6..8cc3896fcf7 100644 --- a/src/lib/onboard/runtime-boundary.ts +++ b/src/lib/onboard/runtime-boundary.ts @@ -78,11 +78,7 @@ export class OnboardRuntimeBoundary { preferredInferenceApi?: string | null; } = {}, ): Promise { - const runtime = this.getRuntime(); - await runtime.markStepStarted(stepName); - if (Object.keys(updates).length > 0) { - await runtime.updateContext(this.options.toSessionUpdates(updates)); - } + await this.getRuntime().markStepStarted(stepName, this.options.toSessionUpdates(updates)); this.options.maybeForceE2eStepFailure(stepName); } diff --git a/src/lib/state/onboard-session-step-start.test.ts b/src/lib/state/onboard-session-step-start.test.ts new file mode 100644 index 00000000000..1594ace1872 --- /dev/null +++ b/src/lib/state/onboard-session-step-start.test.ts @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +type OnboardSessionModule = typeof import("./onboard-session"); + +let session: OnboardSessionModule; +let tmpDir: string; + +beforeEach(async () => { + tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-step-start-session-")); + vi.stubEnv("HOME", tmpDir); + vi.resetModules(); + session = await import("./onboard-session"); + session.clearSession(); +}); + +afterEach(() => { + session.releaseOnboardLock(); + fs.rmSync(tmpDir, { recursive: true, force: true }); + vi.unstubAllEnvs(); +}); + +describe("onboard session step start", () => { + it("records a started step with its filtered context in the same write (#13654)", () => { + session.saveSession(session.createSession()); + + session.markStepStarted("provider_selection", { + provider: "compatible-endpoint", + endpointUrl: "https://user:secret@proxy.example.test/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }); + + const loaded = session.loadSession(); + expect(loaded?.steps.provider_selection.status).toBe("in_progress"); + expect(loaded).toMatchObject({ + provider: "compatible-endpoint", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }); + expect(loaded?.endpointUrl).not.toContain("secret"); + }); +}); diff --git a/src/lib/state/onboard-session.ts b/src/lib/state/onboard-session.ts index a87fa8c57b5..056964545ef 100644 --- a/src/lib/state/onboard-session.ts +++ b/src/lib/state/onboard-session.ts @@ -2319,10 +2319,14 @@ export function compareAndSwapSession( } } -export function markStepStarted(stepName: string): Session { +export function markStepStarted(stepName: string, updates: SessionUpdates = {}): Session { + const safeUpdates = filterSafeUpdates(updates); const updatedSession = updateSession((session) => { const step = session.steps[stepName]; if (!step) return session; + // Record the step and its context in one write so an interruption cannot + // keep the started step without the context it was started with. + Object.assign(session, safeUpdates); const now = new Date().toISOString(); step.status = "in_progress"; step.startedAt = now;