refactor(onboard): add FSM runner shell#4453
Conversation
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
📝 WalkthroughWalkthroughAdds ChangesOnboarding State Machine Runner
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
PR Review AdvisorFindings: 0 needs attention, 2 worth checking, 0 nice ideas Review findings🛠️ Needs attention
🔎 Worth checking
🌱 Nice ideas
Consider writing more tests for
Since last review detailsCurrent findings:
This is an automated advisory review. A human maintainer must make the final merge decision. |
E2E Advisor RecommendationRequired E2E: Dispatch hint: Full advisor summaryE2E Recommendation AdvisorBase: Required E2E
Optional E2E
New E2E recommendations
Dispatch hint
|
E2E Scenario Advisor RecommendationRequired scenario E2E: Dispatch required scenario E2E:
Full scenario advisor summaryE2E Scenario AdvisorBase: Required scenario E2E
Optional scenario E2E
Relevant changed files
|
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Selective E2E Results — ✅ All requested jobs passedRun: 26979740935
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/onboard/machine/runner.test.ts`:
- Around line 35-38: updateSession currently discards in-place mutations because
it calls mutator(cloneSession(session)) and if the mutator returns void it falls
back to the original session; change it to pass a cloned mutable object to
mutator, capture that mutated object, and use it when mutator returns void: call
const mutated = cloneSession(session); const result = mutator(mutated); const
next = result ?? mutated; then set session = cloneSession(next) and return
cloneSession(session). This preserves in-place mutations while still supporting
mutator returns of Session or void for the updateSession helper.
In `@src/lib/onboard/machine/runner.ts`:
- Around line 66-69: The normalizeMaxTransitions function currently passes
Infinity/NaN through Math.trunc/Math.max which can produce Infinity or NaN and
disable the safety check (transitions >= transitionLimit); update
normalizeMaxTransitions to treat any non-finite input as undefined by first
checking Number.isFinite(value) (and returning DEFAULT_MAX_TRANSITIONS if not
finite), then apply Math.trunc and Math.max(1, ...) so the returned
transitionLimit is always a finite integer >= 1; ensure callers that compare
transitions >= transitionLimit (the safety valve) rely on this normalized value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 894be915-0e81-42ad-80b5-75936722f84f
📒 Files selected for processing (2)
src/lib/onboard/machine/runner.test.tssrc/lib/onboard/machine/runner.ts
| const updateSession = (mutator: (value: Session) => Session | void): Session => { | ||
| const next = mutator(cloneSession(session)) ?? session; | ||
| session = cloneSession(next); | ||
| return cloneSession(session); |
There was a problem hiding this comment.
updateSession drops in-place mutations when mutator returns void.
On Line 36, fallback to session discards mutations made to the cloned argument when mutator returns void. That makes the test double less faithful to the declared (Session | void) contract.
Suggested fix
const updateSession = (mutator: (value: Session) => Session | void): Session => {
- const next = mutator(cloneSession(session)) ?? session;
+ const current = cloneSession(session);
+ const next = mutator(current) ?? current;
session = cloneSession(next);
return cloneSession(session);
};🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/lib/onboard/machine/runner.test.ts` around lines 35 - 38, updateSession
currently discards in-place mutations because it calls
mutator(cloneSession(session)) and if the mutator returns void it falls back to
the original session; change it to pass a cloned mutable object to mutator,
capture that mutated object, and use it when mutator returns void: call const
mutated = cloneSession(session); const result = mutator(mutated); const next =
result ?? mutated; then set session = cloneSession(next) and return
cloneSession(session). This preserves in-place mutations while still supporting
mutator returns of Session or void for the updateSession helper.
| function normalizeMaxTransitions(value: number | undefined): number { | ||
| if (value === undefined) return DEFAULT_MAX_TRANSITIONS; | ||
| return Math.max(1, Math.trunc(value)); | ||
| } |
There was a problem hiding this comment.
Harden transition-limit normalization against non-finite values.
At Line 66-69, Math.trunc + Math.max allows Infinity and yields NaN for NaN; either case can break the safety valve used at Line 84-85 (transitions >= transitionLimit) and effectively remove the cap.
Proposed fix
const DEFAULT_MAX_TRANSITIONS = 100;
+const MAX_TRANSITIONS_CAP = 10_000;
function normalizeMaxTransitions(value: number | undefined): number {
if (value === undefined) return DEFAULT_MAX_TRANSITIONS;
- return Math.max(1, Math.trunc(value));
+ if (!Number.isFinite(value)) return DEFAULT_MAX_TRANSITIONS;
+ return Math.min(MAX_TRANSITIONS_CAP, Math.max(1, Math.trunc(value)));
}Also applies to: 81-85
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/lib/onboard/machine/runner.ts` around lines 66 - 69, The
normalizeMaxTransitions function currently passes Infinity/NaN through
Math.trunc/Math.max which can produce Infinity or NaN and disable the safety
check (transitions >= transitionLimit); update normalizeMaxTransitions to treat
any non-finite input as undefined by first checking Number.isFinite(value) (and
returning DEFAULT_MAX_TRANSITIONS if not finite), then apply Math.trunc and
Math.max(1, ...) so the returned transitionLimit is always a finite integer >=
1; ensure callers that compare transitions >= transitionLimit (the safety valve)
rely on this normalized value.
Summary
Add a reusable onboarding FSM runner shell that dispatches handlers until the machine reaches a terminal state. The runner applies handler results through
OnboardRuntime, supporting advance, retry, branch, complete, and failure paths without wiring it into live onboarding yet.Changes
src/lib/onboard/machine/runner.tswith handler dispatch, context update, terminal-state, and missing-handler support.Type of Change
Verification
npx prek run --all-filespassesnpm testpassesnpm run docsbuilds without warnings (doc changes only)Signed-off-by: Carlos Villela cvillela@nvidia.com
Summary by CodeRabbit