Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6b753bf
docs(onboard): document FSM migration target
cv May 27, 2026
fb1b32d
refactor(onboard): centralize machine state metadata
cv May 27, 2026
c3e4ad6
refactor(onboard): derive session step mapping from FSM metadata
cv May 27, 2026
603832c
refactor(onboard): derive progress labels from FSM metadata
cv May 27, 2026
4fad8e7
fix(onboard): emit lifecycle events for onboarding start
cv May 28, 2026
f99e9cb
fix(onboard): emit machine events for resume conflicts
cv May 28, 2026
2b60df4
refactor(onboard): introduce explicit state result types
cv May 28, 2026
30341b0
refactor(onboard): apply explicit state results through runtime
cv May 28, 2026
d4ad2d9
refactor(onboard): make finalization return FSM result
cv May 28, 2026
356c947
refactor(onboard): make agent setup return FSM result
cv May 28, 2026
2296519
refactor(onboard): make policy setup return FSM result
cv May 28, 2026
67a9a1e
refactor(onboard): make preflight and gateway return FSM results
cv May 28, 2026
46f4a49
refactor(onboard): make sandbox return branch FSM result
cv May 28, 2026
9cc15f5
refactor(onboard): return FSM results from provider inference
cv May 28, 2026
dbbb273
refactor(onboard): add FSM runner shell
cv May 28, 2026
6b27a0b
refactor(onboard): consume handler FSM results compatibly
cv May 28, 2026
44009ad
refactor(onboard): allow step recording without machine transitions
cv May 28, 2026
cd6e5f7
refactor(onboard): plumb step mutation options through runtime
cv May 28, 2026
e266e3b
refactor(onboard): add record-only FSM runner adapter
cv May 28, 2026
bf4da0b
refactor(onboard): return ordered provider FSM results
cv May 28, 2026
212ff4d
refactor(onboard): run live sequence with record-only steps
cv May 28, 2026
f69f60a
refactor(onboard): let FSM handlers return result sequences
cv May 29, 2026
727ac69
refactor(onboard): add sequence runner adapter
cv May 29, 2026
75f82f7
refactor(onboard): support FSM runner stop states
cv May 29, 2026
59deee6
refactor(onboard): define FSM flow context
cv May 29, 2026
25c5abf
refactor(onboard): extract preflight and gateway FSM phases
cv May 29, 2026
4d9cc9f
refactor(onboard): extract provider and sandbox FSM phases
cv May 29, 2026
8a5b54a
refactor(onboard): extract agent policy finalization FSM phases
cv May 29, 2026
bec7ef8
refactor(onboard): assemble FSM phase sequence
cv May 29, 2026
0e168b3
refactor(onboard): add initial FSM flow slice
cv May 29, 2026
a1af752
merge(onboard): sync FSM stop states with main
cv Jun 9, 2026
5900708
merge(onboard): sync flow context with stop states
cv Jun 9, 2026
8576e5f
merge(onboard): sync preflight phases with flow context
cv Jun 9, 2026
42eeb90
merge(onboard): sync provider sandbox phases with preflight phases
cv Jun 9, 2026
dc8c463
test(onboard): cover sandbox branch metadata passthrough
cv Jun 9, 2026
5c76573
merge(onboard): sync finalization phases with provider sandbox phases
cv Jun 9, 2026
68722ed
test(onboard): run finalization phases through sequence runner
cv Jun 9, 2026
1775dc2
merge(onboard): sync flow sequence with finalization phases
cv Jun 9, 2026
3de7633
test(onboard): validate assembled provider sequence
cv Jun 9, 2026
8a893ff
merge(onboard): sync initial slice with flow sequence
cv Jun 9, 2026
ab55336
fix(onboard): handle init in initial FSM slice
cv Jun 9, 2026
5c7b7ee
Merge branch 'main' into stack/onboard-fsm-flow-context
jyaunches Jun 9, 2026
83c1412
Merge branch 'main' into stack/onboard-fsm-flow-context
cv Jun 9, 2026
6abbbb4
Merge branch 'stack/onboard-fsm-flow-context' into stack/onboard-fsm-…
cv Jun 9, 2026
c07f0dd
Merge branch 'stack/onboard-fsm-preflight-gateway-phases' into stack/…
cv Jun 9, 2026
cf6c2a9
Merge branch 'stack/onboard-fsm-provider-sandbox-phases' into stack/o…
cv Jun 9, 2026
4a297d0
Merge branch 'stack/onboard-fsm-agent-policy-finalization-phases' int…
cv Jun 9, 2026
cfdaf52
Merge branch 'stack/onboard-fsm-flow-sequence' into stack/onboard-fsm…
cv Jun 9, 2026
23e8577
Merge branch 'main' into stack/onboard-fsm-flow-context
cv Jun 9, 2026
abbd8c4
chore: apply static formatting for FSM flow stack
cv Jun 9, 2026
b592eac
Merge remote-tracking branch 'origin/stack/onboard-fsm-flow-context' …
cv Jun 9, 2026
adbbdfa
chore(onboard): format preflight gateway FSM phase
cv Jun 9, 2026
8a6bca2
Merge remote-tracking branch 'origin/stack/onboard-fsm-preflight-gate…
cv Jun 9, 2026
baeab37
chore(onboard): format provider sandbox FSM phase
cv Jun 9, 2026
5118bd7
Merge remote-tracking branch 'origin/stack/onboard-fsm-provider-sandb…
cv Jun 9, 2026
a64242b
chore(onboard): format finalization FSM phases
cv Jun 9, 2026
32059c9
Merge remote-tracking branch 'origin/stack/onboard-fsm-agent-policy-f…
cv Jun 9, 2026
3562942
chore(onboard): format FSM flow sequence
cv Jun 9, 2026
c2bb6a9
Merge remote-tracking branch 'origin/stack/onboard-fsm-flow-sequence'…
cv Jun 9, 2026
69d537d
Merge branch 'main' into stack/onboard-fsm-initial-sequence-slice
cv Jun 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions src/lib/onboard/machine/flow-slices.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from "vitest";

