Skip to content

fix(connection): recover saved SSH tunnels after disconnect - #1070

Merged
shanselman merged 2 commits into
mainfrom
fix/pairing-pond-20260730
Jul 31, 2026
Merged

shanselman merged 2 commits into
mainfrom
fix/pairing-pond-20260730

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where users connecting the Windows tray to a remote Gateway through a saved SSH tunnel would stay disconnected after the tunnel process exited. The tray scheduled a restart, but the recovery path checked obsolete global SSH settings instead of the active saved gateway.

Why This Change Was Made

Recovery now goes through the owner of the failed tunnel:

  • GatewayConnectionManager owns registry-backed tunnels and may reconnect the gateway clients.
  • Settings-owned tunnels restart only the exact failed tunnel generation and configuration.

Tunnel exits carry the exact configuration, owner, and lifecycle generation that failed, so delayed callbacks cannot reconnect a different gateway or clear a replacement process. Automatic recovery uses bounded 3, 10, and 30 second retries, stops after three failures in five minutes, and re-arms after successful automatic or manual recovery.

User Impact

Remote Gateway connections configured in the gateway registry recover automatically when their SSH forward drops and becomes available again. Existing device and node pairing remain valid; users do not need to pair again. Repeated failures stop with an honest failed state instead of causing an unlimited reconnect loop.

Evidence

  • Built and tested the original recovery patch in a native CRLF checkout on an on-demand AWS Windows desktop.
  • Ran a Linux Gateway on a separate AWS Linux host and connected the Windows tray through an SSH forward.
  • Completed both pairing stages: operator device approval, then Windows node approval.
  • Verified local MCP tool discovery and device.info.
  • Verified gateway-mediated device.info.
  • Removed the transport carrying the Windows-to-Linux SSH route. The tray recorded tunnel.restart_scheduled and retried through the active gateway record.
  • Restored the transport. The tray recreated one SSH process, returned to Connected, retained the same paired node identity, reported zero pending approvals, and passed local MCP plus gateway-mediated device.info again.
  • Current-head ownership, generation, failure-state, retry-budget, and recovery re-arm behavior is covered by deterministic unit and contract tests.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Validation

Current head: 21fd3491a70ca5e865e607d08533c361a8f5ab63

  • .\build.ps1
    • passed: Shared, CLI, WinNode CLI, SetupEngine, WinUI
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore
    • 3,399 passed, 32 skipped
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore
    • 2,023 passed
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore
    • 529 passed
  • git diff --check
    • passed

Real Behavior Proof

  • Environment tested for the original recovery behavior: on-demand AWS Windows desktop, AWS Linux Gateway, and an SSH transport between them
  • Runtime-tested commit: 0fa8a2e6
  • Exact steps:
    • launched the patched tray with an isolated data directory
    • approved operator device pairing and node pairing
    • ran winnode --list-tools
    • ran local winnode --command device.info --params "{}"
    • ran gateway-mediated nodes invoke --command device.info
    • removed and restored the task-owned SSH transport
  • Evidence after fix:
    • one tray-owned SSH process listening on the configured local Gateway port
    • diagnostics progressed from tunnel.restart_scheduled to Connected
    • the same node identity remained paired: true, connected: true, and approvalState: approved
    • device pending count: 0
    • node pending count: 0
    • local MCP device.info: success
    • gateway-mediated device.info: success
  • Observed result: the registry-backed tunnel recovered without restarting the tray or repeating either pairing stage
  • Screenshot or artifact links verified? N/A
  • Not verified or blocked: the external multi-host SSH fault-injection proof was not rerun on current head because the prior on-demand hosts are no longer available. Current-head state-machine behavior is covered by the validation above.
  • Rubber-duck review: two independent final reviews found no blockers. Merge confidence was 97% and 93% after verifying ownership, lifecycle generation, bounded recovery, success re-arm, and manual recovery paths.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? No
  • Command or tool execution surface changed? No
  • Data access scope changed? No
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? Yes
  • Config or environment changes? No
  • Migration needed? No
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

@clawsweeper clawsweeper Bot added 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. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 5:53 PM ET / 21:53 UTC.

ClawSweeper review

What this changes

The PR routes failed saved-gateway SSH tunnels through the connection manager, adds lifecycle-aware restart handling and bounded retries, and adds connection and tray tests.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 4 items remain

Keep this member-authored PR open for maintainer review. Current main has the reported ownership mismatch, and the branch follows the documented direction by moving registry-backed SSH tunnel recovery through the connection manager; no discrete correctness defect was found in the reviewed patch.

Priority: P2
Reviewed head: 21fd3491a70ca5e865e607d08533c361a8f5ab63
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source review and focused tests are strong, but final-head real SSH failure-and-recovery evidence remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR documents a detailed real multi-host recovery run at 0fa8a2e6, but the final hardening head 21fd3491 has no inspectable current-head fault-injection artifact; add redacted diagnostics or live output showing recovery on the final head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR documents a detailed real multi-host recovery run at 0fa8a2e6, but the final hardening head 21fd3491 has no inspectable current-head fault-injection artifact; add redacted diagnostics or live output showing recovery on the final head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main defect: Current main handles a tunnel exit by waiting and calling EnsureStarted only when global settings enable SSH. That path does not inspect the active registry gateway or reconnect its clients.
Documented ownership boundary: The connection architecture assigns SshTunnelService to GatewayConnectionManager and says a GatewayRecord SSH tunnel starts before client connection through the local forward.
Final patch behavior: The final head validates the failed tunnel's owner, configuration, active gateway, automatic-reconnect intent, and pending generation before disconnecting clients and reconnecting through the active gateway.
Findings None None.
Security None None.

How this fits together

The tray stores remote gateway records, optionally with SSH port-forward configuration. The connection manager starts that tunnel, connects operator and node clients through it, and publishes connection state to the tray UI.

flowchart LR
  A[Saved gateway record] --> B[SSH tunnel service]
  B --> C[Gateway connection manager]
  C --> D[Operator and node clients]
  B --> E[Unexpected tunnel exit]
  E --> F[Recovery ownership check]
  F --> C
  C --> G[Tray connection status]
Loading

Decision needed

Question Recommendation
Should automatic recovery of a saved gateway's SSH tunnel be an explicit GatewayConnectionManager lifecycle responsibility? Approve manager-owned recovery: Accept the connection manager as the recovery owner and merge once the final-head runtime evidence is accepted.

Why: The patch aligns with the documented tunnel ownership boundary but changes availability behavior for existing remote gateway setups, which requires maintainer confirmation rather than automated closure or merge.

Before merge

  • Resolve merge risk (P1) - Merging changes restart and reconnect sequencing for existing saved remote gateways, so maintainer confirmation of the manager-owned lifecycle contract is still needed.
  • Resolve merge risk (P1) - The supplied live SSH fault-injection run was performed at commit 0fa8a2e6; the final hardening commit 21fd3491 has stated test validation but no inspectable current-head live recovery artifact.
  • Complete next step (P2) - This member-authored availability change needs human confirmation of the connection-manager ownership contract and current-head runtime proof, not an automated repair lane.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Recovery surface 11 files affected, 834 added, 110 removed The branch changes tunnel lifecycle and gateway reconnect behavior across production code and focused connection/tray tests.

Merge-risk options

Maintainer options:

  1. Confirm contract and runtime evidence (recommended)
    Confirm that manager-owned recovery is intended and accept a redacted current-head SSH recovery trace before merge.
  2. Pause for lifecycle redesign
    Pause the PR if maintainers want saved-tunnel recovery to remain outside the manager-owned connection lifecycle.

Technical review

Best possible solution:

Adopt manager-owned recovery for registry-backed tunnels, preserve paired device identity through reconnect, and retain generation guards plus bounded retries so stale exits cannot revive replaced connections.

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

Yes, at source level. Current main restarts only through global SSH settings after an exit, while a registry-backed active gateway owns its tunnel through the connection manager; this read-only Linux review could not execute the native Windows path.

Is this the best way to solve the issue?

Yes, subject to the maintainer ownership decision. The branch removes the legacy settings-versus-registry mismatch rather than introducing a parallel client-recovery path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The manager-owned recovery path changes behavior for existing saved SSH tunnel configurations.
  • add merge-risk: 🚨 availability: Tunnel exit, restart, and gateway reconnect sequencing determine whether remote connections recover.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR documents a detailed real multi-host recovery run at 0fa8a2e6, but the final hardening head 21fd3491 has no inspectable current-head fault-injection artifact; add redacted diagnostics or live output showing recovery on the final head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: The PR addresses a bounded remote-gateway recovery bug without evidence of an emergency-wide outage.
  • merge-risk: 🚨 compatibility: The manager-owned recovery path changes behavior for existing saved SSH tunnel configurations.
  • merge-risk: 🚨 availability: Tunnel exit, restart, and gateway reconnect sequencing determine whether remote connections recover.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR documents a detailed real multi-host recovery run at 0fa8a2e6, but the final hardening head 21fd3491 has no inspectable current-head fault-injection artifact; add redacted diagnostics or live output showing recovery on the final head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Barbara Kudiess: Authored the immediately preceding current-main GatewayConnectionManager recovery work, which is the central subsystem this PR extends. (role: recent area contributor; confidence: high; commits: bc210e048aa9; files: src/OpenClaw.Connection/GatewayConnectionManager.cs)

Rank-up moves

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

  • Attach redacted current-head diagnostics or live output showing a saved tunnel exit, bounded retry, return to Connected, and preserved pairing.

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 (4 earlier review cycles)
  • reviewed 2026-07-30T16:14:31.373Z sha 4a1e456 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T16:59:25.267Z sha 0fa8a2e :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T03:41:10.256Z sha 0fa8a2e :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T21:17:11.700Z sha 0fa8a2e :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the fix/pairing-pond-20260730 branch from 4a1e456 to 0fa8a2e Compare July 30, 2026 16:33
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 30, 2026
@vincentkoc vincentkoc self-assigned this Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

ClawSweeper follow-up:

  • Inspected the failed network-recovery E2E job from workflow run 30562125176, attempt 1.
  • The setup failed before either recovery assertion ran: the pair-operator step reported Loopback port 56981 listener verification failed because the WSL wslrelay listener did not bind.
  • The identical PR head, 0fa8a2e6d37ac877669776f7ed3058b518021ed6, was rerun as attempt 2. Both network-recovery tests passed.
  • The same exact-head run also has green setup-connect E2E, revocation-recovery E2E, main tests, and win-x64/win-arm64 builds.

This classifies the initial result as a transient WSL setup/loopback failure, not a regression in the SSH tunnel lifecycle patch. The requested rank-up move is complete, so I am marking the PR ready for maintainer review.

Failed attempt: https://github.com/openclaw/openclaw-windows-node/actions/runs/30562125176/attempts/1

Passing rerun: https://github.com/openclaw/openclaw-windows-node/actions/runs/30562125176/attempts/2

@clawsweeper re-review

@vincentkoc
vincentkoc marked this pull request as ready for review July 31, 2026 03:37
@clawsweeper

clawsweeper Bot commented Jul 31, 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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 31, 2026
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 7b9bc681-ce19-4a8b-b06c-94efb63a5f9f
@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. 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. and removed proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 31, 2026
@shanselman
shanselman merged commit d7d153c into main Jul 31, 2026
29 checks passed
@shanselman
shanselman deleted the fix/pairing-pond-20260730 branch July 31, 2026 22:07
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: 🦐 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants