Skip to content

Commit 7c54c86

Browse files
shanselmanCopilot
andcommitted
Merge upstream main into bkudiess-connection-analysis
Co-authored-by: Copilot App <[email protected]> Copilot-Session: f5f0e4a6-88fa-4782-9a60-5648648fda3e
2 parents 22fd6e8 + b46e91e commit 7c54c86

133 files changed

Lines changed: 12548 additions & 8980 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.

‎Directory.Build.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<MicrosoftWindowsAppSDKVersion>2.3.1</MicrosoftWindowsAppSDKVersion>
5-
<MicrosoftWindowsSdkBuildToolsVersion>10.0.28000.2270</MicrosoftWindowsSdkBuildToolsVersion>
5+
<MicrosoftWindowsSdkBuildToolsVersion>10.0.28000.2526</MicrosoftWindowsSdkBuildToolsVersion>
66
</PropertyGroup>
77

88
</Project>

‎README.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,22 @@ Packaged installs declare camera, microphone, and location capabilities. Windows
315315
# Speak text aloud on the Windows node (requires TTS enabled in Settings and tts.speak allowed on the gateway)
316316
openclaw nodes invoke --node <id> --command tts.speak --params '{"text":"Hello from OpenClaw","provider":"windows"}'
317317

318-
# Execute a command on the Windows node
319-
openclaw nodes invoke --node <id> --command system.run --params '{"command":"Get-Process | Select -First 5","shell":"powershell","timeoutMs":10000}'
318+
# Execute a command on the Windows node (raw node.invoke requires canonical argv)
319+
openclaw gateway call node.invoke --params '{"nodeId":"<id>","command":"system.run","params":{"command":["cmd.exe","/d","/s","/c","echo hello"],"rawCommand":"echo hello","timeoutMs":10000}}' --json
320320

321321
# View exec approval policy
322322
openclaw nodes invoke --node <id> --command system.execApprovals.get
323323

324-
# Update exec approval policy (add custom rules)
325-
openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"rules":[{"pattern":"echo *","action":"allow"},{"pattern":"*","action":"deny"}],"defaultAction":"deny"}'
324+
# Update exec approvals using baseHash from the preceding get response
325+
openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"baseHash":"<hash-from-get>","file":{"version":1,"defaults":{"security":"allowlist","ask":"on-miss","askFallback":"deny","autoAllowSkills":false},"agents":{"main":{"security":"allowlist","ask":"on-miss","askFallback":"deny","autoAllowSkills":false,"allowlist":[]}}}}'
326326
```
327327
> 📷 **Camera permission**: Desktop builds rely on Windows Privacy settings. Packaged MSIX builds will show the system consent prompt.
328328

329-
> 🔒 **Exec Policy**: `system.run` is gated by an approval policy on the Windows node at `%LOCALAPPDATA%\OpenClawTray\exec-policy.json` (schema: `{ "defaultAction": "...", "rules": [...] }`). This is separate from gateway-side `~/.openclaw/exec-approvals.json`.
329+
> 🔒 **Exec approvals**: `system.run` is gated by the V2 approval coordinator and `%APPDATA%\OpenClawTray\exec-approvals.json`. The file uses the same `defaults`/`agents`/`allowlist` model as the macOS node host. `system.execApprovals.set` requires the current `baseHash` and rejects stale or unsafe remote updates.
330330
>
331-
> Rules are matched against the full command line. Known wrapper payloads such as `cmd /c ...`, `powershell -Command ...`, `pwsh -EncodedCommand ...`, and `bash -c ...` are also evaluated before execution. Dangerous environment overrides like `PATH`, `PATHEXT`, `NODE_OPTIONS`, `GIT_SSH_COMMAND`, `LD_*`, and `DYLD_*` are rejected.
331+
> Allowlist rules match resolved executable paths, using path-aware wildcards such as `**/git.exe`. Script interpreters and command hosts cannot receive reusable grants. Non-empty custom environments are rejected until they can be identity-bound and displayed safely.
332+
>
333+
> **V2 caller migration**: raw MCP, direct `node.invoke`, plugin, and `winnode` callers must replace string-form `{"command":"echo hello","shell":"cmd"}` with canonical `{"command":["cmd.exe","/d","/s","/c","echo hello"],"rawCommand":"echo hello"}`. The normal gateway `exec host=node` path already performs this wrapping. Remove custom `env`; non-empty environments are rejected.
332334

333335
#### Command Center diagnostics
334336

@@ -341,7 +343,7 @@ Open the status detail/Command Center from the tray menu or with `openclaw://com
341343
- recent activity and node invoke results through the Activity Stream, storing command names/status/duration only (not payloads, screenshots, recordings, or secrets)
342344
>
343345
> ```bash
344-
> openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"rules":[{"pattern":"powershell.exe","action":"allow"},{"pattern":"pwsh.exe","action":"allow"},{"pattern":"echo *","action":"allow"},{"pattern":"*","action":"deny"}],"defaultAction":"deny"}'
346+
> openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"baseHash":"<hash-from-get>","file":{"version":1,"defaults":{"security":"allowlist","ask":"off","askFallback":"deny","autoAllowSkills":false},"agents":{"main":{"security":"allowlist","ask":"off","askFallback":"deny","autoAllowSkills":false,"allowlist":[]}}}}'
345347
> ```
346348

347349
> 🔐 **Web Chat secure context**: Remote web chat requires `https://` (or localhost). If using a self-signed cert, trust it in Windows (Trusted Root Certification Authorities) or use an SSH tunnel to localhost.

‎docs/CONNECTION_ARCHITECTURE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ The invariant is that a paired device token always wins. Do not downgrade a pair
183183

184184
**`CredentialResolver`** implements the precedence for WebSocket connections (operator and node roles). It also returns a detailed `GatewayCredentialResolution` so the active snapshot and diagnostics can distinguish `Resolved`, `Missing`, `Unreadable`, `Corrupt`, `FallbackUsed`, and `BootstrapRequired`. Shared-token-only gateways are a clean resolved state when no paired device token exists. If a stored per-gateway device token is unreadable or corrupt and the resolver falls back to a shared/bootstrap token, `GatewayConnectionSnapshot` preserves that fallback status instead of reporting only the token source.
185185

186-
Unreadable/corrupt identity fallback is an explicit same-gateway recovery path, not a silent cross-gateway downgrade. A readable stored device token still always wins. When the per-gateway identity file cannot be read or parsed, fallback may use only credentials already stored on the same active `GatewayRecord`; the snapshot and diagnostics report `FallbackUsed` with `PrimaryStatus=Unreadable` or `Corrupt` so UI/diagnostics can prompt repair or re-pair. Credential reads never fall back to another gateway's identity directory.
186+
Unreadable/corrupt identity fallback is a credential-resolution diagnostic, not permission to replace an existing keypair. A readable stored device token still always wins. When the per-gateway identity file cannot be read or parsed, resolution may identify a same-gateway shared/bootstrap credential, but gateway client construction fails closed until the persisted identity is readable or the user explicitly resets pairing. OpenClaw never regenerates, overwrites, or otherwise changes the identity path on a load failure. The snapshot and diagnostics report the persisted-identity error so UI and diagnostics can prompt repair or explicit re-pair. Credential reads never fall back to another gateway's identity directory.
187187

188188
Node credential precedence follows the same invariant with a distinct stored token:
189189

‎docs/MCP_MODE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ MCP startup is reported from the actual listener state. `NodeService.McpStartupE
145145

146146
### Testing
147147

148-
The tray's most interesting code lives in capabilities — `system.run` (LocalCommandRunner + ExecApprovalPolicy), `screen.snapshot` (Windows.Graphics.Capture + GraphicsCapturePicker), `canvas.*` (WebView2 with trusted origin enforcement), `camera.snap`/`camera.clip` (MediaCapture + consent prompt), `location.get` (Windows.Devices.Geolocation). All of that has nontrivial Windows-only behavior and almost none of it is currently exercised end-to-end without first standing up a gateway and authenticating.
148+
The tray's most interesting code lives in capabilities: `system.run` (LocalCommandRunner + the V2 exec-approval coordinator), `screen.snapshot` (Windows.Graphics.Capture + GraphicsCapturePicker), `canvas.*` (WebView2 with trusted origin enforcement), `camera.snap`/`camera.clip` (MediaCapture + consent prompt), and `location.get` (Windows.Devices.Geolocation). All of that has nontrivial Windows-only behavior and almost none of it is currently exercised end-to-end without first standing up a gateway and authenticating.
149149

150150
Local MCP changes that. Concrete benefits:
151151

@@ -260,7 +260,7 @@ The server is built on several defensive layers, not just one. Loopback alone is
260260
Together these three checks force a malicious cross-origin browser fetch into a CORS preflight that we deliberately do not honor (no `Access-Control-Allow-*` is ever emitted), so the actual call is blocked before reaching capability code.
261261
4. **Bearer token.** Every request must include the persistent local MCP bearer token (`Authorization: Bearer <token>`) once the server has created `%APPDATA%\OpenClawTray\mcp-token.txt`. This blocks drive-by local clients that know the port but cannot read the per-user token file.
262262
5. **Concurrency cap.** A semaphore limits in-flight handlers to 8. A misbehaving local client cannot pin every threadpool thread on long-running screen/camera calls.
263-
6. **Capability-level controls remain in force.** `SystemCapability.SetApprovalPolicy(...)` (the exec approval policy) still gates `system.run`. Camera and screen capture still go through Windows consent flows. MCP doesn't bypass any of those.
263+
6. **Capability-level controls remain in force.** The V2 exec-approval coordinator still gates `system.run`. Camera and screen capture still go through Windows consent flows. MCP doesn't bypass any of those.
264264

265265
**Authentication is local bearer-token based.** The token is persistent, generated by the tray, stored in the current user's OpenClawTray data directory, and verified before MCP method dispatch. It is defense-in-depth rather than a hard sandbox boundary: a malicious process already running as the same user may still be able to read user-profile files or invoke native APIs directly. If we need stronger isolation for shared machines or low-trust local processes, the next step is scoped or per-call tokens issued by the tray, not URL ACLs or HTTPS — both add deployment pain without solving the same-user trust problem.
266266

‎docs/TELEMETRY.md‎

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,76 @@ model/provider names, attachment metadata, filenames, tool names, token usage,
266266
URLs, error messages, or local chat log text. No chat log category is added to
267267
the OpenTelemetry log allowlist.
268268

269+
## Local MCP server lifecycle
270+
271+
The local MCP HTTP server exports transport lifecycle diagnostics for both
272+
MCP-only mode and gateway-enabled local MCP:
273+
274+
- lifecycle traces: `openclaw.mcp.server.start` and
275+
`openclaw.mcp.server.stop`
276+
- request trace: `openclaw.mcp.server.request`
277+
- lifecycle counter: `openclaw.mcp.server.lifecycle.operations`
278+
- request counter: `openclaw.mcp.server.requests`
279+
- listener-error counter: `openclaw.mcp.server.listener.errors`
280+
- request-duration histogram: `openclaw.mcp.server.request.duration`
281+
282+
Lifecycle operations are emitted once per real start or stop attempt. Concurrent
283+
or repeated successful starts do not create duplicate operations. Repeated stop
284+
and disposal calls share the first stop operation. The stop span covers listener
285+
stop and in-flight handler drain. Listener close happens later during resource
286+
disposal, so a close failure increments the listener-error counter but does not
287+
retroactively change the completed stop result.
288+
289+
Request duration is post-accept handling time. It starts after
290+
`HttpListener.GetContextAsync` returns, includes handler-limiter admission, body
291+
read, bridge dispatch, and response delivery, and ends at successful delivery or
292+
rejection. It does not include time spent in the HTTP.sys backlog before a
293+
context is accepted.
294+
295+
The MCP request span is an independent transport-level root. A `tools/call`
296+
request also creates the existing independent `openclaw.node.tool.invoke` root,
297+
which measures node dispatch through response delivery. When both spans are
298+
sampled, the node-tool root contains an OpenTelemetry span link to the MCP
299+
request. The link provides structural correlation without changing either
300+
root's parentage or making tool sampling inherit the request's sampling decision,
301+
and without adding a request identifier attribute. A custom link-aware sampler
302+
may still consider links when making its own decision. Gateway tool invocations
303+
and MCP invocations whose request span was not recorded have no link. The overlap
304+
is intentional: the MCP request signal
305+
diagnoses local HTTP transport behavior, while node-tool telemetry diagnoses
306+
command execution. A successfully delivered JSON-RPC error envelope is a
307+
successful MCP transport request; response text is never parsed to classify
308+
telemetry.
309+
310+
Reviewed MCP attributes are:
311+
312+
- `openclaw.mcp.server.operation`: `start` or `stop`
313+
- `openclaw.mcp.server.request.kind`: `probe`, `json_rpc`, or `other`
314+
- `openclaw.outcome`: `success`, `failure`, or `canceled`
315+
- `openclaw.error.category`: `none`, `listener_start`, `listener_accept`,
316+
`listener_stop`, `listener_close`, `authentication_failed`, `busy`, `timeout`,
317+
`shutdown`, `drain_timeout`, `invalid_request`, `transport_failure`, or
318+
`internal_failure`
319+
- `error.type`: exception type on spans only
320+
321+
Metrics always include the finite error category, including `none` on success,
322+
and never include exception types. Authentication rejection, handler saturation,
323+
invalid HTTP requests, request deadlines, shutdown cancellation, response
324+
delivery failures, and unexpected internal failures are classified through typed
325+
control flow. Deadline and shutdown cancellation use first-wins attribution, so
326+
a later shutdown cannot turn a timeout into cancellation and a later deadline
327+
cannot turn shutdown into timeout. Each source records its cause before
328+
canceling the request token, so request handling cannot observe cancellation
329+
before attribution. If multiple failures occur during stop, the first failure
330+
owns the lifecycle result; later listener failures remain visible through the
331+
listener-error counter.
332+
333+
MCP server telemetry never exports listener ports or endpoints, local or remote
334+
addresses, HTTP scheme or version, headers, user agents, content lengths, bearer
335+
tokens, request or response bodies, JSON-RPC methods or IDs, tool names, command
336+
arguments, or error and exception messages. Existing detailed MCP logs remain
337+
local. No MCP category is added to the OpenTelemetry log allowlist.
338+
269339
## Windows node tool calls
270340

271341
Gateway `node.invoke` and local MCP `tools/call` share one node-side telemetry
@@ -288,14 +358,23 @@ do not depend on ambient activity flowing across those boundaries. The
288358
invocation tracker uses one monotonic clock for the root and duration metric and
289359
completes exactly once.
290360

361+
For local MCP `tools/call`, a sampled root links to the sampled
362+
`openclaw.mcp.server.request` span that caused it. The link carries only the
363+
standard OpenTelemetry trace and span context. It does not add request IDs,
364+
JSON-RPC fields, tool arguments, or metric tags. The tool invocation remains a
365+
separate root so gateway and MCP command traces retain the same topology and
366+
sampling contract.
367+
291368
Reviewed attributes are:
292369

293370
- `openclaw.node.tool.name`: a registered command or `unknown`
294371
- `openclaw.node.tool.transport`: `gateway` or `mcp`
295372
- `openclaw.outcome`: `success`, `failure`, or `canceled`
296373
- `openclaw.error.category`: a finite typed category
297-
- `openclaw.node.tool.system_run.approval.pipeline`: `legacy` for the existing
298-
approval policy or `v2` for the opt-in direct-argv approval pipeline; present
374+
- `openclaw.node.tool.system_run.approval.pipeline`: `v2` for the authoritative
375+
canonical-argv approval pipeline; current `system.run` always emits this value.
376+
`legacy` remains a finite historical value for backward-compatible telemetry
377+
readers, but the runtime no longer selects the legacy approval path. Present
299378
only for `system.run` traces and failure/cancellation logs
300379
- `openclaw.node.tool.sandbox.requested`: whether sandboxing was configured
301380
- `openclaw.node.tool.sandbox.applied`: whether the command was known to run

‎docs/WINDOWS_NODE_ARCHITECTURE.md‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ Niche scenario. If the "server" must be Windows for some reason, this works but
254254
| `camera.clip` | ✅ | ✅ | ✅ | ❌ | **✅** | MediaCapture + MediaEncoding |
255255
| `camera.list` | ✅ | ✅ | ✅ | ❌ | **✅** | DeviceInformation.FindAllAsync |
256256
| `screen.record` | ✅ CGWindowListCreateImage | ✅ ReplayKit | ✅ MediaProjection | ❌ | **✅** | Windows.Graphics.Capture |
257-
| `system.run` | ✅ | ❌ | ❌ | ✅ | **✅** | Process.Start (cmd/pwsh) + ExecApprovalPolicy |
258-
| `system.execApprovals` | ❌ | ❌ | ❌ | ❌ | **✅** | JSON policy file (exec-policy.json) |
257+
| `system.run` | ✅ | ❌ | ❌ | ✅ | **✅** | Process.Start + V2 exec-approval coordinator |
258+
| `system.execApprovals` | ❌ | ❌ | ❌ | ❌ | **✅** | V2 store (`exec-approvals.json`) with base-hash CAS |
259259
| `system.notify` | ✅ NSUserNotification | ✅ UNUserNotification | ✅ NotificationManager | ❌ | **✅** | ToastNotificationManager |
260260
| `location.get` | ✅ CLLocationManager | ✅ CLLocationManager | ✅ FusedLocation | ❌ | **✅** | Windows.Devices.Geolocation |
261261
| `device.info/status` | ✅ shared schema | ✅ shared schema | ✅ shared schema | ❌ | **✅** | .NET runtime, storage, network |
@@ -453,7 +453,51 @@ string stderr = await process.StandardError.ReadToEndAsync();
453453
await process.WaitForExitAsync();
454454
```
455455

456-
**Critical:** Exec approvals must be enforced locally, same as macOS/headless nodes. Store in `%APPDATA%\OpenClaw\exec-approvals.json`.
456+
**Critical:** Exec approvals must be enforced locally, same as macOS/headless nodes. The default store is `%APPDATA%\OpenClawTray\exec-approvals.json`; `OPENCLAW_STATE_DIR` overrides that location.
457+
458+
#### Decision: retire Windows V1 exec policy without migration
459+
460+
Windows V1 `exec-policy.json` command-text globs are not evaluated or converted after the
461+
V2 cutover. When no valid V2 policy exists, the node uses an empty allowlist with
462+
prompt-on-miss and deny fallback.
463+
464+
**Consequences:**
465+
466+
- Existing V1 files remain untouched during normal runtime but no longer authorize or deny execution.
467+
- Prior V1 allows require attended V2 reapproval; unattended calls deny.
468+
- Prior V1 denies are not imported and may be explicitly superseded through an attended V2 prompt.
469+
- Malformed or untrusted V2 state remains hard deny and is never replaced from V1 state.
470+
471+
This compatibility break is accepted because V1 matched shell command text while V2 binds
472+
resolved executable identity and canonical argv. Mechanical conversion could widen a narrow
473+
command rule into a reusable `cmd.exe` or PowerShell grant, while retaining both evaluators
474+
would preserve parallel authorization paths and bypass drift.
475+
476+
**Rejected alternatives:** V1 runtime fallback, mechanical rule conversion, and file-triggered
477+
migration UI. Revisit this decision only if measured support impact justifies a separate
478+
compatibility feature.
479+
480+
#### Decision: version the low-level `system.run` boundary as canonical argv
481+
482+
The V2 low-level node contract accepts `command` only as `string[]` canonical argv.
483+
String-form `command`, implicit `shell`, separate `args`, and non-empty custom `env`
484+
are intentional breaking changes. The normal gateway `exec host=node` flow already
485+
constructs canonical Windows argv, so this affects raw MCP, direct `node.invoke`,
486+
plugins, and other callers that bypass gateway exec orchestration.
487+
488+
Migration example:
489+
490+
```json
491+
// Before
492+
{"command":"echo hello","shell":"cmd"}
493+
494+
// V2
495+
{"command":["cmd.exe","/d","/s","/c","echo hello"],"rawCommand":"echo hello"}
496+
```
497+
498+
The node returns `command-array-required` for a string command and
499+
`custom-env-not-supported` for a non-empty environment. This explicit boundary
500+
keeps approval identity and process execution on one argv representation.
457501

458502
### Location → Windows.Devices.Geolocation
459503

0 commit comments

Comments
 (0)