Skip to content

Harden gateway connection and pairing flows#741

Draft
ranjeshj wants to merge 1 commit into
openclaw:mainfrom
ranjeshj:user/ranjeshj/connectionfixes
Draft

Harden gateway connection and pairing flows#741
ranjeshj wants to merge 1 commit into
openclaw:mainfrom
ranjeshj:user/ranjeshj/connectionfixes

Conversation

@ranjeshj

Copy link
Copy Markdown
Collaborator

Summary

Harden Windows companion gateway connection, setup-code pairing, node pairing, token recovery, and browser-control auth flows.

Key changes:

  • keep operator and node WebSocket lifecycles separate, with setup-code operator connects using role=operator
  • persist all returned role handoff tokens from hello-ok.auth.deviceTokens[]
  • clear bootstrap credentials only after required role tokens are durably readable
  • forward node device-token receipt from WindowsNodeClient through NodeConnector so bootstrap cleanup can complete after node reconnect
  • request and handle pairing scopes correctly, including response-aware node/device approval and admin-gated fallback
  • prevent stale node clients from mutating current state and abort node handshakes when capability registration fails
  • preserve shared-token HTTP/dashboard/browser-control semantics, including browser proxy registration only when a shared gateway token is available
  • add local MCP-only connection controls without exposing them through the gateway node transport
  • add WSL setup retry for transient post-terminate /etc/wsl.conf read timing while keeping config validation strict
  • add protocol research documentation and expanded connection/E2E coverage

Validation

  • ./build.ps1 passed
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore passed
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore passed
  • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj --no-restore passed
  • dotnet test ./tests/OpenClaw.SetupEngine.Tests/OpenClaw.SetupEngine.Tests.csproj --no-restore passed
  • OPENCLAW_RUN_E2E=1 dotnet test ./tests/OpenClaw.E2ETests/OpenClaw.E2ETests.csproj -r win-arm64 --no-restore passed: 17/17
  • Copilot autoreview clean: no accepted/actionable findings
  • Dual-model protocol audit completed; accepted multi-role handoff finding fixed and revalidated

Notes

Draft PR for review. The changes intentionally avoid broad WebSocket lifecycle rewrites or gateway-side assumptions; fixes are scoped to client-side behavior verified against docs/CONNECTION_PROTOCOL_RESEARCH.md and docs/CONNECTION_ARCHITECTURE.md.

Consolidate the connection/pairing hardening work into one validated change set.

Connection and credential handling:
- keep gateway credentials registry-backed and preserve strict credential precedence: device token, shared gateway token, then bootstrap token
- force fresh setup-code bootstrap credentials for immediate QR/setup-code pairing while preserving shared gateway tokens for HTTP/dashboard paths
- dedupe loopback-equivalent gateway URLs so localhost and 127.0.0.1 records do not split pairing state
- validate replacement shared tokens before disconnecting or clearing durable device tokens
- clear stale bootstrap tokens only after required role tokens are durably readable
- recover stale operator device-token mismatches by falling back to bootstrap when recovery material is still present

Operator/node pairing and token lifecycle:
- keep operator clients in the operator role during bootstrap while preserving explicit node bootstrap behavior
- persist role-specific handoff tokens from hello-ok auth.deviceTokens[] for both operator and node roles
- forward WindowsNodeClient node-token receipt through NodeConnector so GatewayConnectionManager can complete bootstrap cleanup after the node token becomes durable
- request operator.pairing with normal shared-token operator connects so node trust approvals can be reached
- wait for node/device pair approval responses instead of treating a sent frame as success
- fall back from node.pair.approve to device.pair.approve only when admin authority is available
- guard node connection events by client generation so stale clients cannot mutate current state
- abort node handshake when pre-connect capability binding fails, preventing caps=0/cmds=0 registrations

Tray, MCP, and browser-control behavior:
- expose connection-control MCP tools only through local MCP, not the gateway node transport
- route MCP setup-code and shared-token connection tools through GatewayConnectionManager
- refresh gateway node state when local node connected/paired events arrive
- register browser.proxy only when a live gateway client and shared gateway token are available, and use the shared token for browser-control HTTP auth

Setup and reliability:
- add bounded retry for transient WSL startup timing when validating /etc/wsl.conf after WSL terminate/apply-config
- keep invalid wsl.conf content validation strict after the read succeeds
- preserve SSH tunnel behavior for operator and node connection paths

Maintainability simplifications:
- reuse setup-code gateway lookup state in GatewayConnectionManager
- centralize delayed reconnect scheduling with generation/disposal guards
- centralize response-aware pair approval RPC handling
- consolidate operator scope helper literals and checks

Validation:
- build.ps1 passed
- OpenClaw.Shared.Tests passed
- OpenClaw.Tray.Tests passed
- OpenClaw.Connection.Tests passed
- OpenClaw.SetupEngine.Tests passed
- full OpenClaw.E2ETests passed with OPENCLAW_RUN_E2E=1 and win-arm64 runtime
- targeted QR/setup-code E2E tests passed after audit follow-up
- Copilot autoreview passed with no accepted/actionable findings
- dual-model protocol audit completed; accepted multi-role handoff finding fixed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ranjeshj ranjeshj force-pushed the user/ranjeshj/connectionfixes branch from e27427c to 6b93d72 Compare June 10, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant