Repository navigation
Description
Summary
This issue tracks the stacked onboarding finite-state-machine (FSM) migration work and explains the current intended end-state for reviewers and maintainers.
The stack moves onboarding from a large manual sequence in src/lib/onboard.ts toward explicit FSM state results, a strict runtime/runner, and phase slices. Fresh onboarding is now being migrated onto FSM slices. Resume/ahead-state flows intentionally remain compatibility-driven for now so historical repair and backstop checks still execute even when the saved machine state is already ahead.
Stack overview
1. FSM target, metadata, and mappings
- docs(onboard): document FSM migration target #4361 — docs(onboard): document FSM migration target
- refactor(onboard): centralize machine state metadata #4362 — refactor(onboard): centralize machine state metadata
- refactor(onboard): derive session step mapping from FSM metadata #4363 — refactor(onboard): derive session step mapping from FSM metadata
- refactor(onboard): derive progress labels from FSM metadata #4364 — refactor(onboard): derive progress labels from FSM metadata
2. Runtime lifecycle/events/result primitives
- fix(onboard): emit lifecycle events for onboarding start #4373 — fix(onboard): emit lifecycle events for onboarding start
- fix(onboard): emit machine events for resume conflicts #4374 — fix(onboard): emit machine events for resume conflicts
- refactor(onboard): introduce explicit state result types #4375 — refactor(onboard): introduce explicit state result types
- refactor(onboard): apply explicit state results through runtime #4376 — refactor(onboard): apply explicit state results through runtime
3. Existing handlers return FSM results
- refactor(onboard): make finalization return FSM result #4443 — refactor(onboard): make finalization return FSM result
- refactor(onboard): make agent setup return FSM result #4444 — refactor(onboard): make agent setup return FSM result
- refactor(onboard): make policy setup return FSM result #4445 — refactor(onboard): make policy setup return FSM result
- refactor(onboard): make preflight and gateway return FSM results #4446 — refactor(onboard): make preflight and gateway return FSM results
- refactor(onboard): make sandbox return branch FSM result #4447 — refactor(onboard): make sandbox return branch FSM result
- refactor(onboard): return FSM results from provider inference #4452 — refactor(onboard): return FSM results from provider inference
4. Runner, record-only steps, and compatibility bridge
- refactor(onboard): add FSM runner shell #4453 — refactor(onboard): add FSM runner shell
- refactor(onboard): consume handler FSM results compatibly #4454 — refactor(onboard): consume handler FSM results compatibly
- refactor(onboard): allow step recording without machine transitions #4457 — refactor(onboard): allow step recording without machine transitions
- refactor(onboard): plumb step mutation options through runtime #4458 — refactor(onboard): plumb step mutation options through runtime
- refactor(onboard): add record-only FSM runner adapter #4461 — refactor(onboard): add record-only FSM runner adapter
5. Ordered results and sequence adapter
- refactor(onboard): return ordered provider FSM results #4471 — refactor(onboard): return ordered provider FSM results
- refactor(onboard): run live sequence with record-only steps #4472 — refactor(onboard): run live sequence with record-only steps
- refactor(onboard): let FSM handlers return result sequences #4473 — refactor(onboard): let FSM handlers return result sequences
- refactor(onboard): add sequence runner adapter #4475 — refactor(onboard): add sequence runner adapter
6. Flow context, phase adapters, and slice helpers
- refactor(onboard): support FSM runner stop states #4480 — refactor(onboard): support FSM runner stop states
- refactor(onboard): define FSM flow context #4481 — refactor(onboard): define FSM flow context
- refactor(onboard): extract preflight and gateway FSM phases #4482 — refactor(onboard): extract preflight and gateway FSM phases
- refactor(onboard): extract provider and sandbox FSM phases #4483 — refactor(onboard): extract provider and sandbox FSM phases
- refactor(onboard): extract agent policy finalization FSM phases #4484 — refactor(onboard): extract agent policy finalization FSM phases
- refactor(onboard): assemble FSM phase sequence #4485 — refactor(onboard): assemble FSM phase sequence
- refactor(onboard): add initial FSM flow slice #4486 — refactor(onboard): add initial FSM flow slice
- refactor(onboard): add core FSM flow slice #4487 — refactor(onboard): add core FSM flow slice
- refactor(onboard): add final FSM flow slice #4488 — refactor(onboard): add final FSM flow slice
7. Live fresh-flow migration and boundary tests
- refactor(onboard): run initial phases through FSM slice #4499 — refactor(onboard): run initial phases through FSM slice
- refactor(onboard): run core phases through FSM slice #4500 — refactor(onboard): run core phases through FSM slice
- refactor(onboard): run final phases through FSM slice #4507 — refactor(onboard): run final phases through FSM slice
- refactor(onboard): extract live FSM slice runner helper #4530 — refactor(onboard): extract live FSM slice runner helper
- test(onboard): cover live FSM slice boundaries #4531 — test(onboard): cover live FSM slice boundaries
Current behavior after the stack
Fresh onboarding is migrated to FSM slices:
- Initial slice: preflight/gateway → stops at
provider_selection - Core slice: provider/inference + sandbox → stops at
openclaworagent_setup - Final slice: branch setup + policies + finalization → completion
Step helpers can now record status without mutating the durable machine state. Fresh flows use record-only step mutation so OnboardRuntime owns machine transitions.
Resume compatibility is intentional
Resume/ahead-state flows still use the compatibility execution path. This is intentional because many historical fixes are repair/backstop checks inside phase bodies. Those checks must still run even if a saved session has already advanced beyond the phase's nominal FSM state.
Examples of this pattern include preflight/gateway backstops, provider repair, sandbox reuse/repair decisions, policy reconciliation, and final verification/recovery checks.
A future project can model resume repairs as first-class FSM behavior, but this stack keeps resume conservative to avoid regressions.
Suggested review order
- Review and merge the foundation PRs first (docs(onboard): document FSM migration target #4361 onward).
- Keep later PRs draft until their bases are merged/restacked.
- Review handler-result PRs independently; most are small behavior-preserving changes.
- Review live-slice PRs (refactor(onboard): run initial phases through FSM slice #4499, refactor(onboard): run core phases through FSM slice #4500, refactor(onboard): run final phases through FSM slice #4507, refactor(onboard): extract live FSM slice runner helper #4530, test(onboard): cover live FSM slice boundaries #4531) more carefully because they affect the live
onboard.tsexecution path for fresh runs.
Follow-up work after this stack
- Move large inline live phase wiring out of
src/lib/onboard.tsinto a dedicated module. - Clarify/rename the resume compatibility result application helper.
- Audit high-level smoke coverage for fresh, retry, branch, and resume paths after the stack lands.
- Decide later whether resume repair/backstop behavior should become explicit FSM policy.
Activity
Iamkewl commentedon May 29, 2026
Might be outside the scope of this, wondering if I should open a seperate issue with the same, found post revieiwng the PRs:
Summary
OnboardRuntimeBoundary.recordStateResultWithStepCompatibility(runtime-boundary.ts:95–107) silently discards transition results in two cases:return currentreturn currentNeither case emits an event, log, or trace. When debugging resume flows, there's no way to tell if a result was applied, discarded by idempotency, or discarded by provenance mismatch without stepping through with a debugger.
Proposal
Introduce a new type-safe event
"state.result.skipped"to the FSM runtime and emit it when a result is skipped during transition recording.1. Add
"state.result.skipped"toONBOARD_MACHINE_EVENT_TYPESinsrc/lib/onboard/machine/types.ts:2. Define
emitResultSkippedonOnboardRuntimeinsrc/lib/onboard/machine/runtime.ts:3. Update
recordStateResultWithStepCompatibilityinsrc/lib/onboard/runtime-boundary.tsto emit the events:wscurran commentedon May 29, 2026
✨
Related open PRs:
fix(onboard): repair rebuilt resume snapshots (#4938)
cv commentedon Jun 8, 2026
Post-mortem: rebuild/resume E2E regression after #4472
After #4472 merged, the rebuild/resume path exposed a regression that should have been caught before that PR landed.
What failed
The affected path was rebuild-driven resume:
rebuildSandbox()reopens the persisted onboarding session and callsonboard({ resume: true, recreateSandbox: true })so the sandbox can be recreated with the prior configuration.In the broken case, the persisted session had already reached a terminal machine snapshot:
session.machine.state === "complete"session.statuswas reset to"in_progress"by rebuildsession.resumablewas reset totrue#4472 intentionally moved the live sequence to record-only step helpers so the FSM runtime owns durable machine transitions. That part was directionally correct for #4533. The gap was that resume compatibility still relies on legacy step fields and repair/backstop phase bodies. When rebuild reopened a session whose machine snapshot was still terminal
complete, the compatibility recorder treated subsequent nonterminal results as stale/already-ahead and skipped them. Finalization then tried to complete from an already-complete machine state, hitting the invalidcomplete -> completetransition assertion instead of replaying the compatibility phases.Root cause
#4472 repaired terminal
failedsnapshots before resume, but did not repair terminalcompletesnapshots that had been reopened for resume/rebuild. That left the durable machine state ahead of the compatibility execution path.The important distinction is:
completestatus !== "complete"orresumable !== false) must be normalized back to the next resumable state derived from the legacy step record#4938 fixed this by extending
repairResumeMachineSnapshot()to repair reopened/resumablecompletesnapshots while leaving non-resumable completed sessions untouched.Why #4472 missed it
The review and tests covered the new record-only behavior and failed-session resume repair, but did not cover the rebuild-specific reopened-terminal shape. That shape is subtle because it is not a normal resume interruption; it is created by
rebuildSandbox()after a previously successful onboard, when rebuild temporarily turns a completed session back into an in-progress resumable one.This is exactly the kind of boundary #4533 called out as risky: fresh onboarding can move to FSM-owned transitions, but resume/ahead-state flows must keep compatibility repairs and backstops alive until resume behavior is modeled as first-class FSM policy.
Fix and verification
Fixed by #4938:
completemachine snapshots from legacy step statecompletesnapshots aftergatewayandpoliciesVerification after #4938:
npx prek run --all-filesnpm testonboard-resume-e2epassedonboard-repair-e2epassedmessaging-providers-e2epassedrebuild-openclaw-e2epassedPrevention
For future PRs in this stack, we should treat changes to the live sequence, runtime boundary, resume repair, record-only runner, or rebuild/session reopening as requiring targeted runtime coverage before merge:
onboard-resume-e2eonboard-repair-e2erebuild-openclaw-e2eWe should also consider adding a dedicated E2E scenario that explicitly creates the reopened-complete snapshot shape (
machine.state: "complete",status: "in_progress",resumable: true,lastCompletedStepset) and verifiesonboard --resumerepairs the snapshot before record-only replay. The unit coverage now pins this, but the original failure lived at the rebuild/runtime boundary, so a small targeted E2E would have caught #4472 before merge.cv commentedon Jun 9, 2026
Status refresh (June 9, 2026)
Refreshed live GitHub state for the section 6 PRs and the follow-on live-slice stack.
Section 6
PRs #4480-#4488 are merged. They all carry
v0.0.62; their CI/check surfaces were green at merge time, and none have pending/failing checks now.Merged section 6 PRs:
Open follow-on stack
DIRTY; needs conflict/rebase work.CLEAN.CLEAN.CLEAN.Next maintainer move
For #4499, add the targeted resume/ahead-state compatibility coverage requested by the advisor, plus a clear comment documenting the removal condition for the compatibility path. Then rerun/push, wait for checks/advisor, and mark #4499 ready for review if clean.
cv commentedon Jun 10, 2026
Closeout
This tracker is complete.
All PRs listed in the stack have merged, including the section 6 phase/slice helpers (#4480-#4488), the live fresh-flow migration (#4499, #4500, #4507), the live slice runner extraction (#4530), and the boundary coverage PR (#4531). The rebuild/resume regression follow-up (#4938) also merged, and the compatibility skip visibility feedback from this issue is now represented by
state.result.skippedplus runtime-boundary coverage.Final state for this tracker:
Closing this as completed. Broader cleanup and future policy work, such as continuing to slim
src/lib/onboard.ts, making resume repair/backstop behavior first-class FSM policy, or expanding the E2E scenario catalog, should stay under the umbrella issue #3802 or be split into dedicated follow-up issues.test(onboard): cover rebuild resume snapshot handoff (#5111)