import {
createSession,
filterSafeUpdates,
MACHINE_SNAPSHOT_VERSION,
normalizeSession,
type Session,
type SessionUpdates,
} from "../../state/onboard-session";
import type { OnboardFlowContext } from "./flow-context";
import { advanceTo } from "./result";
import { OnboardRuntime, type OnboardRuntimeDeps } from "./runtime";
import type { OnboardSequencePhase } from "./sequence-runner";
import { initialOnboardFlowPhases, runInitialOnboardFlowSequence } from "./flow-slices";

function cloneSession(session: Session): Session {
return normalizeSession(JSON.parse(JSON.stringify(session))) ?? session;
}

function runtime(initialSession: Session = createSession()) {
let session = cloneSession(initialSession);
const updateSession = (mutator: (value: Session) => Session | void): Session => {
session = cloneSession(mutator(cloneSession(session)) ?? session);
return cloneSession(session);
};
const deps: OnboardRuntimeDeps = {
loadSession: () => cloneSession(session),
createSession,
saveSession: (next) => {
session = cloneSession(next);
return cloneSession(session);
},
updateSession,
markStepStarted: () => cloneSession(session),
markStepComplete: (_stepName, updates: SessionUpdates = {}) =>
updateSession((current) => Object.assign(current, filterSafeUpdates(updates))),
markStepCompleteRecordOnly: (_stepName, updates: SessionUpdates = {}) =>
updateSession((current) => Object.assign(current, filterSafeUpdates(updates))),
markStepSkipped: () => cloneSession(session),
markStepFailed: () => cloneSession(session),
markStepFailedRecordOnly: () => cloneSession(session),
completeSession: () => cloneSession(session),
filterSafeUpdates,
emitEvent: () => undefined,
now: () => "2026-05-29T00:00:00.000Z",
};
return new OnboardRuntime(deps);
}

function context(): OnboardFlowContext {
return {
resume: false,
fresh: false,
session: createSession(),
agent: null,
recordedSandboxName: null,
requestedSandboxName: null,
sandboxName: null,
fromDockerfile: null,
model: null,
provider: null,
endpointUrl: null,
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
preferredInferenceApi: null,
nimContainer: null,
webSearchConfig: null,
webSearchSupported: false,
selectedMessagingChannels: [],
gpu: null,
sandboxGpuConfig: null,
gpuPassthrough: false,
};
}

function phase(
state: OnboardSequencePhase<OnboardFlowContext>["state"],
next: ReturnType<typeof advanceTo>["next"],
): OnboardSequencePhase<OnboardFlowContext> {
return { state, run: (ctx) => ({ context: ctx, result: advanceTo(next) }) };
}

describe("onboard flow slices", () => {
it("selects only initial preflight/gateway phases", () => {
expect(
initialOnboardFlowPhases([
phase("preflight", "gateway"),
phase("gateway", "provider_selection"),
phase("provider_selection", "inference"),
]).map((entry) => entry.state),
).toEqual(["init", "preflight", "gateway"]);
});

it("runs the initial slice from a default session and stops at provider selection", async () => {
const result = await runInitialOnboardFlowSequence({
context: context(),
runtime: runtime(),
phases: [
phase("preflight", "gateway"),
phase("gateway", "provider_selection"),
phase("provider_selection", "inference"),
],
});

expect(result.session.machine.state).toBe("provider_selection");
});

it("runs the initial slice from preflight and stops at provider selection", async () => {
const result = await runInitialOnboardFlowSequence({
context: context(),
runtime: runtime(
createSession({
machine: {
version: MACHINE_SNAPSHOT_VERSION,
state: "preflight",
stateEnteredAt: "2026-05-29T00:00:00.000Z",
revision: 0,
},
}),
),
phases: [
phase("preflight", "gateway"),
phase("gateway", "provider_selection"),
phase("provider_selection", "inference"),
],
});

expect(result.session.machine.state).toBe("provider_selection");
});
});
33 changes: 33 additions & 0 deletions src/lib/onboard/machine/flow-slices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import type { OnboardFlowContext } from "./flow-context";
import { onboardFlowPhaseResult } from "./flow-context";
import { advanceTo } from "./result";
import type { OnboardMachineRunnerRuntime } from "./runner";
import type { OnboardSequencePhase } from "./sequence-runner";
import { runOnboardSequenceWithRunner } from "./sequence-runner";

export function initialOnboardFlowPhases<Context extends OnboardFlowContext>(
phases: readonly OnboardSequencePhase<Context>[],
): OnboardSequencePhase<Context>[] {
return [
{
state: "init",
run: (context) => onboardFlowPhaseResult(context, advanceTo("preflight")),
},
...phases.filter((phase) => phase.state === "preflight" || phase.state === "gateway"),
];
}

export async function runInitialOnboardFlowSequence<Context extends OnboardFlowContext>(options: {
context: Context;
runtime: OnboardMachineRunnerRuntime;
phases: readonly OnboardSequencePhase<Context>[];
}) {
return runOnboardSequenceWithRunner({
...options,
phases: initialOnboardFlowPhases(options.phases),
stopStates: ["provider_selection"],
});
}
3 changes: 3 additions & 0 deletions src/lib/onboard/machine/sequence-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface OnboardSequenceRunnerOptions<Context> {
phases: readonly OnboardSequencePhase<Context>[];
maxTransitions?: OnboardMachineRunnerOptions<Context>["maxTransitions"];
sequenceOwnership?: OnboardMachineRunnerOptions<Context>["sequenceOwnership"];
stopStates?: OnboardMachineRunnerOptions<Context>["stopStates"];
}

export class DuplicateOnboardSequencePhaseError extends Error {
Expand Down Expand Up @@ -69,13 +70,15 @@ export async function runOnboardSequenceWithRunner<Context>({
phases,
maxTransitions,
sequenceOwnership,
stopStates,
}: OnboardSequenceRunnerOptions<Context>) {
let pendingContext = initialContext;
return runOnboardMachine({
context: initialContext,
runtime,
maxTransitions,
sequenceOwnership,
stopStates,
handlers: buildOnboardSequenceHandlers(phases, (context) => {
pendingContext = context;
}),
Expand Down