Skip to content

fix(cli): request scopes a session-only device grant covers - #199698

Merged
hannesrudolph merged 10 commits into
openclaw:mainfrom
daniel-lxs:cli-session-scopes
Nov 21, 2026
Merged

hannesrudolph merged 10 commits into
openclaw:mainfrom
daniel-lxs:cli-session-scopes

Conversation

@daniel-lxs

@daniel-lxs daniel-lxs commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Related: #199692

Depends on #199693. This branch is stacked on it, so until #199693 merges the diff also shows its commits.

What Problem This Solves

Fixes: a device paired with only operator.sessions.write, as the multiplayer guide recommends for guests, can't use openclaw gateway call or openclaw tui. The CLI asks for operator.read and the TUI for admin, read, write and approvals, so every connect becomes a scope-upgrade request for the admin.

User Impact

User impact: a session-only guest can list, read and create its sessions from the CLI and use the TUI within its grant. Once the TUI has stored the grant with a device token, its connections and gateway call file no upgrade request. Behind trusted-proxy auth the Gateway issues the TUI no device token and gateway call stores none, so there each connection is refused once with a scope-upgrade request and then works within the grant. #199699 removes that refusal as a Gateway opt-in.

Devices whose grant holds the general scope are unchanged, and a device that needs a real upgrade (for example operator.read to operator.admin) still files one.

In the TUI, a session-only device gets no command list or pending approvals, because those need operator.read and operator.approvals.

Why This Change Was Made

Where the client learns its grant:

  • gateway call projects its least-privilege scopes through the stored device grant with the existing projectOperatorScopesForMethod. It narrows only when the method's session-scoped alternative still authorizes the call.
  • The TUI connects within a stored grant that holds operator.sessions.* and none of its default scopes, unless --token or --password is given.

A device approved before it ever connected: it has no stored grant, so its first request can exceed it. The Gateway's scope-upgrade refusal already reports approvedScopes, and the client uses that:

  • The gateway client gains an opt-in fitScopesToApprovedGrant hook that reconnects once within the reported grant, which the TUI uses.
  • gateway call retries once with the session grant.
  • The TUI stores the device token it receives with the grant, so its later connections, and gateway call reading that stored grant, fit it. gateway call keeps its read-only storage mode on the retry and stores nothing.

Until a grant is stored, each connection still files that request first, because nothing tells the client its grant before it asks. Behind trusted-proxy auth nothing is stored, so that holds for every connection. The opt-in Gateway change in #199699 removes it.

Moves: two moves keep the touched files within the line-cap ratchet without changing behaviour:

  • CLI scope selection, including the existing sessions.create cwd escalation retry, moves to src/gateway/call-scopes.ts.
  • The gateway client's host-dependency defaults move to packages/gateway-client/src/client-host-deps.ts. client.ts re-exports their types, so the package API is unchanged.

Docs: docs/start/multiplayer.md and docs/cli/tui.md describe the guest behaviour and when the first-connect request remains.

Evidence

  • New tests:

    • src/gateway/call.stored-grant-scopes.test.ts 5/5. A session-only grant reads with operator.sessions.read; a read grant and a method without a session scope keep their request; a refused request retries with the reported grant and keeps read-only storage on both attempts (this case fails without the read-only fix); a grant that can't serve the method does not retry.
    • packages/gateway-client/src/client.approved-grant.test.ts 3/3, against a real WebSocket server that refuses with a scope upgrade: reconnects once within the reported grant; pauses without the hook, or when the hook keeps the request.
    • src/tui/gateway-chat.connection.test.ts 16/16, adding session-only, read, operator.pairing and --token grants.
    • Without this change, the session-only, retry, operator.pairing and --token cases fail; the keep-behaviour cases pass on both.
  • Existing tests: call.test.ts 91/91, client.test.ts 95/95, client.handshake.test.ts 22/22, client.device-auth.test.ts 25/25, reconnect-policy.test.ts 19/19, tui.test.ts 51/51.

  • Static checks: typecheck, lint and format are clean.

  • Restack onto fix(cli): connect through gateway.remote.edgeAuth without a Gateway token #199693's pairing hint: this branch now sits on a675d1b23b7, which adds the openclaw gateway call hint for an unpaired edgeAuth device and keeps an explicit --url in it. git range-diff 3411a94ae50..48d8e528f08 a675d1b23b7..74994fa1a99 shows this branch's two commits unchanged, and the runs below were made at 48d8e528f08, before the restack. On 74994fa1a99: call.edge-auth.test.ts 6/6, call.stored-grant-scopes.test.ts 5/5, call.test.ts 91/91, gateway-chat.connection.test.ts 16/16, client.approved-grant.test.ts 3/3, typecheck clean, line-cap ratchet OK. On 71857425b24, the same two commits on fix(cli): connect through gateway.remote.edgeAuth without a Gateway token #199693's first hint commit: client-bootstrap.auth.test.ts 6/6, client.test.ts 95/95, tui.test.ts 51/51.

  • Live run at 48d8e528f08 (built with pnpm build:runtime): a loopback Gateway with gateway.auth.mode: "trusted-proxy", behind a small TLS proxy standing in for Cloudflare Access (it answers 302 unless the request carries Cf-Access-Token, then injects the identity headers). The guest config has only gateway.remote.url and gateway.remote.edgeAuth: no token, no password, no stored device token. --tls-fingerprint is there only because the test proxy uses a self-signed certificate. The output is trimmed, and IDs and ports are from throwaway test state. The admin approves only operator.sessions.write. The Gateway has narrowToDeviceGrant off, as it is by default and as it is without feat(gateway): connect approved trusted-proxy CLI and TUI devices within their grant #199699.

    Guest and admin terminal output, proxy connect frames, Gateway audit count
$ openclaw tui            # configured target: edgeAuth only, no token or password
gateway connect failed: GatewayClientRequestError: device pairing required (requestId: ec48566a-d37f-4f97-ae85-f7991145134a)   (x3, the TUI keeps retrying)
$ openclaw devices list   # admin
pending [('ec48566a-d37f-4f97-ae85-f7991145134a', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]
(admin rejects it, to see the explicit-URL path file its own request)
$ openclaw tui --url wss://127.0.0.1:19752 --tls-fingerprint <test cert>   # explicit URL, no token or password
gateway connect failed: GatewayClientRequestError: device pairing required (requestId: c820625e-58c1-4eeb-a9b9-fd489ad03684)   (x5, the TUI keeps retrying)
pending [('c820625e-58c1-4eeb-a9b9-fd489ad03684', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]
(admin rejects it; the guest asks for only operator.sessions.write, the multiplayer guide's guest grant)
$ openclaw devices approve <that request>   # admin
Approved 53f0504a86c3... (c64fc939-1658-4717-8d5f-da77ce8b27bd)
$ openclaw devices list   # admin
paired [('53f0504a86c3', 'cli', ['operator.sessions.write']), ('e9dc0e3e3843', 'cli', ['operator.pairing', 'operator.sessions.write'])]
$ openclaw tui            # first start after approval
gateway connected
$ openclaw tui            # second start
gateway connected
$ openclaw gateway call sessions.list --json   # call 1
gateway connect failed: GatewayClientRequestError: scope upgrade pending approval (requestId: a1e50f8c-b21f-46c6-b981-c326cd958b52)
{ "count": 0, "totalCount": 0, ... }   (exit 0)
$ openclaw gateway call sessions.list --json   # call 2
gateway connect failed: GatewayClientRequestError: scope upgrade pending approval (requestId: a1e50f8c-b21f-46c6-b981-c326cd958b52)
{ "count": 0, "totalCount": 0, ... }   (exit 0)
$ openclaw devices list   # admin, at the end
pending [('a1e50f8c-b21f-46c6-b981-c326cd958b52', 'cli', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]

# connect frames the proxy forwarded from step 4 on (device id shortened)
20:57:21 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=none
20:57:22 client=openclaw-tui/ui scopes=["operator.sessions.write"] device=<guest> auth=none
20:58:08 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=none
20:58:08 client=openclaw-tui/ui scopes=["operator.sessions.write"] device=<guest> auth=none
20:58:55 client=cli/cli scopes=["operator.read"] device=<guest> auth=none
20:58:55 client=cli/cli scopes=["operator.sessions.write"] device=<guest> auth=none
20:59:00 client=cli/cli scopes=["operator.read"] device=<guest> auth=none
20:59:00 client=cli/cli scopes=["operator.sessions.write"] device=<guest> auth=none

# Gateway log: 'device access upgrade requested' lines for the guest device
upgrade audit lines for the guest device before step 4: 0
upgrade audit lines after step 4: 1
upgrade audit lines after step 5: 2
upgrade audit lines after call 1: 3
upgrade audit lines after call 2: 4
- **Upgrade from 2026.11.3, stored credentials kept:** the same loopback trusted-proxy setup, starting on the published `[email protected]` package for both the Gateway and the guest. The guest device is approved for only `operator.sessions.write` and stores that grant with the device token 2026.11.3 issues it. 2026.11.3 has no shipped command that leaves this grant behind a trusted proxy (its TUI gets no device token there, `gateway call` stores none, and its other commands ask for scopes the grant refuses), so the grant is written by 2026.11.3's own CLI Gateway client from its public `plugin-sdk/gateway-runtime`, asking for exactly that scope. 2026.11.3 will not dial without a credential, so that client sends a placeholder password, which trusted-proxy auth does not check (the two `auth=password` frames). Then the guest CLI moves to `48d8e528f08` with the same state directory and runs the documented update step, `openclaw doctor --fix`; then the Gateway does the same. Without the doctor step, both refuse the 2026.11.3 databases and ask for it (`Cannot load device identity ... run "openclaw doctor --fix"` on the guest, `uses schema version 27 ... requires state migration` on the Gateway); that is `main`'s migration owner, not this change.
Upgrade run: terminal output, proxy connect frames, Gateway audit counts
# PHASE 1: Gateway and guest on openclaw 2026.11.3 (npm package, 847611d)
$ <2026.11.3 CLI Gateway client> sessions.list, scopes [operator.sessions.write]
2026.11.3 client: device pairing required (requestId: 8057efaa-68a8-4628-a0ac-f8dbbf0a62e7)
$ openclaw devices list   # admin
pending [('8057efaa-68a8-4628-a0ac-f8dbbf0a62e7', 'cli', ['operator.sessions.write'])]
$ openclaw devices approve <that request>   # admin
Approved a6f98fe8e981... (8057efaa-68a8-4628-a0ac-f8dbbf0a62e7)
$ <2026.11.3 CLI Gateway client> sessions.list, scopes [operator.sessions.write]
2026.11.3 client connected: sessions.list count=0
# guest state 2026.11.3 wrote: ./openclaw.json, ./state/openclaw.sqlite (device identity and the origin-bound device token)
$ openclaw tui            # 2026.11.3, stored grant, no token or password
OpenClaw 2026.11.3 (847611d)
scope upgrade pending approval (requestId: b021ea69-68be-4851-9504-a5be9e201395)   (x5, the TUI keeps retrying)
$ openclaw gateway call sessions.list --json   # 2026.11.3
gateway connect failed: GatewayClientRequestError: scope upgrade pending approval (requestId: b021ea69-68be-4851-9504-a5be9e201395)   (exit 1)
(admin rejects the upgrade request 2026.11.3 filed; the paired grant stays [operator.sessions.write])

# PHASE 2: guest CLI upgraded to this PR at 48d8e528f08, same guest state; Gateway still 2026.11.3
$ openclaw --version
OpenClaw 2026.11.3 (48d8e52)
$ openclaw doctor --fix --non-interactive   # the documented update step; migrates the guest state database
doctor exit=0
$ openclaw tui
gateway connected
$ openclaw gateway call sessions.list --json   # twice
{ "count": 0, ... }   (exit 0)
{ "count": 0, ... }   (exit 0)
$ openclaw devices list   # admin
pending []

# PHASE 3: Gateway upgraded to this PR at 48d8e528f08 too (after openclaw doctor --fix --non-interactive on the Gateway host)
$ openclaw tui
gateway connected
$ openclaw gateway call sessions.list --json   # twice
{ "count": 0, ... }   (exit 0)
{ "count": 0, ... }   (exit 0)
$ openclaw devices list   # admin
pending []

# connect frames the proxy forwarded (device id shortened; one device throughout)
22:41:59 client=cli/cli scopes=["operator.sessions.write"] device=<guest> auth=password
22:42:04 client=cli/cli scopes=["operator.sessions.write"] device=<guest> auth=password
22:42:07 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=deviceToken
22:42:08 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=deviceToken
22:42:10 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=deviceToken
22:42:15 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=deviceToken
22:42:23 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=deviceToken
22:42:42 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=deviceToken
22:42:47 client=cli/cli scopes=["operator.read"] device=<guest> auth=deviceToken
22:43:18 client=openclaw-tui/ui scopes=["operator.sessions.write"] device=<guest> auth=deviceToken
22:44:03 client=cli/cli scopes=["operator.sessions.read"] device=<guest> auth=deviceToken
22:44:04 client=cli/cli scopes=["operator.sessions.read"] device=<guest> auth=deviceToken
22:44:34 client=openclaw-tui/ui scopes=["operator.sessions.write"] device=<guest> auth=deviceToken
22:45:19 client=cli/cli scopes=["operator.sessions.read"] device=<guest> auth=deviceToken
22:45:19 client=cli/cli scopes=["operator.sessions.read"] device=<guest> auth=deviceToken

# Gateway log: 'device access upgrade requested' lines for the guest device
phase 1 (2026.11.3 client): 7
phase 2 (PR head client, 2026.11.3 Gateway): 0
phase 3 (PR head client and Gateway): 0
- **Independent review:** an independent review of this change found three issues, all fixed and covered above: the TUI narrowed when `--token` was given, it narrowed non-session grants, and a newly approved device had no stored grant.

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

✅ Maintainer security changes approved

A maintainer approved this revision with an explicit security approval comment.

A later push requires a fresh approval comment for an external contributor's PR.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR fits CLI and TUI connections to approved session-only device grants and resolves guest identity before the Gateway greeting.

Example: A device approved only for operator.sessions.write runs openclaw gateway call sessions.list --json.

  • Before: The CLI requests operator.read and fails with scope upgrade pending approval.
  • After: The CLI requests operator.sessions.read from a stored grant, or retries within the reported grant, and returns the session list.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, behaviorally demonstrated client repair with no actionable defect found; overall scope remains partial relative to the linked issue's no-upgrade-request expectation.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The body records shipped CLI/TUI connections through an isolated TLS proxy, actual scope frames and session-list results, plus preserved stored credentials across an upgrade; the current-head smoke exercises profile-before-hello and a successful /sessions request after fixture-backed identity lookups.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Guests granted only session access cannot use CLI session calls or connect the TUI without requesting broader permissions.
Reason: Restores a documented guest workflow while preserving authorization; eliminating the remaining trusted-proxy refusal belongs to #199699.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it addresses a current session-only guest workflow failure, and no introduced correctness defect was found; the enforced security approval remains pending.

Priority: P2
Reviewed head: 2fa4878a208e5ad7847efc20d2e6b2c5c61252c8

Before merge

  • Await maintainer action - A maintainer must review the security-sensitive changes at 2fa4878 and submit the enforced /allow-security-sensitive-change approval.

Findings

None.

Agent review details

How this fits together

CLI and TUI clients select connection scopes from device credentials or structured Gateway refusals; Gateway admission then enforces the grant, resolves the caller profile, and serves authorized session RPCs.

flowchart LR
  A[CLI or TUI] --> B[Stored device grant]
  B --> C[Existing scope projection]
  C --> D[Gateway client]
  D --> E[Gateway admission]
  E --> F[Profile and session RPCs]
  E --> G[Scope refusal]
  G --> D
Loading

Technical review

Best possible solution:

Land the client-side grant fitting after security approval, leaving first-contact trusted-proxy narrowing to the separately scoped follow-up.

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

Current-main source confirms the overbroad scope requests, and the linked report and supplied terminal traces demonstrate the resulting refusal; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch uses the existing scope projection and admission owners, preserves genuine upgrade requests, and includes the profile-ordering repair needed for a stable session-only connection.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1a60c2dc6c56.

Provenance checked

  • TUI default operator scopes changes intended behavior with a stated reason (d33683a: The original repair required explicit approved upgrades so cached read-only credentials could not silently remove TUI write and approval capabilities.)
  • Session scope projection keeps the original intent (da27b33: Project requested permissions through the original grant and the method's exact session authorization policy.)
  • sessions.create cwd escalation keeps the original intent (6bd21a1: Retry the structured pre-mutation admin requirement for filesystem-backed cwd selection.)
  • Deferred authenticated profile resolution changes intended behavior with a stated reason (f4f290c: The existing admission path resolves profiles before hello when policy or trusted-proxy co-author metadata requires them, otherwise permitting deferred identity enrichment.)
  • Gateway client host dependencies and token storage keeps the original intent (74d61d4: Accepted token persistence must settle before readiness or shutdown; moving host defaults retains the callbacks, types, and persistence owner.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit da27b33 adds src/gateway/method-scopes.ts:233 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: da27b336c0e9; files: src/gateway/method-scopes.ts)

PR surface

Source +221, Tests +322, Docs +10, Other 0. Total +553 across 19 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 9 340 119 +221
Tests 7 322 0 +322
Docs 2 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 19 673 120 +553

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Optional client API addition 1 callback fitScopesToApprovedGrant extends GatewayClientOptions, also reachable through the SDK GatewayClient; existing callers retain their behavior when it is omitted.

Root-cause cluster

Relationship: partial_overlap
Canonical: #199692
Summary: This PR supplies the client repair for the canonical guest-scope report; a stacked PR addresses the remaining first-contact refusal.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: Adds an optional public client callback and changes session-only scope negotiation; the maintainer-authored direction retains existing defaults for other grants and explicit shared credentials.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.

Label justifications:

  • P2: Repairs a concrete CLI/TUI failure for devices intentionally limited to session access.
  • merge-risk: 🚨 compatibility: Adds an optional public client callback and changes session-only scope negotiation; the maintainer-authored direction retains existing defaults for other grants and explicit shared credentials.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • 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 (6 earlier review cycles)
  • reviewed 2026-11-15T17:50:29.537Z sha 88cbcd5 :: needs real behavior proof before merge. :: [P2] Preserve the caller's read-only storage mode during retry | [P2] Limit the no-repeat guarantee to token-backed connections
  • reviewed 2026-11-15T21:14:29.810Z sha 48d8e52 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-15T22:52:51.291Z sha 48d8e52 :: blocked before merge. :: none
  • reviewed 2026-11-16T02:48:41.418Z sha 7185742 :: blocked before merge. :: none
  • reviewed 2026-11-16T04:20:56.491Z sha 74994fa :: blocked before merge. :: none
  • reviewed 2026-11-20T22:05:53.925Z sha 2fa4878 :: blocked before merge. :: none

Reviewed November 20, 2026, 5:23 PM ET / 22:23 UTC (Revision 7).

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Nov 15, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Nov 15, 2026
A device paired with only operator.sessions.write, as the multiplayer
guide recommends for guests, could not use `openclaw gateway call` or
`openclaw tui`: the CLI asked for operator.read (and the TUI for admin,
read, write and approvals), so every connect became a scope-upgrade
request for the administrator.

`gateway call` now projects its least-privilege scopes through the
stored device grant with projectOperatorScopesForMethod, but only when
the method's session-scoped alternative still authorizes the call. The
TUI connects within a stored grant that holds operator.sessions.* and
none of its default scopes, unless a shared token or password is given.

A device approved before it ever connected has no stored grant, so its
first request can still exceed it. The Gateway's scope-upgrade refusal
reports the approved scopes: the gateway client gains an opt-in
fitScopesToApprovedGrant hook that reconnects once within them, which
the TUI uses, and `gateway call` retries once with the session grant.
Both retries store the device token they receive, so later CLI and TUI
connections fit the grant without another upgrade request.

Any other gap keeps the current request, so real upgrades still reach
the administrator. Session-only devices see the session methods; the
TUI's command list and pending approvals stay unavailable.

The CLI scope selection, including the sessions.create cwd escalation
retry it already owned, moves to call-scopes.ts; the gateway client's
host dependency defaults move to client-host-deps.ts.
A caller without operator.read has its own profile published as the
activity viewer in hello. With Cloudflare Access identity deferred until
after hello, hello published null and the later attach changed the
viewer, closing the connection with 4001 "gateway policy changed" when
no named role was configured. Resolve that identity before hello so the
published viewer is already correct.
…lient.ts

The two type assertions in resolveHostDeps moved from client.ts, where
the assertion-safety baseline grandfathered them, into client-host-deps.ts.
Give each a SAFETY note and lower client.ts's baseline to its remaining one.
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 20, 2026
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

TUI smoke test at 2fa4878a208e for the profile-before-hello change.

I built the runtime on RooBook and ran the shipped openclaw tui against an isolated Gateway behind a loopback TLS proxy. The Gateway had no named operator roles, and the guest device was approved only for operator.sessions.write. The Access and GitHub HTTP responses came from test fixtures.

The TUI retried within the approved scope. The Gateway resolved the guest's profile before sending hello, and /sessions succeeded on the same WebSocket after both identity lookups.

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 20, 2026
@hannesrudolph

Copy link
Copy Markdown
Member

/allow-security-sensitive-change

@hannesrudolph
hannesrudolph merged commit 95e9afc into openclaw:main Nov 21, 2026
131 of 134 checks passed
daniel-lxs added a commit to daniel-lxs/openclaw that referenced this pull request Nov 21, 2026
Resolve conflicts from openclaw#199698 and openclaw#202616 landing on main: keep this
branch's trustedProxy.narrowToDeviceGrant docs and, in the session-only
Access guest test, keep main's hardened close/waitFor structure with this
branch's sessions.list admission check.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…#199698)

* fix(cli): connect through gateway.remote.edgeAuth without a Gateway token

A CLI behind an identity-aware proxy (Cloudflare Access) has no Gateway
token or password: the proxy authenticates the WebSocket upgrade and the
Gateway uses trusted-proxy auth. `openclaw tui`, `openclaw tui --url` and
`openclaw gateway call` refused to dial in that setup, so the device could
never send the pairing request the Cloudflare Access guide describes.

When edge-auth headers are configured for the target's origin, skip the
local shared-credential prechecks and let the Gateway's device pairing
decide. Targets without edgeAuth, and other origins, keep requiring
credentials as before.

* docs(cli): limit tokenless edgeAuth pairing to trusted-proxy Gateways

* fix(cli): tell an unpaired edgeAuth device to pair through the TUI

* fix(cli): keep an explicit --url in the edgeAuth pairing hint

* fix(cli): request scopes a session-only device grant covers

A device paired with only operator.sessions.write, as the multiplayer
guide recommends for guests, could not use `openclaw gateway call` or
`openclaw tui`: the CLI asked for operator.read (and the TUI for admin,
read, write and approvals), so every connect became a scope-upgrade
request for the administrator.

`gateway call` now projects its least-privilege scopes through the
stored device grant with projectOperatorScopesForMethod, but only when
the method's session-scoped alternative still authorizes the call. The
TUI connects within a stored grant that holds operator.sessions.* and
none of its default scopes, unless a shared token or password is given.

A device approved before it ever connected has no stored grant, so its
first request can still exceed it. The Gateway's scope-upgrade refusal
reports the approved scopes: the gateway client gains an opt-in
fitScopesToApprovedGrant hook that reconnects once within them, which
the TUI uses, and `gateway call` retries once with the session grant.
Both retries store the device token they receive, so later CLI and TUI
connections fit the grant without another upgrade request.

Any other gap keeps the current request, so real upgrades still reach
the administrator. Session-only devices see the session methods; the
TUI's command list and pending approvals stay unavailable.

The CLI scope selection, including the sessions.create cwd escalation
retry it already owned, moves to call-scopes.ts; the gateway client's
host dependency defaults move to client-host-deps.ts.

* fix(cli): keep read-only storage on the session-grant retry

* fix(gateway): resolve a session-only caller's identity before hello

A caller without operator.read has its own profile published as the
activity viewer in hello. With Cloudflare Access identity deferred until
after hello, hello published null and the later attach changed the
viewer, closing the connection with 4001 "gateway policy changed" when
no named role was configured. Resolve that identity before hello so the
published viewer is already correct.

* fix(gateway-client): document the host-deps assertions moved out of client.ts

The two type assertions in resolveHostDeps moved from client.ts, where
the assertion-safety baseline grandfathered them, into client-host-deps.ts.
Give each a SAFETY note and lower client.ts's baseline to its remaining one.
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Release adaptation: preserve stable OpenClaw ID membership role cap and documentation; move only the existing pre-cap connection scope projection before profile preparation. The projected scopes do not decide authority, and stable role resolution and capping remain after profile preparation.

Pinned companion audit: no follow-up cites #199698 or the source SHA; later identity/admission changes are not dependencies.

(cherry picked from commit 95e9afc)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: L status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants