diff --git a/src/lib/onboard/machine/core-flow-phases.test.ts b/src/lib/onboard/machine/core-flow-phases.test.ts index 7048349d83f..431891000b6 100644 --- a/src/lib/onboard/machine/core-flow-phases.test.ts +++ b/src/lib/onboard/machine/core-flow-phases.test.ts @@ -11,7 +11,7 @@ import { } from "./core-flow-phases"; import type { OnboardFlowContext } from "./flow-context"; import type { OnboardStateResult } from "./result"; -import { advanceTo } from "./result"; +import { advanceTo, branchTo } from "./result"; import type { OnboardSequencePhase } from "./sequence-runner"; type Agent = { name: string }; @@ -274,6 +274,74 @@ describe("core onboard flow phases", () => { }); }); + it("uses the strict runner for fresh provider selection sessions", async () => { + const calls: string[] = []; + const applied: string[] = []; + let runtimeSession = createSession({ + machine: { + version: 1, + state: "provider_selection", + stateEnteredAt: "2026-06-09T00:00:00.000Z", + revision: 1, + }, + }); + const phases: readonly OnboardSequencePhase[] = [ + { + state: "provider_selection", + run: (ctx) => { + calls.push("provider_selection"); + return { + context: ctx, + result: [ + advanceTo("inference", { metadata: { state: "provider_selection" } }), + advanceTo("sandbox", { metadata: { state: "inference" } }), + ], + }; + }, + }, + { + state: "sandbox", + run: (ctx) => { + calls.push("sandbox"); + return { + context: { ...ctx, sandboxName: "created-sandbox" }, + result: branchTo("openclaw", { metadata: { state: "sandbox" } }), + }; + }, + }, + ]; + + const result = await runCoreOnboardFlowSlice({ + context: context({ model: "nvidia/test", provider: "nim" }), + runtime: { + session: async () => runtimeSession, + applyResult: async (stateResult) => { + const next = (stateResult as ReturnType).next; + applied.push(next); + runtimeSession = createSession({ + machine: { + version: 1, + state: next, + stateEnteredAt: "2026-06-09T00:03:00.000Z", + revision: runtimeSession.machine.revision + 1, + }, + }); + return runtimeSession; + }, + }, + phases, + resume: false, + recordStateResult: async () => { + throw new Error("compatibility recorder should not run"); + }, + }); + + expect(calls).toEqual(["provider_selection", "sandbox"]); + expect(applied).toEqual(["inference", "sandbox", "openclaw"]); + expect(result.context.sandboxName).toBe("created-sandbox"); + expect(result.session.machine.state).toBe("openclaw"); + }); + it("records each phase result on the resume compatibility path", async () => { const recorded: string[] = []; const phases: readonly OnboardSequencePhase< diff --git a/src/lib/onboard/machine/core-flow-phases.ts b/src/lib/onboard/machine/core-flow-phases.ts index 5f5e0abe85d..bd4cdc541d9 100644 --- a/src/lib/onboard/machine/core-flow-phases.ts +++ b/src/lib/onboard/machine/core-flow-phases.ts @@ -161,18 +161,19 @@ export async function runCoreOnboardFlowSlice { await options.recordStateResult(stateResult); diff --git a/src/lib/onboard/machine/initial-flow-phases.test.ts b/src/lib/onboard/machine/initial-flow-phases.test.ts index 342f26e6ebb..7801c0f2f80 100644 --- a/src/lib/onboard/machine/initial-flow-phases.test.ts +++ b/src/lib/onboard/machine/initial-flow-phases.test.ts @@ -493,6 +493,61 @@ describe("initial onboard flow phases", () => { expect(phase.run).not.toHaveBeenCalled(); }); + it("uses the strict runner for fresh preflight sessions", async () => { + const order: string[] = []; + const applied: string[] = []; + const session = createSession({ + machine: { + version: 1, + state: "preflight", + stateEnteredAt: "2026-06-09T00:00:00.000Z", + revision: 1, + }, + }); + const phases: readonly OnboardSequencePhase[] = [ + { + state: "preflight", + run: (ctx) => { + order.push("preflight"); + return { context: ctx, result: advanceTo("gateway") }; + }, + }, + { + state: "gateway", + run: (ctx) => { + order.push("gateway"); + return { context: ctx, result: advanceTo("provider_selection") }; + }, + }, + ]; + + const result = await runInitialOnboardFlowSlice({ + context: context(), + runtime: { + session: async () => session, + applyResult: async (stateResult) => { + const next = (stateResult as ReturnType).next; + applied.push(next); + session.machine = { + ...session.machine, + state: next, + revision: session.machine.revision + 1, + }; + return session; + }, + }, + phases, + resume: false, + recordStateResult: async () => { + throw new Error("compatibility recorder should not run"); + }, + }); + + expect(order).toEqual(["preflight", "gateway"]); + expect(applied).toEqual(["gateway", "provider_selection"]); + expect(result.session.machine.state).toBe("provider_selection"); + }); + it("uses the strict runner for fresh init sessions", async () => { const order: string[] = []; const session = createSession(); diff --git a/src/lib/onboard/machine/initial-flow-phases.ts b/src/lib/onboard/machine/initial-flow-phases.ts index 08d0d3abe9f..145175d8baa 100644 --- a/src/lib/onboard/machine/initial-flow-phases.ts +++ b/src/lib/onboard/machine/initial-flow-phases.ts @@ -205,21 +205,22 @@ export async function runInitialOnboardFlowSlice { context: { value: 1 }, runtime: runtime("preflight").runtime, phases: [phase("preflight", 2)], - resume: false, runWhenState: ["preflight"], compatibilityWhenState: ["provider_selection"], runSlice, @@ -117,7 +116,6 @@ describe("runLiveOnboardFlowSlice", () => { })), }, ], - resume: true, runWhenState: ["preflight"], compatibilityWhenState: ["provider_selection"], runSlice, @@ -141,7 +139,6 @@ describe("runLiveOnboardFlowSlice", () => { context: { value: 1 }, runtime: liveRuntime.runtime, phases: [phase("preflight", 2)], - resume: true, runWhenState: ["preflight"], compatibilityWhenState: ["preflight"], runSlice, @@ -163,7 +160,6 @@ describe("runLiveOnboardFlowSlice", () => { context: { value: 1 }, runtime: liveRuntime.runtime, phases: [phase("preflight", 2)], - resume: false, runWhenState: ["preflight"], compatibilityWhenState: ["provider_selection"], runSlice, @@ -185,7 +181,6 @@ describe("runLiveOnboardFlowSlice", () => { context: { value: 1 }, runtime: liveRuntime.runtime, phases: [blocked], - resume: false, runWhenState: ["provider_selection"], compatibilityWhenState: ["inference", "sandbox"], runSlice, @@ -209,7 +204,7 @@ describe("runLiveOnboardFlowSlice", () => { context: { value: 1 }, runtime: liveRuntime.runtime, phases: [blocked], - resume: true, + runWhenState: ["preflight"], compatibilityWhenState: ["sandbox"], runSlice, @@ -233,7 +228,6 @@ describe("runLiveOnboardFlowSlice", () => { context: { value: 1 }, runtime: liveRuntime.runtime, phases: [first, second], - resume: true, runWhenState: ["preflight"], compatibilityWhenState: ["provider_selection"], runSlice: vi.fn(), @@ -255,7 +249,6 @@ describe("runLiveOnboardFlowSlice", () => { context: { value: 1 }, runtime: liveRuntime.runtime, phases: [phase("preflight", 2, [])], - resume: true, runWhenState: ["preflight"], compatibilityWhenState: ["provider_selection"], runSlice: vi.fn(), @@ -278,7 +271,6 @@ describe("runLiveOnboardFlowSlice", () => { context: { value: 1 }, runtime: liveRuntime.runtime, phases: [phase("preflight", 2), later], - resume: true, runWhenState: ["preflight"], compatibilityWhenState: ["provider_selection"], runSlice: vi.fn(), diff --git a/src/lib/onboard/machine/live-flow-slice.ts b/src/lib/onboard/machine/live-flow-slice.ts index 1294b2bf488..883f507de77 100644 --- a/src/lib/onboard/machine/live-flow-slice.ts +++ b/src/lib/onboard/machine/live-flow-slice.ts @@ -14,7 +14,6 @@ export interface LiveOnboardFlowSliceOptions { context: Context; runtime: OnboardMachineRunnerRuntime; phases: readonly OnboardSequencePhase[]; - resume: boolean; runWhenState: readonly OnboardMachineState[]; compatibilityWhenState?: readonly OnboardMachineState[]; runSlice(options: { @@ -77,14 +76,16 @@ export async function runLiveOnboardFlowSlice({ context, runtime, phases, - resume, runWhenState, compatibilityWhenState = [], runSlice, applyCompatibleResult, }: LiveOnboardFlowSliceOptions): Promise> { const current = await runtime.session(); - if (!resume && runWhenState.includes(current.machine.state)) { + if ( + runWhenState.includes(current.machine.state) && + !compatibilityWhenState.includes(current.machine.state) + ) { return runSlice({ context, runtime, phases }); } if (!compatibilityWhenState.includes(current.machine.state)) {