Skip to content

fix: harden gateway recovery credential handoffs - #1076

Merged
shanselman merged 30 commits into
openclaw:mainfrom
bkudiess:bkudiess-connection-analysis
Aug 8, 2026
Merged

shanselman merged 30 commits into
openclaw:mainfrom
bkudiess:bkudiess-connection-analysis

Conversation

@bkudiess

@bkudiess bkudiess commented Aug 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Harden operator/node credential handoff against stale replacement sockets and fail closed when SSH listener ownership becomes ambiguous.
  • Preserve paired device-token precedence across recovery, handshake replacement, direct-connect rollback, and late credential writers.
  • Keep direct-connect, SettingsManager, identity, tunnel, and prior healthy runtime state inside one rollback transaction.
  • Recover the live branch with ordinary commits only: revert superseded provenance/allocator work, merge canonical Harden managed Gateway release setup and restart recovery #1120 ownership from main, and preserve the fix: harden gateway recovery credential handoffs #1076 credential-handoff changes.
  • Stabilize the real SSH ownership proof without weakening it: Windows ssh.exe owns the forwarded listener, WSL sshd is the real server, and ProxyCommand wsl.exe ... nc carries only the SSH transport across mirrored-WSL route resets.

Ownership and ordering

Validation

Exact PR head: 59d1301c2836e83bc497a44d4f27e2870c6482aa

  • Merged current origin/main (20d29e1132c37a4c37ec4bb24de668fa665b613e) with an ordinary merge commit; no conflict-resolution edits were required.
  • ./build.ps1: passed.
  • Shared tests: 3,623 passed, 32 skipped, 0 failed.
  • Tray tests: 2,241 passed, 0 failed.
  • Connection tests: 574 passed, 0 failed.
  • SetupEngine tests: 739 passed, 0 failed.
  • Assigned total: 7,177 passed, 32 expected skips, 0 failed.
  • ./scripts/validate-mxc-e2e.ps1: strict 15/15 passed without -AllowSkip (TestResults\E2E\82613ad8).
  • Exact-head SSH ownership/UI proof: 3/3 passed (TestResults\E2E\46d67f3c).
  • Structured autoreview: full fix: harden gateway recovery credential handoffs #1076 source review clean at bb78e548; exact three-file main integration overlap review clean at 59d1301c. The helper correctly refused the redundant whole-branch rerun because the committed PNG proof is binary.
  • Exact-head rubber-duck review: clean, no actionable defects.
  • GitHub required checks: green on exact head 59d1301c. The broad test lane passed on an unchanged-SHA rerun after the known transient SystemRun_Where_ReturnsExpectedOutput timeout; all three E2E shards and both architecture builds passed.

Real behavior proof

The exact-head proof used real Windows ssh.exe, real isolated WSL sshd, real port forwarding, and an isolated OpenClaw Gateway/tray profile. It verified:

  • the owning SSH listener is recognized;
  • a competing listener is rejected before either operator or node credential frames are sent;
  • the externally visible connection state becomes Degraded and node state becomes Error with the credential-withholding diagnostic;
  • the adversary can be removed and the same strong operator/node credentials recover the connection without downgrade;
  • initial operator and node handshake replacement authorizes only the current socket generation;
  • direct-connect rollback restores the previous registry/settings/identity/tunnel/runtime state and rejects late writers;
  • the degraded UI screenshot was captured from the current head.

Proof artifact: TestResults\E2E\46d67f3c\pr1076-proof\proof-summary.json.

The user's existing paired Gateway was not mutated. Earlier read-only paired-path attempts were blocked by unavailable SSH/direct transport; all successful destructive and rollback proof ran only against the isolated test Gateway/profile.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Codex review: found issues before merge. Reviewed August 7, 2026, 8:41 PM ET / August 8, 2026, 00:41 UTC.

ClawSweeper review

What this changes

This PR adds fail-closed SSH listener checks before gateway credential handoffs and makes direct-connect persistence and rollback transactional.

Merge readiness

⛔ Blocked by patch quality or review findings - 5 items remain

Keep open. The central hardening is not on current main, but the published proof still identifies an earlier commit rather than the current PR head, so it is not yet merge-ready.

Priority: P1
Reviewed head: 59d1301c2836e83bc497a44d4f27e2870c6482aa

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 3 items Published proof is not bound to the reviewed head: The proof summary in the exact current PR tree names commit 31e1563, while the reviewed PR head is 59d1301; its related handshake artifacts name the same earlier commit.
The prerequisite merged work is on main: Merged #1120 is present on current main, but it is a prerequisite recovery/provenance stack rather than this PR's remaining credential-handoff change.
Current main lacks the proposed persistence failure seam: Current main's SettingsManager catches persistence exceptions inside Save, whereas this PR adds the throwing persistence path used by its direct-connect rollback transaction.
Findings 1 actionable finding [P2] Refresh the proof artifact for the final head
Security None None.

How this fits together

The tray connects operator and Windows-node clients to a saved Gateway, optionally through an SSH tunnel. This path resolves credentials, establishes the two sessions, and persists gateway and settings state used by later reconnects.

flowchart LR
  A[Saved gateway record] --> B[Connection manager]
  B --> C[SSH listener ownership check]
  C --> D[Credential handoff]
  D --> E[Operator and node sessions]
  B --> F[Direct-connect transaction]
  F --> G[Registry settings and identity rollback]
Loading

Before merge

  • Refresh the proof artifact for the final head (P2) - The committed summary identifies 31e15639, not the reviewed 59d1301c head. The later integration changed the proof and recovery path, while the PR body only names a local test-results path, so publish redacted inspectable output or metadata bound to the final head before merge.
  • Resolve merge risk (P1) - The committed proof package does not demonstrate the exact current head after the later integration commits, leaving the credential-withholding and recovery claims unverifiable from published evidence.
  • Resolve merge risk (P1) - This 68-file change spans credential persistence, tunnel ownership, connection state, and WinUI recovery paths, so accepting unbound proof would leave compatibility and availability regressions insufficiently checked.
  • Complete next step (P2) - The contributor needs to supply inspectable exact-head real-behavior proof; this cannot be safely produced by an automated repair lane.
  • Improve patch quality - Address the highest-priority review finding and re-run the changed-surface validation.

Findings

  • [P2] Refresh the proof artifact for the final head — docs/proof/pr1076/proof-summary.json:2
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Review surface 68 files, +6,317/-677 lines The patch crosses connection, persistence, SSH, UI, CI, and E2E boundaries, making exact-head behavioral evidence especially important.

Merge-risk options

Maintainer options:

  1. Publish final-head recovery evidence (recommended)
    Add a redacted artifact or copied live output tied to 59d1301 that shows listener rejection, credential withholding, and successful recovery before merge.
  2. Accept the evidence gap explicitly
    A maintainer may accept the prose-only current-head assertion, but this retains unresolved verification risk across credential and recovery behavior.

Technical review

Best possible solution:

Publish a redacted, inspectable exact-head proof summary or artifact that records commit 59d1301 and the three SSH ownership outcomes, then complete focused maintainer review of the credential and rollback paths.

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

Yes. Inspecting the exact-head committed proof summary reproduces the evidence gap: it records 31e1563 instead of the reviewed 59d1301 head.

Is this the best way to solve the issue?

No. The hardening approach is plausible and covered by focused tests, but the published evidence must be refreshed to prove that the final integrated head retains the claimed behavior.

Full review comments:

  • [P2] Refresh the proof artifact for the final head — docs/proof/pr1076/proof-summary.json:2
    The committed summary identifies 31e15639, not the reviewed 59d1301c head. The later integration changed the proof and recovery path, while the PR body only names a local test-results path, so publish redacted inspectable output or metadata bound to the final head before merge.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P1: The PR changes live gateway recovery and operator/node credential handoff behavior.
  • merge-risk: 🚨 compatibility: Direct-connect persistence and rollback can affect existing saved gateways, identities, and recovery behavior.
  • merge-risk: 🚨 security-boundary: The patch changes when strong operator and node credentials may be sent through an SSH-forwarded local endpoint.
  • merge-risk: 🚨 availability: Fail-closed listener validation and rollback behavior can leave active gateway sessions degraded if recovery is incorrect.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

Likely related people:

  • shanselman: Merged the current-main recovery prerequisite and authored the recent branch integration and proof-stabilization commits. (role: recent gateway recovery contributor; confidence: high; commits: 01faa6419b42, 4cd3f1d492a7, 59d1301c2836; files: src/OpenClaw.Connection/GatewayConnectionManager.cs, src/OpenClaw.Connection/SshTunnelService.cs)
  • bkudiess: Current-main history credits this contributor with prior local gateway recovery and device-identity hardening work, as well as the initial commits in this PR. (role: earlier connection-recovery contributor; confidence: high; commits: bc210e048aa9, c04c5fb06238, d8110443e34e; files: src/OpenClaw.Connection/GatewayConnectionManager.cs, src/OpenClaw.Shared/DeviceIdentity.cs)
  • vincentkoc: Current-main history includes the SSH tunnel recovery work adjacent to the listener-ownership behavior changed here. (role: recent SSH-tunnel contributor; confidence: medium; commits: d7d153ca5d40; files: src/OpenClaw.Connection/SshTunnelService.cs, src/OpenClaw.Connection/GatewayConnectionManager.cs)

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 (24 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-05T11:02:28.695Z sha c571ed4 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T11:12:03.532Z sha c571ed4 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T16:02:27.459Z sha c571ed4 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T22:11:43.107Z sha c571ed4 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-06T23:38:15.044Z sha 4cd3f1d :: needs maintainer review before merge. :: none
  • reviewed 2026-08-07T07:57:30.614Z sha 3aa3ba7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-07T23:33:58.623Z sha bb78e54 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-08T00:13:54.882Z sha bb78e54 :: found issues before merge. :: [P2] Refresh the proof artifact for the final head

@bkudiess
bkudiess force-pushed the bkudiess-connection-analysis branch from 313885c to 0462436 Compare August 3, 2026 17:09
@bkudiess

bkudiess commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 3, 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:

@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 3, 2026
@bkudiess

bkudiess commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 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:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 4, 2026
@bkudiess

bkudiess commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@bkudiess

bkudiess commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 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:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 4, 2026
@clawsweeper clawsweeper Bot added the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Aug 7, 2026
Reverts the superseded five-file provenance and allocator implementation from 3aa3ba7 before integrating the validated owners from #1120.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Merge current main after #1120 while preserving #1076 credential-handoff behavior and the validated conflict resolutions.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Port the validated acceptance synchronization, mirrored-WSL SSH endpoint, and denied-socket handling from integration commit 4969bbef.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Restore #1120's typed listener-snapshot failure reason after the PR recovery merge while retaining #1076 credential-handoff changes in their owning components.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Restore the two canonical #1120 setup regression tests that were dropped by the #1076 merge conflict resolution.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 7, 2026
Route isolated proof SSH through a WSL stdio proxy so mirrored localhost route loss cannot invalidate recovery. Poll complete listener and connection snapshots while preserving real OpenSSH forwarding and fail-closed credential assertions.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Keep bounded preflight readiness retries and continue asserting the visible degraded state alongside fail-closed credential withholding.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Keep the readiness retry within a single 30-second wall-clock deadline and cap each SSH attempt at five seconds.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Cap both SSH attempts and retry backoff against a Stopwatch-based 30-second budget.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
Break before constructing an attempt timeout when the monotonic preflight budget is exhausted.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 7, 2026

@shanselman shanselman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the final bb78e54 head after full build/tests, strict MXC 12/12, exact-head SSH/UI proof 3/3, structured autoreview, and rubber-duck review. No actionable findings.

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

Copilot-Session: 84bc73e4-939a-4e25-ba88-26af9f4fc8b5
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. 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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