Skip to content

Harden managed Gateway release setup and restart recovery - #1120

Merged
shanselman merged 17 commits into
mainfrom
shanselman-validate-restart-stack
Aug 7, 2026
Merged

shanselman merged 17 commits into
mainfrom
shanselman-validate-restart-stack

Conversation

@shanselman

@shanselman shanselman commented Aug 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • prove app-managed relayless Gateway ownership before strong credentials or repair actions
  • allocate mirrored-WSL-safe Gateway ports and verify the selected port through setup and MXC E2E coverage
  • restore the intended Gateway reload default
  • preserve WebSocket close 1012 details, invalidate stale handshakes, and recover the exact Gateway 2026.7.1 final model-check restart
  • keep managed-local replay fail-closed: temporary NoListener and the typed listener-snapshot race may retry inside the existing bound; every other unknown, conflicting, incomplete, or changed owner fails immediately
  • keep retryable Gateway startup close 1013 inside the restart reconnect timeout while initial pairing and all other close codes retain immediate failure behavior
  • keep bootstrap credential cleanup retryable when an atomic gateway-registry save fails, without exposing an in-memory state that was not durably persisted

Architecture ownership

The old restart classification and retry behavior was split across WizardPage and SetupWizardRunner. GatewayWizardRestartRecoveryPolicy now owns exact-version terminal classification and bounded restart provenance/reconnect policy, while hosted and headless callers retain lifecycle application. The preserved invariant is that no credential is sent until the managed endpoint is verified, and terminal success requires a fresh authenticated hello-ok.

GatewayRegistry remains the authoritative persistence owner. Its atomic update-and-save operation now rolls back the in-memory record if persistence fails, so credential cleanup can be retried by the next connection lifecycle event without memory/disk divergence.

Validation

Validated pushed head: e359b8f02782e2f2d4501b72bebd987a8bb022c9

  • $env:OPENCLAW_REPO_ROOT=(Get-Location).Path; .\build.ps1: passed, 45 documentation files and all 5 projects
  • focused bootstrap cleanup and registry durability tests: 45 passed, 0 failed, 0 skipped
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore: 543 passed, 0 failed, 0 skipped
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore: 738 passed, 0 failed, 0 skipped
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 3,413 passed, 0 failed, 32 skipped
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 2,166 passed, 0 failed, 0 skipped
  • Gateway 2026.7.1 isolated setup E2E: 16 passed, 0 failed, 0 skipped
  • .\scripts\validate-mxc-e2e.ps1 without -AllowSkip: 12 passed, 0 failed, 0 skipped
  • two independent rubber-duck reviews found no blocking issue; the second review verified atomic rollback, lock/event behavior, persistence consistency, and retry coverage

CI blocker correction

The first PR check run exposed two source-owned restart races:

  • the fresh post-restart client received structured UNAVAILABLE / startup-sidecars, then WebSocket close 1013, which the setup waiter treated as terminal before automatic reconnect
  • relayless ownership snapshots could change during the two-phase restart inspection and return an untyped UnknownListener, which the bounded restart wait rejected before the endpoint settled

The second PR check run proved both restart fixes: the network-recovery and revocation-recovery shards passed. It then exposed a separate source-owned persistence race in reused setup-code pairing. Both durable role tokens were written, but bootstrap cleanup first changed the in-memory registry and then hit a transient access-denied error while saving. Later lifecycle events saw the in-memory null and could not retry, while disk still retained the bootstrap token.

The final fix keeps update, save, and rollback under the registry lock. Failed persistence leaves the prior in-memory token intact and emits no successful registry change; the next pairing or connection event retries the cleanup. Credential precedence and setup-code pairing behavior are unchanged.

The repeated hosted McpHttpServerIntegrationTests.SystemRun_Where_ReturnsExpectedOutput 10-second timeout is unrelated to this release stack and remains a rerunnable infrastructure failure; its command-execution source was not changed.

Real behavior proof

Gateway 2026.7.1 final isolated run 8d7904b1:

OpenClaw CLI version: OpenClaw 2026.7.1 (2d2ddc4)
Wizard step '[opaque]' (note, key=model-check) answered with 'true'
Server closed connection: 1012 - service restart
[HANDSHAKE] Received hello-ok!
Gateway restarted after applying the terminal 2026.7.1 wizard answer; endpoint ownership and the authenticated reconnect were verified.
Gateway wizard completed
Test Run Successful.
Total tests: 16
Passed: 16

Strict MXC final isolated run a27d70b5:

gateway system.run payload: exitCode=0; stdout=OPENCLAW_GATEWAY_SYSTEM_RUN_MXC_OK; stderrLength=0
system.run sandbox request executor=mxc-direct-appc; contained=True
system.run sandbox result exitCode=0; containment=mxc
MXC denied-write payload: exitCode=1; fileExists=False
Test Run Successful.
Total tests: 12
Passed: 12

No firewall dialog was observed. The worktree was clean after commit, the pushed SHA matched the remote branch, and git diff --check passed.

shanselman and others added 15 commits August 6, 2026 18:46
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 184fa070-4567-45dc-ac2d-c81c2840af14
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 184fa070-4567-45dc-ac2d-c81c2840af14
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 184fa070-4567-45dc-ac2d-c81c2840af14
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 184fa070-4567-45dc-ac2d-c81c2840af14
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 184fa070-4567-45dc-ac2d-c81c2840af14
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 15b5584f-677b-453f-8aa4-4f33fe60bc50
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 15b5584f-677b-453f-8aa4-4f33fe60bc50
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 15b5584f-677b-453f-8aa4-4f33fe60bc50
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 15b5584f-677b-453f-8aa4-4f33fe60bc50
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 15b5584f-677b-453f-8aa4-4f33fe60bc50
Classify the Gateway 2026.7.1 terminal restart from stable model-check context, and bound managed-local NoListener retries without weakening endpoint ownership checks.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper clawsweeper Bot added 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. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Aug 7, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Codex review: needs changes before merge. Reviewed August 7, 2026, 3:48 PM ET / 19:48 UTC.

ClawSweeper review

What this changes

The PR hardens managed Gateway setup, restart recovery, endpoint provenance, and durable credential cleanup with expanded Windows/WSL E2E coverage.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep open. The latest commit fixes the registry persistence race, but the previously reported restart-classification blocker remains on the current head.

Priority: P1
Reviewed head: e359b8f02782e2f2d4501b72bebd987a8bb022c9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The pinned-scenario proof is strong, but an ordinary setup route remains incorrect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies current-head isolated Gateway 2026.7.1 restart output with fresh hello-ok and MXC production-boundary output, though it does not cover the normal configured-LKG route behind the finding.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies current-head isolated Gateway 2026.7.1 restart output with fresh hello-ok and MXC production-boundary output, though it does not cover the normal configured-LKG route behind the finding.
Evidence reviewed 6 items Restart gate uses installation configuration: The terminal-restart branch checks _ctx.Config.Gateway.Version rather than the authenticated server version.
Normal LKG remains older than targeted recovery version: The LKG helper assigns 2026.6.11 when version is omitted, while the special recovery condition accepts only 2026.7.1.
Prior blocker remains unchanged: Neither the headless runner nor the setup redesign document changed after the earlier reviewed head, so both prior findings remain applicable.
Findings 2 actionable findings [P1] Classify the restart from the running Gateway version
[P3] Update the setup redesign reload-mode example
Security None None.

How this fits together

The setup engine provisions and pairs a managed Gateway, then tray and node clients reconnect through it. This change governs endpoint ownership checks, credential handling, WebSocket recovery, and the resulting authenticated session.

flowchart LR
A[Setup wizard answer] --> B[Restart recovery policy]
B --> C[Endpoint ownership check]
C --> D[Reconnect and hello handshake]
D --> E[Gateway registry cleanup]
E --> F[Tray and node connection]
C --> G[Fail closed on unknown owner]
Loading

Before merge

  • Classify the restart from the running Gateway version (P1) - The recovery gate still receives _ctx.Config.Gateway.Version, but GatewayLkgVersion.ApplyToConfig normally sets that to 2026.6.11. An app-managed Gateway later updated to 2026.7.1 therefore falls through to generic replay after its terminal 1012 instead of taking this exact recovery. Capture the authenticated hello-ok server version, or align and test the ordinary default path.
  • Update the setup redesign reload-mode example (P3) - The default has changed to hybrid, but docs/SETUP_ENGINE_REDESIGN.md still presents "ReloadMode": "hot". Update the documented example so generated setup configurations do not retain the obsolete reload strategy.
  • Resolve merge risk (P1) - A normal unpinned setup can run Gateway 2026.7.1 while retaining the configured 2026.6.11 LKG, leaving the intended terminal-restart recovery unreachable.
  • Complete next step (P2) - A narrow source-level repair can use the authenticated server version and add the missing ordinary-route regression test.

Findings

  • [P1] Classify the restart from the running Gateway version — src/OpenClaw.SetupEngine/SetupWizardRunner.cs:131-136
  • [P3] Update the setup redesign reload-mode example — src/OpenClaw.SetupEngine/default-config.json:90-91
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Changed surface 32 files, +1,968 / -100 lines The PR spans setup, connection, shared WebSocket behavior, workflow coverage, and Windows/WSL E2E infrastructure.
Production and tests production +615, tests +1,427 changed lines The test expansion supports a broad reliability change, but the ordinary setup route remains uncovered.

Merge-risk options

Maintainer options:

  1. Use the authenticated server version (recommended)
    Capture the version from the authenticated hello response and test that an LKG-configured setup reaching Gateway 2026.7.1 takes the bounded recovery path.
  2. Pause the release-stack change
    Keep the PR out of merge until the restart condition is reachable for the normal setup route.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Capture the authenticated hello version for terminal restart classification and add a regression test covering the default LKG configuration with a running 2026.7.1 Gateway.

Technical review

Best possible solution:

Classify the restart from the authenticated running Gateway version and cover the normal LKG configuration route before merge.

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

Yes, from source: apply the normal LKG configuration, run Gateway 2026.7.1, and trigger terminal model-check close 1012. The configured version remains 2026.6.11, so the exact recovery branch does not run.

Is this the best way to solve the issue?

No. The compatibility path is narrowly scoped, but it uses installation configuration rather than the authenticated running server version, which is the durable source of truth.

Full review comments:

  • [P1] Classify the restart from the running Gateway version — src/OpenClaw.SetupEngine/SetupWizardRunner.cs:131-136
    The recovery gate still receives _ctx.Config.Gateway.Version, but GatewayLkgVersion.ApplyToConfig normally sets that to 2026.6.11. An app-managed Gateway later updated to 2026.7.1 therefore falls through to generic replay after its terminal 1012 instead of taking this exact recovery. Capture the authenticated hello-ok server version, or align and test the ordinary default path.
    Confidence: 0.99
  • [P3] Update the setup redesign reload-mode example — src/OpenClaw.SetupEngine/default-config.json:90-91
    The default has changed to hybrid, but docs/SETUP_ENGINE_REDESIGN.md still presents "ReloadMode": "hot". Update the documented example so generated setup configurations do not retain the obsolete reload strategy.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: An intended recovery for a supported managed Gateway version is unreachable on the normal setup configuration.
  • merge-risk: 🚨 compatibility: The default setup configuration can leave existing managed Gateway upgrade and restart behavior unhandled.
  • merge-risk: 🚨 security-boundary: The PR modifies proof required before stronger credentials are sent to a managed local endpoint.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body supplies current-head isolated Gateway 2026.7.1 restart output with fresh hello-ok and MXC production-boundary output, though it does not cover the normal configured-LKG route behind the finding.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies current-head isolated Gateway 2026.7.1 restart output with fresh hello-ok and MXC production-boundary output, though it does not cover the normal configured-LKG route behind the finding.

Evidence

Acceptance criteria:

  • [P1] ./build.ps1.
  • [P1] dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore.
  • [P1] dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore.
  • [P1] dotnet test ./tests/OpenClaw.SetupEngine.Tests/OpenClaw.SetupEngine.Tests.csproj --no-restore.
  • [P1] ./scripts/validate-mxc-e2e.ps1.

What I checked:

Likely related people:

  • Barbara Kudiess: Current-main history includes the existing local Gateway recovery implementation. (role: recent area contributor; confidence: medium; commits: bc210e048aa9; files: src/OpenClaw.SetupEngine/SetupWizardRunner.cs)
  • AlexAlves87: Current-main history attributes the embedded Gateway LKG behavior to this contributor. (role: introduced LKG configuration; confidence: high; commits: f536bcf06559; files: src/OpenClaw.SetupEngine/GatewayLkgVersion.cs)
  • Vincent Koc: Current-main history includes WSL relay verification work by this contributor. (role: recent provenance contributor; confidence: medium; commits: 6e225e4758e1; files: src/OpenClaw.Connection/ManagedLocalGatewayPortProvenanceService.cs)

Rank-up moves

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

  • Capture the authenticated running Gateway version or align the supported version contract.
  • Add a regression case for the normal LKG-configured setup path.
  • Update the stale setup-redesign reload-mode example.

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 (2 earlier review cycles)
  • reviewed 2026-08-07T18:21:30.261Z sha 9b63aa1 :: found issues before merge. :: [P1] Classify the restart from the running Gateway version | [P3] Update the setup redesign reload-mode example
  • reviewed 2026-08-07T19:10:14.226Z sha 23654f2 :: needs changes before merge. :: [P1] Classify the restart from the running Gateway version | [P3] Update the setup redesign reload-mode example

Keep retryable startup close 1013 and typed listener snapshot changes inside the existing managed-local restart window while preserving immediate failure for every other unknown owner.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 7, 2026
Keep gateway registry memory aligned with persisted state when bootstrap credential cleanup cannot be saved, so later connection lifecycle events can retry safely.

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

Copilot-Session: 73908040-d4b7-493b-b024-b0c9ebcfc98d
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 7, 2026
@shanselman
shanselman merged commit 01faa64 into main Aug 7, 2026
26 checks passed
@shanselman
shanselman deleted the shanselman-validate-restart-stack branch August 7, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. 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.

1 participant