Skip to content

Commit 86fa840

Browse files
committed
Merge origin/main into telemetry instrumentation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 8274c0b2-0aa9-4726-bc8c-b991f5b8e125
2 parents 37b84d8 + bd6c4bf commit 86fa840

113 files changed

Lines changed: 9606 additions & 452 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/ARCHITECTURE.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ These are the canonical homes. Do not reintroduce private copies elsewhere.
5454
| Settings test data | `OpenClaw.TestSupport.SettingsDataBuilder` | authoritative |
5555
| JSON `JsonElement` coercion (non-nullable fallback family) | `JsonReadHelpers` | authoritative |
5656
| WSL/POSIX shell quoting | `WslShellQuoting` | authoritative |
57+
| UI-thread marshaling for presentation code | `IUiDispatcher` | authoritative |
58+
| Page view-model activation/deactivation + disposal lifetime | `NavigationScopeManager` | authoritative |
59+
| Presentation-layer DI composition root | `AppServiceRegistration` (root `ServiceProvider`, owned by `App`) | authoritative |
5760
| Capability UI metadata | `NodeCapabilityUiCatalog` (planned) | planned |
5861
| Capability registration/gating | `NodeCapabilityRegistrationPolicy` (planned) | planned |
5962
| Local MCP exposure policy | `McpCapabilityPolicy` (planned) | planned |
@@ -116,6 +119,9 @@ leading and trailing pipe. Columns, in order:
116119
| chat-send-queue | planned | src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs | send queue/admission/abort state | ChatSendQueue | - | queued send/abort/generation semantics preserved | none | review-only | extracted in Phase 4 |
117120
| gateway-pending-requests | planned | src/OpenClaw.Shared/OpenClawGatewayClient.cs | request-id -> method/completion tracking | PendingRequestRegistry | - | request ids never leak after disconnect; thread-safe | none | review-only | extracted in Phase 4 |
118121
| connect-envelope | planned | src/OpenClaw.Shared/OpenClawGatewayClient.cs + WindowsNodeClient.cs | connect message + auth precedence + signature version | ConnectEnvelopeBuilder | - | credential precedence never downgrades a device token; v3->v2 fallback preserved | none | review-only | extracted in Phase 4 |
122+
| ui-dispatcher | authoritative | src/OpenClaw.Tray.WinUI/App.xaml.cs | UI-thread marshaling abstraction for presentation code | IUiDispatcher | App and existing WinUI code may call DispatcherQueue directly until the view-model migration | presentation view models depend on IUiDispatcher not a concrete DispatcherQueue | UiDispatcherContractTests.PageViewModel_ReceivesRegisteredDispatcher | behavioral | - |
123+
| navigation-scope | authoritative | src/OpenClaw.Tray.WinUI/Windows/HubWindow.xaml.cs | page view-model activation/deactivation and disposal lifetime | NavigationScopeManager | HubWindow keeps frame navigation back-stack and rail selection | transient page view models are activated on navigation and deactivated then disposed on navigate-away | NavigationScopeManagerTests.NavigatingAway_DeactivatesAndDisposesPreviousViewModel | behavioral | - |
124+
| composition-root | authoritative | src/OpenClaw.Tray.WinUI/App.xaml.cs | presentation-layer service construction and wiring | AppServiceRegistration | App remains the composition root and owns non-DI service lifetimes | one validated root ServiceProvider; App-owned singletons registered as instances are never disposed by the container | AppServiceRegistrationTests.Dispose_DoesNotDisposeAppOwnedInstanceSingletons | behavioral | - |
119125
<!-- LEDGER:END -->
120126

121127
## Deferred test builders

‎docs/CONNECTION_ARCHITECTURE.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ OpenClaw.Tray.WinUI (net10.0-windows) — UI app, tray icon, pages, windows
1616

1717
**OpenClaw.Shared** owns the low-level gateway clients (`OpenClawGatewayClient`, `WindowsNodeClient`, `WebSocketClientBase`), device identity/signing (`DeviceIdentity`), protocol models, and the `IOperatorGatewayClient` interface.
1818

19+
`WindowsNodeClient` also owns gateway invocation lifetime at the transport
20+
boundary. Active invokes are registered by invoke ID in a focused cancellation
21+
registry, linked to the node connection lifetime, and cancelled individually by
22+
the gateway `node.invoke.cancel` event. Active invocations atomically transition
23+
to cancelled or completed when capability execution returns; whichever
24+
transition wins determines the protocol outcome. Capability implementations
25+
remain responsible for cooperative cancellation of their own underlying work.
26+
1927
**OpenClaw.Connection** owns all connection management: `GatewayConnectionManager`, `GatewayRegistry`, `CredentialResolver`, `ConnectionStateMachine`, `NodeConnector`, `SshTunnelService/Manager`, `SetupCodeDecoder`, and all connection interfaces/DTOs/enums. This project has zero WinUI dependencies and is independently testable.
2028

2129
**OpenClaw.Tray.WinUI** consumes the connection layer through interfaces. It never creates gateway clients directly — `GatewayConnectionManager` owns that entirely.

‎docs/MCP_MODE.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,37 @@ The capability list lives on `NodeService`, *not* on `WindowsNodeClient`. That s
6666
- `tools/list` — flattens `_capabilities` into MCP tools. Tool name = command name (`"screen.snapshot"`); known commands get curated descriptions from `McpToolBridge.CommandDescriptions`; unknown commands fall back to `"{category} capability: {command}"`. `inputSchema` is permissive.
6767
- `tools/call` — finds the capability via `INodeCapability.CanHandle(name)`, builds a `NodeInvokeRequest` (the same struct the gateway path uses), calls `ExecuteAsync`, wraps the result as MCP `content[].text`. Tool failures come back as `result.isError = true`, not JSON-RPC errors (per MCP spec — JSON-RPC errors are reserved for protocol issues).
6868
- `ping`, `notifications/initialized` — protocol housekeeping.
69+
- `notifications/cancelled` — cancels the active request whose JSON-RPC ID is
70+
supplied as `params.requestId`. A cancelled `tools/call` completes with an MCP
71+
tool error containing `cancelled`. If concurrent HTTP scheduling processes
72+
cancellation just before an already-sent call registers, the notification
73+
records a pending cancellation for five seconds. The first matching
74+
registration atomically consumes that tombstone and returns `cancelled` before
75+
capability execution begins, so correctness does not depend on scheduler
76+
timing. Repeated notifications for the same pending ID do not extend its
77+
original five-second lifetime. Pending cancellations and recent-completion
78+
guards are each capped at 1,024 entries;
79+
expired entries are pruned first and the oldest remaining entry is evicted at
80+
capacity. Because JSON-RPC IDs are client-scoped but this stateless HTTP
81+
transport has no client identity, duplicate active IDs are allowed and
82+
cancellation is ignored when more than one active call matches; this prevents
83+
one local client from cancelling another client when the collision is already
84+
observable. Request matching uses the decoded JSON string value or normalized
85+
arbitrary-precision JSON number value, while preserving the distinction
86+
between string and numeric IDs. A tombstone cannot predict a later
87+
cross-client ID collision, so it cancels the first matching registration;
88+
complete isolation would require client identity in the transport. A recent
89+
completion guard also prevents a late notification from poisoning immediate
90+
ID reuse.
6991

7092
The bridge takes a `Func<IReadOnlyList<INodeCapability>>` rather than a snapshot. Every `tools/list` re-reads the live list. This is what guarantees zero-cost capability addition — register a new capability after server start and it appears on the next `tools/list`.
7193

94+
Cancellation is cooperative and uses the same `CancellationToken` capability
95+
contract as the gateway transport. Screen and camera operations propagate the
96+
token through recording consent/countdown, camera admission, capture waits, and
97+
recording shutdown. The HTTP request deadline remains a separate safety bound;
98+
no command-specific transport deadlines are applied.
99+
72100
### HTTP transport
73101

74102
`OpenClaw.Shared/Mcp/McpHttpServer.cs` is `System.Net.HttpListener` bound to `http://127.0.0.1:8765/`. Loopback-only by construction; not reachable from any other machine even with firewall holes. A defensive `IPAddress.IsLoopback` check on each request acts as belt-and-suspenders.

‎docs/SETUP_ENGINE_REDESIGN.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ src/OpenClaw.SetupEngine.UI/
8080
## Config File (`default-config.json`)
8181

8282
**Config is required.** Neither the headless exe nor the UI will run without one. The bundled `default-config.json` is auto-loaded from `AppContext.BaseDirectory` if no `--config` is specified.
83+
If the setup UI cannot find, read, or deserialize the selected configuration,
84+
it opens on the setup failure page with the load error and does not start setup.
8385

8486
```json
8587
{
@@ -319,6 +321,26 @@ OpenClaw.SetupEngine.Program.Main(["--log-path", "./trace.log"])
319321

320322
Common flags include `--config`, `--headless`, `--dry-run`, `--rollback-on-failure`, `--no-rollback-on-failure`, `--log-path`, `--gateway-port`, and uninstall safety flags such as `--uninstall` plus `--confirm-destructive`.
321323

324+
SetupEngine option names are case-insensitive. Value options accept either separated
325+
syntax (`--config custom.json`) or equals syntax (`--config=custom.json`). Unknown
326+
options, bare `--`, and positional arguments are rejected with exit code 2.
327+
Boolean flags do not accept values, and duplicate value options are rejected;
328+
duplicate bare flags remain idempotent.
329+
330+
Duplicate value rejection is an intentional compatibility break from the legacy
331+
first-value-wins behavior. Scripts that repeat a value option must remove the
332+
duplicate before upgrading.
333+
334+
The same parser enforces the tray-hosted setup window's narrower command-line
335+
contract: `--config` and `--no-rollback-on-failure`. The tray projects recognized
336+
restart and deep-link host arguments out first. A restart PID must be a positive
337+
integer other than the current process, and the post-setup launch target must be
338+
`chat`; malformed host values remain for strict rejection. All remaining unknown options,
339+
positionals, missing values, and duplicates render the setup failure page before
340+
the setup lock is acquired. The tray executable's uninstall arguments are parsed
341+
by `CliUninstallHandler` and currently use separated syntax for values such as
342+
`--json-output <path>`.
343+
322344
Exit codes: 0 = success, 1 = pipeline failure, 2 = bad arguments or setup lock/safety failure, 3 = cancelled
323345

324346
### UI (hosted by tray)

‎docs/WINDOWS_NODE_TESTING.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ These features need the gateway to send `node.invoke` commands:
9191
| `stt.listen` | Voice-activity microphone transcription | Returns when the user stops speaking or timeout expires |
9292
| `stt.status` | Speech-to-text readiness | Returns Whisper.net model download/readiness state |
9393

94+
### Cancelling an invocation
95+
96+
The gateway may send the `node.invoke.cancel` event with
97+
`payload.invokeId` matching an active `node.invoke.request`. The Windows node
98+
cancels only that invocation and completes its original result with
99+
`ok: false, error: "cancelled"`; unknown or already-completed IDs are ignored.
100+
The legacy `payload.requestId` spelling is also accepted for compatibility.
101+
Operation completion is the linearization point: once capability execution
102+
returns and atomically marks the invocation complete, later cancellation is too
103+
late and the completed result is preserved.
104+
105+
For local MCP, send a JSON-RPC `notifications/cancelled` notification with
106+
`params.requestId` matching the active `tools/call` JSON-RPC ID. Cancellation
107+
must stop queued camera admission, recording delays/frame waits, and active
108+
recording cleanup rather than only abandoning the HTTP waiter.
109+
94110
## Capabilities Advertised
95111

96112
When the node connects, it advertises these capabilities:

‎docs/WSL_GATEWAY_ADMIN.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ wsl.exe -d OpenClawGateway --user openclaw -- bash -lc "ls -ld /home/openclaw/.o
9494

9595
Do not run `systemctl --user` as `root`; that checks root's user service manager, not the gateway's service.
9696

97+
## Inspect an optional Tailscale Serve endpoint
98+
99+
When the setup review enabled **Tailnet access with Tailscale Serve**, the generated distro runs its own Tailscale daemon. The Windows Companion intentionally uses the generated `wss://<node>.<tailnet>.ts.net` endpoint; it does not silently fall back to localhost.
100+
101+
Windows must also have Tailscale installed and signed in to the same tailnet. These checks do not print credentials:
102+
103+
```powershell
104+
# Windows Companion side: confirm this PC is connected to Tailscale.
105+
& "$env:ProgramFiles\Tailscale\tailscale.exe" status --json
106+
107+
# WSL side: confirm the daemon is connected and has a MagicDNS name.
108+
wsl.exe -d OpenClawGateway --user root -- tailscale status --json
109+
110+
# Confirm Serve routes tailnet HTTPS to the loopback OpenClaw gateway port.
111+
# Tailscale lifecycle and Serve are intentionally owned by root, not openclaw.
112+
wsl.exe -d OpenClawGateway --user root -- /usr/bin/tailscale serve status --json
113+
114+
# Funnel is unsupported. This must show no public route.
115+
wsl.exe -d OpenClawGateway --user root -- /usr/bin/tailscale funnel status --json
116+
117+
# Check the OpenClaw gateway itself; it remains loopback-bound inside WSL.
118+
wsl.exe -d OpenClawGateway --user openclaw -- bash -lc "systemctl --user status openclaw-gateway.service --no-pager || true"
119+
```
120+
121+
The generated WSL distro is Ubuntu 24.04 (noble). Tailscale Serve setup requires that exact generated distro and rejects another `BaseDistro` before replacing an existing gateway. Setup installs Tailscale from its signed stable APT repository rather than executing the mutable `install.sh` bootstrap script as root.
122+
123+
Tailscale Serve preserves Companion token and device authentication by default (`gateway.auth.allowTailscale=false`). Setup runs `tailscale up`, Serve, reset, logout, and daemon management as root; the `openclaw` account is never made a Tailscale operator. Tailscale's LocalAPI permits read-only operations, such as identity lookup, to local unprivileged clients while reserving mutation for root or an explicitly configured operator. In the setup review, **Trust Tailscale identities for gateway authentication** is an explicit opt-in; when enabled, verified Tailscale identity headers and tailnet ACLs become part of the gateway access-control boundary. Token and device credentials remain available for Companion pairing and compatibility. Do not enable Funnel for this generated gateway: this workflow supports private tailnet Serve only.
124+
97125
## Use root instead of sudo
98126

99127
There is no interactive sudo password prompt. Open a root shell only when you intentionally need to inspect or change protected files:

‎src/OpenClaw.Chat/ChatModels.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public enum ChatThreadStatus
44
{
55
Created,
66
Running,
7-
Suspended
7+
Suspended,
8+
Ended
89
}
910

1011
public enum ChatActivity

‎src/OpenClaw.Connection/NodeConnector.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ private bool IsCurrentClient(object? sender, long generation)
221221
// Validation and dispatch stay atomic so a retired client cannot publish after its
222222
// replacement. Subscribers must remain synchronous and must not block on connector
223223
// lifecycle work while this lock is held.
224+
//
225+
// Lock ordering: _connectSemaphore (async, serialises connect/disconnect) may be
226+
// held when _clientLifecycleLock is acquired, but subscribers never acquire
227+
// _connectSemaphore. Among monitor locks, _clientLifecycleLock is the outermost
228+
// in the connector's acquisition graph. Subscribers may acquire their own locks
229+
// (GatewayConnectionManager._telemetryLock, GatewayRegistry._lock,
230+
// ConnectionDiagnostics._lock) but code holding those locks must not
231+
// synchronously enter connector lifecycle operations, preserving a consistent
232+
// acquisition order that prevents deadlock. Subscriber handlers must return
233+
// promptly; current subscribers use fire-and-forget async dispatch for heavy
234+
// work and perform only lightweight synchronous preambles.
224235
private void ForwardIfCurrent<T>(
225236
object? sender,
226237
long generation,

‎src/OpenClaw.SetupEngine.UI/Pages/CapabilitiesPage.xaml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@
109109
<TextBlock Grid.Column="2" Text="~200 MB" Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorTertiaryBrush}" FontFamily="Cascadia Mono, Consolas" VerticalAlignment="Center" />
110110
</Grid>
111111
</Border>
112+
<Border Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="1" CornerRadius="4" Padding="14,12">
113+
<StackPanel Spacing="8">
114+
<Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="14">
115+
<FontIcon Grid.Column="0" Glyph="&#xE701;" FontSize="18" VerticalAlignment="Center" />
116+
<StackPanel Grid.Column="1" Spacing="2">
117+
<TextBlock Text="Tailnet access with Tailscale Serve" Style="{StaticResource BodyStrongTextBlockStyle}" />
118+
<TextBlock TextWrapping="Wrap" Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="Publish this private gateway as HTTPS/WSS to your Tailscale tailnet. Windows Tailscale must already be signed in; setup root owns Serve." />
119+
</StackPanel>
120+
<ToggleSwitch x:Name="TailscaleToggle" Grid.Column="2" OnContent="" OffContent="" Toggled="TailscaleToggle_Toggled" VerticalAlignment="Center" />
121+
</Grid>
122+
<StackPanel x:Name="TailscaleOptions" Visibility="Collapsed" Spacing="6" Margin="32,0,0,0">
123+
<TextBlock x:Name="TailscaleStatusText" Text="Check Windows Tailscale before continuing." Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" TextWrapping="Wrap" />
124+
<RadioButtons x:Name="TailscaleAuthModeSelector" SelectedIndex="0" SelectionChanged="TailscaleAuthMode_SelectionChanged">
125+
<x:String>Sign in in browser</x:String>
126+
<x:String>Use one-off auth key</x:String>
127+
</RadioButtons>
128+
<PasswordBox x:Name="TailscaleAuthKeyBox" Visibility="Collapsed" PlaceholderText="Tailscale auth key (not saved)" />
129+
<ToggleSwitch x:Name="TailscaleTrustAuthToggle" Header="Trust Tailscale identities for gateway authentication" OnContent="Enabled" OffContent="Disabled" Toggled="TailscaleTrustAuthToggle_Toggled" />
130+
<TextBlock TextWrapping="Wrap" Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="Off by default. Enable only when your Tailscale ACLs should be part of the gateway access-control boundary; OpenClaw receives only a restricted identity lookup, not Tailscale operator control." />
131+
</StackPanel>
132+
</StackPanel>
133+
</Border>
112134
<Border Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="1" CornerRadius="4" Padding="14,12">
113135
<Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="14">
114136
<FontIcon Grid.Column="0" Glyph="&#xE896;" FontSize="18" VerticalAlignment="Center" />

0 commit comments

Comments
 (0)