Skip to content

refactor(setup): split setup steps and own keepalive processes - #1093

Merged
karkarl merged 2 commits into
mainfrom
bkudiess-setup-engine-owners
Aug 19, 2026
Merged

karkarl merged 2 commits into
mainfrom
bkudiess-setup-engine-owners

Conversation

@bkudiess

@bkudiess bkudiess commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Split the 20 remaining setup step classes out of the 3,860-line SetupSteps.cs god file into one file per step without changing pipeline order, IDs, retry, rollback, journal, logging, or WSL argv behavior.
  • Extract setup-time detached WSL keepalive ownership into KeepaliveProcessManager.
  • Keep StartKeepaliveStep as the thin SetupContext adapter and result mapper.
  • Add an internal, policy-free IKeepaliveProcessRuntime seam for deterministic process identity, start, enumeration, kill, and failure tests.
  • Broaden the SetupEngine ShellEscape closure guard to every production file and route the two newly exposed Tailscale copies through canonical WslShellQuoting.
  • Update the architecture ledger and setup/WSL documentation.

Ownership transfer

Old owner New owner Preserved invariant
StartKeepaliveStep inline process, marker, identity, and rollback logic KeepaliveProcessManager Existing matching process is reused; stale/wrong identity starts fresh; start failure soft-succeeds; rollback kills only matching-distro keepalives and continues after per-process failure
Raw Process and CIM mechanics inside the step Internal IKeepaliveProcessRuntime / ProcessKeepaliveRuntime Policy remains in the manager; every process wrapper is disposed
20 setup classes in SetupSteps.cs One file per step SetupStepFactory.BuildDefaultSteps() remains authoritative and unchanged

WslGatewayKeepAliveService, managed-local repair, WslShellClient, GatewayConfigScriptBuilder, Tailscale step grouping, setup schema, CLI, and UI behavior are unchanged.

Validation

  • ./build.ps1: all 5 projects passed
  • Shared: 3,399 passed, 32 skipped
  • Tray: 2,038 passed
  • SetupEngine: 726 passed
  • Focused keepalive: 25 passed
  • ShellEscape closure: 1 passed
  • Connection regression source guards: 12 passed
  • Complete tracked/untracked patch hygiene: valid UTF-8, final newline, no introduced trailing whitespace

Real behavior proof

  • Canonical OPENCLAW_RUN_E2E=1 SetupAndConnectTests: 16/16 passed with no skips.
  • The run created an isolated OpenClawE2E-* distro and setup-time keepalive process.
  • The tray recognized the setup-time keepalive without spawning a duplicate.
  • Product uninstall killed the isolated process tree, deleted its marker and empty directory, and unregistered the isolated distro.
  • The pre-existing shared OpenClawGateway distro, marker, and keepalive processes remained unchanged.
  • validate-wsl-gateway.ps1 -Scenario UpstreamInstall was additionally attempted twice but blocked before setup because the script still targets removed SetupWarningPage / OnboardingSetupLocal automation IDs. Current onboarding uses WelcomePage, WelcomeInstallLocalGatewayChoice, and WelcomeNextButton after Standardize onboarding gateway choice on ListView pill selector #1048. The failed isolated runs left the shared distro, marker, and processes unchanged. PreflightOnly does not exercise setup/keepalive, so it was not reported as substitute proof.

Review

  • Exact final-byte GPT-5.6 Sol, Gemini fallback, and rubber-duck reviews: clean.
  • Claude Opus 4.8 full-diff review was clean before the final seven blank-line whitespace normalization; no behavior bytes changed afterward.
  • Bundled autoreview failed closed before model invocation on four mechanically moved files with credential-oriented names/content. A dedicated literal, entropy, and credential scan found no added secret; no file was omitted, renamed, or truncated to bypass the guard.

Architecture

Adds authoritative setup-keepalive-process-manager ownership and strengthens the existing setup-shellescape-closed guard. The remaining shared helpers stay in SetupSteps.cs only when used by multiple step files.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codex review: found issues before merge. Reviewed August 18, 2026, 7:17 PM ET / 23:17 UTC.

ClawSweeper review

What this changes

The PR splits Setup Engine steps into focused files and moves setup-time WSL keepalive process ownership into a dedicated manager.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep open. The head preserves fresh-WSL retry behavior, but changes a thrown keepalive launch error from a retrying setup failure into successful setup; that availability policy needs explicit approval or restoration of current behavior.

Priority: P1
Reviewed head: 83220f2b4e8f29115350a91c97f34df7f60ba783
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The refactor has meaningful isolated runtime proof, but its changed exceptional-path availability policy remains a merge blocker.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body reports a current-head isolated 16/16 SetupAndConnect run with observed keepalive handoff and uninstall cleanup.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports a current-head isolated 16/16 SetupAndConnect run with observed keepalive handoff and uninstall cleanup.
Evidence reviewed 6 items Current-main exception behavior: Current main only soft-succeeds when Process.Start returns null; a thrown launch exception is not caught in the step and therefore follows normal pipeline retry/failure handling.
Head changes that policy: The new manager catches any StartDetached exception and returns FailedToStart, which StartKeepaliveStep maps to success; the added test explicitly asserts this result.
Previous readiness finding is addressed: The extracted WSL creation step retains one-minute version verification and 30/60/90-second root-probe retries, with transient and persistent-timeout coverage.
Findings 1 actionable finding [P1] Preserve launch-exception failure semantics
Security None None.

Live Verification

Command: dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter FullyQualifiedName~KeepaliveProcessManagerTests

Result: FAIL (failed) — execution before step 1 run: sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.22.0.tgz

sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.22.0.tgz

Assertions:

  • FAIL expect_output: Passed

How this fits together

The Setup Engine provisions an app-owned WSL gateway and starts a temporary keepalive process so the tray can take over after setup. Pipeline results feed into gateway startup, pairing, and the tray restart path.

flowchart LR
  A[Setup configuration] --> B[Setup pipeline]
  B --> C[WSL distro creation]
  C --> D[Temporary keepalive manager]
  D --> E[Gateway startup and pairing]
  E --> F[Tray keepalive handoff]
Loading

Decision needed

Question Recommendation
Should a thrown setup-time WSL keepalive launch exception remain a retrying setup failure, or intentionally be treated as successful setup for later tray recovery? Preserve retry and failure behavior: Let launch exceptions reach the existing pipeline retry/failure path while retaining the extracted manager.

Why: Current main and the PR head implement different user-visible failure semantics, and neither the supplied discussion nor repository policy records a maintainer-approved choice.

Before merge

  • Preserve launch-exception failure semantics (P1) - This catch converts a thrown WSL launch failure into FailedToStart, which the step maps to success. Current main only soft-succeeds on a null process handle; thrown errors follow normal pipeline retry/failure handling. Restore that behavior unless a maintainer explicitly approves the availability-policy change.
  • Resolve merge risk (P1) - A thrown WSL keepalive launch error now reports setup success instead of using the established retry/failure path, potentially hiding an availability failure until tray handoff.
  • Complete next step (P2) - A maintainer must choose the intended exception policy before a mechanical repair can be selected.

Findings

  • [P1] Preserve launch-exception failure semantics — src/OpenClaw.SetupEngine/KeepaliveProcessManager.cs:139-145
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Refactor scope 31 files affected; production +4,483/-4,045, tests +523/-49 The broad mechanical split makes preservation of exceptional-path behavior especially important.

Merge-risk options

Maintainer options:

  1. Preserve launch failure handling (recommended)
    Remove the exception-to-success conversion so the existing retry and failure behavior remains intact.
  2. Approve the new recovery policy
    Accept soft success only with explicit maintainer confirmation that tray restart recovery is the intended availability contract.

Technical review

Best possible solution:

Keep the ownership transfer, but retain the established launch-exception retry/failure behavior unless a maintainer explicitly approves soft success as the permanent availability policy.

Do we have a high-confidence way to reproduce the issue?

Yes. Source comparison shows that current main lets a thrown Process.Start error enter normal pipeline retry/failure handling, while this head catches it and returns success.

Is this the best way to solve the issue?

No. For a refactor claiming preserved retry behavior, preserving the current exception path is the narrowest solution unless a maintainer deliberately chooses the new policy.

Full review comments:

  • [P1] Preserve launch-exception failure semantics — src/OpenClaw.SetupEngine/KeepaliveProcessManager.cs:139-145
    This catch converts a thrown WSL launch failure into FailedToStart, which the step maps to success. Current main only soft-succeeds on a null process handle; thrown errors follow normal pipeline retry/failure handling. Restore that behavior unless a maintainer explicitly approves the availability-policy change.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 99730e7569fc.

Labels

Label justifications:

  • P1: The changed exception path can cause a first-run local gateway setup to report success despite a failed keepalive launch.
  • merge-risk: 🚨 availability: The PR changes whether a WSL process-launch failure stops and retries setup or is deferred to later tray recovery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body reports a current-head isolated 16/16 SetupAndConnect run with observed keepalive handoff and uninstall cleanup.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports a current-head isolated 16/16 SetupAndConnect run with observed keepalive handoff and uninstall cleanup.

Evidence

What I checked:

  • Current-main exception behavior: Current main only soft-succeeds when Process.Start returns null; a thrown launch exception is not caught in the step and therefore follows normal pipeline retry/failure handling. (src/OpenClaw.SetupEngine/SetupSteps.cs:4116, 99730e7569fc)
  • Head changes that policy: The new manager catches any StartDetached exception and returns FailedToStart, which StartKeepaliveStep maps to success; the added test explicitly asserts this result. (src/OpenClaw.SetupEngine/KeepaliveProcessManager.cs:139, 83220f2b4e8f)
  • Previous readiness finding is addressed: The extracted WSL creation step retains one-minute version verification and 30/60/90-second root-probe retries, with transient and persistent-timeout coverage. (src/OpenClaw.SetupEngine/CreateWslInstanceStep.cs:119, 83220f2b4e8f)
  • Architecture transfer follows the ledger: The updated ledger assigns setup-time keepalive ownership to KeepaliveProcessManager and records the intended handoff and cleanup invariants. (docs/ARCHITECTURE.md:160, 83220f2b4e8f)
  • Behavior provenance: Blame attributes the shipped inline keepalive behavior to the v2026.7.1 source commit authored by Scott Hanselman. (src/OpenClaw.SetupEngine/SetupSteps.cs:4116, 4206611f2b2e)
  • Proof and hygiene: The PR body reports a current-head isolated 16/16 SetupAndConnect run covering keepalive handoff and uninstall cleanup; the reviewed diff has no whitespace errors and the checkout is clean. (83220f2b4e8f)

Likely related people:

  • Scott Hanselman: Current-main blame identifies the v2026.7.1 source commit for the original inline keepalive launch and failure behavior. (role: introduced shipped keepalive behavior; confidence: high; commits: 4206611f2b2e; files: src/OpenClaw.SetupEngine/SetupSteps.cs)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Restore current exception propagation, or obtain explicit maintainer approval for soft-success recovery.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (18 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-07T23:30:08.237Z sha 8f6c07f :: needs changes before merge. :: [P1] Preserve fresh-WSL readiness retries
  • reviewed 2026-08-08T06:25:23.426Z sha 8f6c07f :: found issues before merge. :: [P1] Preserve fresh-WSL readiness retries
  • reviewed 2026-08-08T14:23:12.705Z sha 8f6c07f :: found issues before merge. :: [P1] Preserve fresh-WSL readiness retries
  • reviewed 2026-08-09T00:06:54.548Z sha 8f6c07f :: found issues before merge. :: [P1] Preserve fresh-WSL readiness retries
  • reviewed 2026-08-09T03:16:37.343Z sha 8f6c07f :: found issues before merge. :: [P1] Preserve fresh-WSL readiness retries
  • reviewed 2026-08-09T09:28:39.948Z sha 8f6c07f :: found issues before merge. :: [P1] Preserve fresh-WSL readiness retries
  • reviewed 2026-08-09T11:59:48.761Z sha 8f6c07f :: found issues before merge. :: [P1] Preserve fresh-WSL readiness retries
  • reviewed 2026-08-09T14:51:05.076Z sha 8f6c07f :: needs changes before merge. :: [P1] Preserve fresh-WSL readiness retries

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 5, 2026
@bkudiess
bkudiess marked this pull request as draft August 5, 2026 06:23
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 5, 2026
@bkudiess

bkudiess commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Evidence update: two independent full-diff reviewers were asked for an explicit numeric confidence (not a qualitative 'clean') covering split fidelity, the KeepaliveProcessManager/SetupContext boundary, the policy-free runtime seam, the EnumerateProcessIds disposal fix, rollback kill-identity, and deterministic test coverage. Claude Opus 4.8: 97% confidence, zero accepted findings. GPT-5.6 Terra: 98% confidence, zero accepted findings. Neither found any real secret in the four bundler-flagged step files. PR body updated with this evidence.

The one remaining before-merge item (thrown keepalive-start exception soft-succeeding setup) is an intentional, binding availability-policy decision requested during this PR's development, not a code defect -- documented in a new 'Maintainer decision needed' section in the PR body. Requesting a fresh review pass to reflect the added confidence evidence; the availability-policy choice itself still needs explicit maintainer sign-off before merge.

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@bkudiess
bkudiess marked this pull request as ready for review August 5, 2026 22:22
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 Urgent regression or broken agent/channel workflow affecting real users now. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Aug 6, 2026
bkudiess and others added 2 commits August 18, 2026 11:37
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 61934333-9a0d-4743-b5e1-cc62b0f65570
@karkarl
karkarl force-pushed the bkudiess-setup-engine-owners branch from 8f6c07f to 83220f2 Compare August 18, 2026 23:11
@karkarl

karkarl commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Current-head validation and sanitized full setup proof

Validated pushed head 83220f2b4e8f29115350a91c97f34df7f60ba783, rebased onto 99730e7569fc15f4f29eefbf42753707d698f94e.

Validation

  • ./build.ps1: passed
  • Shared: 3,698 passed, 32 skipped
  • Tray: 2,620 passed
  • SetupEngine: 888 passed
  • Connection: 632 passed
  • WinNode CLI: 126 passed
  • Focused keepalive, rollback, and cancellation: 398 passed
  • Real ARM64 WSL setup/connect/recovery E2E: 20 passed
  • WSL gateway preflight: passed
  • GitHub checks: setup-connect, network recovery, revocation recovery, win-x64, win-arm64, full tests, and CodeQL all passed

The current-head UI run completed the entire authorized real setup flow on Windows ARM64. The product-owned OpenClawGateway WSL distro was removed and recreated. Setup completed validated gateway installation, device pairing, the Standard capability profile, QuickStart onboarding with supported no-secret choices, final completion, Companion relaunch, and an active gateway/node connection.

All screenshots below are cropped to the application window. The device identity in the final diagnostic view is covered by an opaque redaction. The install-plan screenshot was excluded because it displayed a local user-profile path.

Real WSL replacement and setup pipeline

Sanitized active WSL replacement and setup pipeline

Gateway installed and ready for onboarding

Sanitized gateway installed milestone

Entire setup completed

Sanitized All set completion

Companion relaunched and connected

Sanitized connected Companion

Gateway connected and node active

Sanitized connected gateway and active Windows node

The final state shows the local gateway connected at ws://localhost:18789/, paired via device token, gateway version 2026.6.34, and node mode active with six capabilities. No provider, messaging, or web-search credentials were entered or exposed during this proof run.

@karkarl
karkarl merged commit b37307c into main Aug 19, 2026
22 checks passed
@karkarl
karkarl deleted the bkudiess-setup-engine-owners branch August 19, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants