Skip to content

fix: setup engine slow-machine fixes and config audit - #547

Closed
ranjeshj wants to merge 3 commits into
openclaw:masterfrom
ranjeshj:ranjeshj/dev
Closed

ranjeshj wants to merge 3 commits into
openclaw:masterfrom
ranjeshj:ranjeshj/dev

Conversation

@ranjeshj

Copy link
Copy Markdown
Contributor

Setup Engine: Slow-Machine Fixes & Config Audit

⚠️ Validation pending — manual testing on slow ARM64 machines required.


Summary

Fixes 7 bugs found during setup testing on slow ARM64 machines with WSL2 mirrored networking. Also includes a full audit of hardcoded config values, extracting them into default-config.json for configurability, and fixes from a dual-model adversarial code review.

🔴 Critical Fixes (2)

1. WebSocket default URL uses localhost → IPv6 resolution failure

  • SetupContext.EffectiveGatewayUrl defaulted to ws://localhost:{port}. .NET resolves localhost to IPv6 [::1] first, but WSL2 mirrored networking only forwards IPv4 (127.0.0.1). Health checks using 127.0.0.1 passed, but WebSocket connections to localhost got "connection refused" for 3m40s across all retries.
  • Fix: Changed all gateway URLs from localhost to 127.0.0.1.

2. PairNodeStep health check also used localhost (IPv6)

  • Same IPv6 bug in PairNodeStep's pre-connect gateway health check.
  • Fix: Changed to http://127.0.0.1:{port}.

🟠 High-Priority Fixes (2)

3. WaitForConnectionOrPairing resolves immediately on first Error/Disconnected

  • The method resolved the TaskCompletionSource on the first Error or non-pairing Disconnected event, killing the connection before the WebSocket client's built-in auto-reconnect could retry. On slow machines with WSL2 port-forwarding lag, pairing always failed after ~40s.
  • Fix: Removed immediate resolution on Error/Disconnected. Only resolve on Connected or PairingRequired. Timeout catches genuinely unreachable gateways.

4. StartGatewayStep only checked health from inside WSL, not from Windows

  • With WSL2 mirrored networking, the gateway port can be healthy inside WSL but not yet forwarded to the Windows host.
  • Fix: Added WaitForWindowsPortReachable() — polls http://127.0.0.1:{port} from the Windows side after the WSL health check passes.

🟡 Medium Fix (1)

5. Hardcoded 15s/20s pairing timeouts too short for slow machines

  • Fix: All replaced with Pairing.TimeoutSeconds (default 60s) for configurability.

🟢 Low-Priority Fixes (2)

6. Port conflict detection missed "node" gateway processes

  • The gateway runs as node … openclaw … gateway. If the process name appeared as "node", it would falsely report a port conflict.
  • Fix: Now matches both "openclaw" and "node".

7. No way to disable rollback for debugging setup failures

  • Fix: Added rollback confirmation dialog in UI mode. Users can choose to keep the current state for debugging.

🔧 Bonus Fix

TryRevokeOperatorTokenAsync used hardcoded ws://localhost:18789

  • Fallback URL was hardcoded instead of using configured EffectiveGatewayUrl.

📋 Config Audit

Replaced CommandTimeoutMultiplier (1 multiplier × 48 individual timeout values) with a simpler 2-tier model:

Config Default Purpose
CommandTimeoutSeconds 60 Standard WSL commands (probes, state changes, pairing CLIs)
InstallTimeoutSeconds 600 Network downloads and bulk I/O (distro import, CLI install)
WindowsPortTimeoutSeconds 30 WSL2 port forwarding delay
StabilizationDelaySeconds 5 Post-pairing grace period
RollbackTimeoutSeconds 60 Per-step rollback kill timeout
Wizard.RequestTimeoutSeconds 30 Normal wizard step response
Wizard.AuthStepTimeoutSeconds 300 Auth/OAuth wizard steps

All timeouts are "kill if hung" safety nets — fast machines finish instantly; raising timeouts has zero cost on fast machines.

🔍 Adversarial Code Review Fixes

Dual-model review (Claude Opus + GPT Codex) found and fixed:

  • TryEnqueue deadlock — if DispatcherQueue is shut down (window closed), TaskCompletionSource was never completed, deadlocking the pipeline. Now checks return value and defaults to rollback.
  • Dialog dismiss default — ESC/close on rollback dialog incorrectly defaulted to "keep for debugging". Now defaults to rollback (safer).

Files Changed (6)

  • src/OpenClaw.SetupEngine.UI/Pages/ProgressPage.xaml.cs — Rollback confirmation dialog
  • src/OpenClaw.SetupEngine/SetupContext.cs — Config classes, timeout helpers
  • src/OpenClaw.SetupEngine/SetupPipeline.cs — Rollback confirmation callback
  • src/OpenClaw.SetupEngine/SetupSteps.cs — All 7 bug fixes + timeout extraction
  • src/OpenClaw.SetupEngine/SetupWizardRunner.cs — Wizard timeout extraction
  • src/OpenClaw.SetupEngine/default-config.json — All new config entries with comments

Fix 7 bugs found during setup testing on slow ARM64 machines with WSL2
mirrored networking, plus a full audit of hardcoded config values.

Critical fixes:
- WebSocket default URL used localhost which resolves to IPv6; WSL2
  mirrored networking only forwards IPv4. Changed to 127.0.0.1.
- PairNodeStep health check also used localhost (same IPv6 issue).

High-priority fixes:
- WaitForConnectionOrPairing resolved immediately on first Error or
  Disconnected, killing connections before WebSocket auto-reconnect
  could retry. Now only resolves on Connected or PairingRequired;
  timeout catches unreachable gateways.
- StartGatewayStep only checked health from inside WSL, not from
  Windows. Added WaitForWindowsPortReachable() to poll from Windows
  side after WSL health check passes.

Medium fixes:
- Hardcoded 15s/20s pairing timeouts too short for slow machines.
  Replaced with configurable Pairing.TimeoutSeconds (default 60s).

Low-priority fixes:
- Port conflict detection missed node gateway processes (matched
  only openclaw, but gateway runs as node).
- Added rollback confirmation dialog in UI mode (keep state for
  debugging vs rollback).

Bonus fix:
- TryRevokeOperatorTokenAsync used hardcoded ws://localhost:18789
  fallback instead of configured EffectiveGatewayUrl.

Config audit:
- Replaced CommandTimeoutMultiplier (1 multiplier x 48 individual
  values) with 2-tier model: CommandTimeoutSeconds (60s) for standard
  WSL commands, InstallTimeoutSeconds (600s) for downloads/installs.
- Extracted WindowsPortTimeoutSeconds, StabilizationDelaySeconds,
  WizardConfig (RequestTimeoutSeconds, AuthStepTimeoutSeconds),
  RollbackTimeoutSeconds into default-config.json.

Review fixes (Hanselman dual-model review):
- DispatcherQueue.TryEnqueue return value now checked to prevent
  deadlock if dispatcher shuts down during rollback confirmation.
- Dialog dismiss (ESC/close) now defaults to rollback (safer).
- Added RunContinuationsAsynchronously to TCS.

Co-authored-by: Copilot <[email protected]>
@clawsweeper

clawsweeper Bot commented May 26, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed May 26, 2026, 7:40 PM ET / 23:40 UTC.

Summary
This PR changes SetupEngine loopback defaults to 127.0.0.1, extracts setup/wizard timeouts into config, adds Windows-side gateway reachability waits, changes pairing reconnect behavior, adds rollback confirmation UI, and updates related tests.

Reproducibility: no. high-confidence runtime reproduction was performed for the target slow ARM64 WSL2 machine. Source inspection does confirm the current-main localhost default and immediate Error handling paths the PR is trying to change.

Review metrics: 1 noteworthy metric.

  • Diff size: 9 files changed, +300/-99. The PR changes setup runtime behavior, config defaults, UI rollback behavior, and tests, so upgrade and real-machine proof matter before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Add redacted slow ARM64 WSL2 mirrored-networking proof showing the setup path succeeds after the change.
  • Narrow the node port-owner exemption to actual OpenClaw gateway processes.
  • Handle terminal auth Error statuses promptly while still allowing transient reconnect retries.

Proof guidance:
Needs real behavior proof before merge: The PR body says validation is pending and no after-fix real-machine proof is attached; add redacted terminal output, logs, screenshots, recording, or an artifact, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • Changing generated gateway and dashboard URLs from localhost to 127.0.0.1 is intentional, but it still needs upgrade proof across normal Windows and slow WSL2 mirrored-networking setups.
  • The node process exemption can let an unrelated Node.js service on the gateway port bypass conflict detection and turn a clear preflight error into a later setup failure.
  • Ignoring terminal Error statuses can stretch invalid-token or rejected-auth paths to the full pairing timeout instead of returning promptly.
  • No after-fix real behavior proof is attached for the slow ARM64 WSL2 scenario the PR is designed to fix.

Maintainer options:

  1. Fix the setup edge cases first (recommended)
    Narrow the node port exemption to OpenClaw gateway command lines and keep transient reconnect retries without swallowing terminal auth failures.
  2. Hold for slow-machine proof
    Keep the PR draft or blocked until redacted logs, terminal output, or a recording show the changed flow succeeding on the target slow ARM64 WSL2 setup.
  3. Accept the timeout behavior explicitly
    Maintainers could accept longer failure waits, but that should be a deliberate setup UX decision rather than an accidental result of ignoring every Error status.

Next step before merge
Contributor action is needed for real slow-machine proof, and maintainer review should confirm the narrowed port/auth repairs before merge.

Security
Cleared: No concrete security or supply-chain regression was found in the diff; the token and credential-adjacent changes stay within existing local setup flows.

Review findings

  • [P2] Constrain the node process exemption — src/OpenClaw.SetupEngine/SetupSteps.cs:970
  • [P3] Return promptly on terminal auth errors — src/OpenClaw.SetupEngine/SetupSteps.cs:1509
Review details

Best possible solution:

Land the slow-machine setup fixes after narrowing the port-owner check, preserving prompt terminal auth failure handling, and adding redacted target-environment proof for both fresh setup and the changed default URL path.

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

No high-confidence runtime reproduction was performed for the target slow ARM64 WSL2 machine. Source inspection does confirm the current-main localhost default and immediate Error handling paths the PR is trying to change.

Is this the best way to solve the issue?

No, not yet: the direction is plausible, but the current implementation should narrow the node port exemption, preserve prompt terminal auth failures, and include real target-machine proof before merge.

Full review comments:

  • [P2] Constrain the node process exemption — src/OpenClaw.SetupEngine/SetupSteps.cs:970
    This now treats any listener whose ss output contains node as if it is the OpenClaw gateway. If another Node.js app is already bound to the gateway port, setup will proceed past preflight and then fail or wait in openclaw gateway start instead of reporting the real conflict. Please match the command line/path to the OpenClaw gateway process, not the generic node process name.
    Confidence: 0.88
  • [P3] Return promptly on terminal auth errors — src/OpenClaw.SetupEngine/SetupSteps.cs:1509
    The setup wait now ignores every ConnectionStatus.Error. OpenClawGatewayClient raises Error for terminal auth failures and stops auto-reconnect once _authFailed is set, so invalid tokens or rejected device signatures will sit until the full pairing timeout. Keep the transient-disconnect retry behavior, but resolve terminal/auth errors immediately, for operator and node waits.
    Confidence: 0.82

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 4133ae1c7065.

Label changes

Label justifications:

  • P2: This is a normal-priority setup reliability improvement with limited blast radius, but the PR still has concrete merge-blocking edge cases.
  • merge-risk: 🚨 compatibility: The PR changes persisted/default loopback URLs and setup timeout/config behavior that existing local setup assumptions may notice on upgrade.
  • merge-risk: 🚨 availability: The port-owner and terminal-error changes can make setup fail later or wait longer instead of returning clear availability failures.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body says validation is pending and no after-fix real-machine proof is attached; add redacted terminal output, logs, screenshots, recording, or an artifact, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

What I checked:

  • Repository policy read: AGENTS.md was read fully; its setup/connection guidance led the review to inspect connection architecture, onboarding setup behavior, and setup validation expectations without running build/tests in this read-only review. (AGENTS.md:1, 4133ae1c7065)
  • Setup docs checked: Connection and onboarding docs confirm gateway registry, credential precedence, pairing, and local WSL setup are central behavior for this PR. (docs/CONNECTION_ARCHITECTURE.md:1, 4133ae1c7065)
  • Port conflict regression in PR diff: The PR treats any ss output containing node as OpenClaw-owned, which can skip a real port conflict from an unrelated Node.js process. (src/OpenClaw.SetupEngine/SetupSteps.cs:970, cc9febd1a148)
  • Terminal auth errors stop auto-reconnect: Current main's gateway client marks terminal auth failures with ConnectionStatus.Error and ShouldAutoReconnect returns false once _authFailed is set, so the PR should not ignore all Error statuses. (src/OpenClaw.Shared/OpenClawGatewayClient.cs:160, 4133ae1c7065)
  • PR ignores Error statuses: The PR removes immediate Error handling in operator and node setup waits, so terminal auth failures can wait for the full pairing timeout instead of failing promptly. (src/OpenClaw.SetupEngine/SetupSteps.cs:1509, cc9febd1a148)
  • Real behavior proof missing: The PR body explicitly says slow ARM64 WSL2 validation is pending, and the provided GitHub context contains no after-fix logs, terminal output, screenshots, recording, or linked artifact. (cc9febd1a148)

Likely related people:

  • ranjeshj: Introduced the out-of-process SetupEngine and owns the central setup, pairing, wizard, and UI files touched by this PR in current main history. (role: feature owner and recent area contributor; confidence: high; commits: cefce3952ab1, 6bd98858e618; files: src/OpenClaw.SetupEngine/SetupSteps.cs, src/OpenClaw.SetupEngine/SetupContext.cs, src/OpenClaw.SetupEngine/SetupWizardRunner.cs)
  • Scott Hanselman: Recently changed setup-related test quality and coverage, making them a plausible reviewer for the test expectations around this setup flow. (role: recent adjacent test contributor; confidence: medium; commits: 16399edfb05c; files: tests/OpenClaw.SetupEngine.Tests, tests/OpenClaw.E2ETests/Setup)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 May 26, 2026
@clawsweeper

clawsweeper Bot commented May 26, 2026

Copy link
Copy Markdown

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

ranjeshj and others added 2 commits May 26, 2026 14:01
Update SetupEngine and E2E assertions to match intentional setup default host
change from localhost to 127.0.0.1.

Fixes CI failures in:
- OpenClaw.SetupEngine.Tests (EffectiveGatewayUrl_UsesPort, GatewayUrl_DefaultsFromConfig)
- OpenClaw.E2ETests (gateway URL and dashboard URL host assertions)

Co-authored-by: Copilot <[email protected]>
Wait for Windows-side gateway reachability before replaying wizard
steps after restart-like disconnects, and use a reconnect timeout
bounded by pairing and gateway health settings.

Co-authored-by: Copilot <[email protected]>
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. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant