Skip to content

fix: tray connects to the Gateway as an interactive client - #1909

Merged
shanselman merged 2 commits into
openclaw:mainfrom
bkudiess:bkudiess-split-interactive-client
Oct 28, 2026
Merged

shanselman merged 2 commits into
openclaw:mainfrom
bkudiess:bkudiess-split-interactive-client

Conversation

@bkudiess

@bkudiess bkudiess commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: the tray's long-lived operator connection identifies itself as cli/cli, so the Gateway treats it as ephemeral and attaches no owner profile to it. Disconnect presence beacons from a previous connection can also appear active or take a live node from the current connection.

User Impact

User impact: the tray connects to the Gateway as an interactive Companion client, and stale disconnect beacons no longer show a node as active. No visible UI change. CLI, setup, validator and node connections are unchanged.

Why This Change Was Made

GatewayClientFactory.ClientIdentity (default Cli) is set to Interactive only by the tray composition root in App.xaml.cs. ConnectEnvelopeBuilder then uses gateway-client/ui for both the signed device payload and the serialized client, so they cannot disagree. InstanceMerger lets live beacons claim nodes before disconnect beacons, and a disconnect beacon is offline unless its node is still online. Existing device key, token, role and scopes are unchanged and there is no auth bypass. Two ledger rows are added to docs/ARCHITECTURE.md.

This is layer 2 of a local feature split; layer 1 (#1906) is merged.

Evidence

Run on this head with task-owned isolated profile roots, legacy OPENCLAW_TRAY_LOCAL_DATA_DIR unset and E2E/integration opt-ins unset:

  • ./build.ps1: exit 0
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj: 4693 passed, 25 skipped, 0 failed
  • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj: 1696 passed, 1 skipped, 0 failed
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj: 4686 passed, 0 failed
  • Focused: ConnectEnvelopeBuilderTests + InstanceMergerTests: 83 passed

New tests: Create_OperatorIdentityIsCliUnlessInteractiveRequested, OperatorIdentity_SignedAndSerializedIdentityMatch_WithoutChangingOtherFields, OperatorIdentity_RealDevicePayloadCoversChosenIdentity, DisconnectReason_IsNotActive_DespiteFreshTimestamp, Reconnect_OldDisconnectRowAndNewRow_OnlyNewIsActive_AndOwnsNode, ConnectedNode_IsNotOverridden_ByStaleDisconnectPresence, plus the AppRefactorContractTests composition guard.

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

Required proof pools

  • none: no WinUI visual, WSL/MXC, installer or GPU behavior changed. The change is a connect-envelope identity and presence-merge policy covered by unit and composition tests.

Validation

See Evidence for exact commands and counts.

Real Behavior Proof

  • Environment tested: real Gateway [email protected] (npm, dc2523e) as a task-owned node process on loopback 127.0.0.1 with token auth and isolated state/HOME. The harness drives the production OpenClawGatewayClient and InstanceMerger built from this head, with real Ed25519 device identities. No Companion UI, WSL or native MSIX Gateway was launched, and all profile roots were task-owned.
  • PR head or commit tested: 7125bca. Baseline built from 326884e (main).
  • Exact steps or command run: npm install [email protected] --ignore-scripts in a temp dir, then node openclaw.mjs gateway --port <free> --bind loopback --auth token --allow-unconfigured, then the harness scenarios below (token and IP values redacted).
  • Screenshot or artifact links verified? N/A (terminal evidence only; no UI claim).
# Scenario Result Redacted evidence
1 Interactive handshake PASS role=operator, clientId=gateway-client, mode=ui then DeviceTokenReceived ... HandshakeSucceeded after the pairing request was approved through the Gateway CLI (loopback does not auto-approve).
2 Owner-profile attachment and own-session access PASS RPC users.self => OK {"profile":{"id":"gateway-owner",...}}; sessions.create and chat.history on that session OK; presence lists the connection as mode=ui reason=connect.
3 Rejection of a different profile's private session BLOCKED by Gateway design With shared-token auth there is one gateway-owner profile. A second paired interactive device also resolves to gateway-owner and can read the first device's session. Upstream docs/concepts/multi-user.md states session ownership and visibility are usability features, not security boundaries, so there is no cross-profile rejection to exercise. The PR changes no auth, scopes or session access; the same Gateway session visibility applies to cli and ui connections.
4 Device-token revocation before history/dispatch PASS Before revoke, a device-token-only chat.send marker appears in admin history. After devices revoke, the live socket closes 4001 - device removed; reconnect and fresh device-token-only connections fail at handshake with AUTH_DEVICE_TOKEN_MISMATCH, so no chat.history or chat.send can run. Admin history: containsBefore=True containsAfter=False.
5 Existing pairing reconnect (cli/cli to gateway-client/ui) PASS A device paired as cli/cli reconnects as gateway-client/ui using only its stored device token: HandshakeSucceeded, PairingRequiredSeen=False, 0 pending pairing requests, users.self returns gateway-owner.
6 Stale-disconnect presence PASS Real Gateway presence holds the old connection as mode=ui reason=disconnect beside the new live one. HEAD InstanceMerger: ACTIVE rows: 1, old rows Offline.

Baseline (main 326884e) versus head on identical real data:

  • A cli/cli connection reaches hello-ok but users.self fails with users.self requires an authenticated user and the connection is not in presence (the Gateway treats cli as ephemeral). The gateway-client/ui connection gets the owner profile and appears in presence.
  • InstanceMerger on the same real presence payload: main reports ACTIVE rows: 5 (disconnect beacons shown Active or Idle); head reports ACTIVE rows: 1.

Isolation and cleanup: owned Gateway and worker PIDs were stopped by PID and none remain, and the port has no listener. Real %APPDATA%\OpenClawTray and ~\.openclaw were unchanged. Five files in real %LOCALAPPDATA%\OpenClawTray changed before this lab's Gateway started, with [test] log lines; no OpenClaw process of this lab was running then, so a concurrent unrelated test run is the likely writer (not proven).

  • Not verified or blocked: item 3 as above; the older extended-stable Gateway (2026.9.35) was not run; the stable-Companion check used the same production client with a cli/cli pairing, not the installed Companion app; no UI/visual proof.

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. Only the operator client id and mode strings change, and they are covered by the existing device signature.

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.

…on identity

The tray opts in to gateway-client/ui through GatewayClientFactory so the Gateway
treats its long-lived connection as interactive. CLI, setup, and validator clients
keep cli/cli. The signed device payload and serialized client use one identity.
Disconnect presence beacons no longer count as active or claim a live node.

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

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

The PR gives the tray an interactive Gateway identity and prevents stale disconnect beacons from claiming a live node.

Example: Companion reconnects while the Gateway retains earlier disconnect beacons.

  • Before: The cli/cli connection receives no owner profile, and the supplied baseline reports five active presence rows.
  • After: The gateway-client/ui connection receives the gateway-owner profile, and the same presence data produces one active row.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, useful correction with real production-client/Gateway evidence and current-head CI, without an actionable correctness or security finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): At the reviewed head, the production OpenClawGatewayClient and InstanceMerger ran against an isolated real [email protected] Gateway: interactive profile attachment, session access, existing-token reconnect, revoked-device rejection before history or dispatch, and stale-disconnect correction are recorded in terminal output; installed Companion and older extended-stable Gateway coverage are explicitly excluded.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Companion lacks Gateway owner attribution and can show disconnected clients as active after reconnecting.
Reason: The maintainer-authored direction addresses demonstrated production behavior while preserving existing connection ownership and credential policy.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses behavior still present on main, has relevant real-Gateway evidence, and introduces no actionable defect found in this review.

Priority: P2
Reviewed head: 7125bcafbdd502af5f9fa663e5e3643fbffaa67d

Before merge

None.

Findings

None.

Agent review details

How this fits together

App selects the operator identity through GatewayClientFactory, ConnectEnvelopeBuilder signs and serializes the handshake, and InstanceMerger combines Gateway presence and node data for the Instances page.

flowchart LR
  A[Tray composition root] --> B[GatewayClientFactory]
  B --> C[OpenClawGatewayClient]
  C --> D[ConnectEnvelopeBuilder]
  D --> E[Gateway]
  E --> F[InstanceMerger]
  F --> G[Instances page]
Loading

Technical review

Best possible solution:

Land the focused identity and presence corrections through the existing factory, envelope builder, and merger.

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

Current-main source retains cli/cli identity and timestamp-only presence classification, and the supplied real-Gateway baseline demonstrates both failures.

Is this the best way to solve the issue?

The patch is the smallest complete correction using existing owners: select one identity for signing and serialization, prioritize live strong matches, and classify disconnected unmatched presence offline.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 65c7ddba163e.

Provenance checked

  • Operator identity changes intended behavior with a stated reason (1d83639: The paired-device and Quick Chat work established signed operator connections and reconnect continuity; this PR explains why the long-lived tray now requires interactive classification.)
  • Envelope construction keeps the original intent (323f46d: Protocol extraction centralized wire construction while retaining credential, scope, fallback, and lifecycle decisions in callers.)
  • Presence merging changes intended behavior with a stated reason (27dd4dd: The Instances implementation uses conservative strong-before-weak matching; prioritizing live strong matches preserves that boundary and explicitly corrects stale disconnect handling.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ranjesh Jaganathan: Raw commit 8afcaf9 adds src/OpenClaw.Tray.WinUI/Services/Connection/GatewayClientFactory.cs:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8afcaf9847f0; files: src/OpenClaw.Tray.WinUI/Services/Connection/GatewayClientFactory.cs)
  • Sytone: Raw commit 1d83639 adds src/OpenClaw.Shared/OpenClawGatewayClient.cs:17 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 1d836390e9ee; files: src/OpenClaw.Shared/OpenClawGatewayClient.cs)
  • Scott Hanselman: Raw commit e2e1cf0 adds src/OpenClaw.Shared/InstanceMerger.cs:46 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e2e1cf089c1d; files: src/OpenClaw.Shared/InstanceMerger.cs)

Review metrics

Metric Value Why it matters
Change distribution Production +42/-9; tests +163/-2; documentation +2/-0 The growth covers explicit identity selection and distinct protocol, composition, and presence regressions without adding another production owner.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Corrects Companion profile attribution and stale presence with a limited connection and presentation scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-28T16:42:00.462Z sha 7125bca :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-28T17:16:49.792Z sha 7125bca :: needs maintainer review before merge. :: none

Reviewed October 28, 2026, 1:22 PM ET / 17:22 UTC (Revision 3).

@bkudiess

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient Contributor real behavior proof is sufficient. 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. and removed 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. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 28, 2026
@shanselman

shanselman commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Hi, I'm a Copilot triage agent, not Scott. I added a small maintainer fix so a mode=node presence row claims its paired node before an earlier mode=ui operator row with the same device ID. The regression reproduces the previous misassignment and now keeps Rename/Forget on the node; the architecture ledger is updated. On c447564ee046db7862277ada64aa6c92cd4097af, .\build.ps1 passed, focused InstanceMergerTests passed (54/54), Tray passed (4,686/4,686), Connection passed (1,690/1,690), docs validation passed, and CI Gate passed. The full Shared run had one Windows symlink-privilege failure (4,692 passed, 26 skipped); the same failure reproduced on clean main. Source review of OpenClaw 2026.9.35 confirms gateway-client/ui is supported and UI presence is tracked; live compatibility was not exercised.

@shanselman
shanselman merged commit 7f6706f into openclaw:main Oct 28, 2026
25 checks passed
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 28, 2026
larroy pushed a commit to larroy/openclaw-windows-node that referenced this pull request Oct 30, 2026
…1909)

* feat(connection): tray operator connects with the interactive Companion identity

The tray opts in to gateway-client/ui through GatewayClientFactory so the Gateway
treats its long-lived connection as interactive. CLI, setup, and validator clients
keep cli/cli. The signed device payload and serialized client use one identity.
Disconnect presence beacons no longer count as active or claim a live node.

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

* fix(instances): prefer node presence for shared device ids

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

---------

Co-authored-by: Copilot App <[email protected]>
KratosFu pushed a commit to KratosFu/openclaw-windows-node that referenced this pull request Nov 13, 2026
Ported from upstream 7f6706f (openclaw#1909). OperatorClientIdentity picks the
id and mode a connection signs and sends: Cli (cli/cli, the default, as
before) or Interactive (gateway-client/ui). The gateway takes a cli
connection for a one-off command and gives it no owner profile, so the
owner's account methods (users.authConnect.*, the ChatGPT sign-in) were
refused. GatewayClientFactory and OpenClawGatewayClient carry the option.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants