Skip to content

fix(gateway): enforce the session permission mode on every Gateway tool call - #202941

Merged
obviyus merged 1 commit into
mainfrom
fix/gateway-session-permission-mode
Nov 21, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/gateway-session-permission-mode

Conversation

@obviyus

@obviyus obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

A chat set to a permission mode (Read only, Ask me, Auto-review) bounds file tools to its sessionRoot on the built-in runtime. On a Claude CLI chat it did not: the CLI calls OpenClaw's own tools through the Gateway (mcp__openclaw__read and friends), and the Gateway applied the session's mode only to restricted senders. An owner's Claude CLI chat in workspace mode read files anywhere on the host.

Why This Change Was Made

The Gateway runs these tools, so it owns the boundary. resolveGatewayScopedTools now applies the session's permission policy for every caller instead of only inheritedToolPolicySource === "sender" (that scope came from #165418, which kept "ordinary owner/profile authority unchanged"; nothing else relies on owners being unbounded). The prepared session workspace now also applies when the session has a mode, so relative paths resolve inside the same root the policy bounds.

Rule, now in docs/gateway/permission-modes.md: whoever runs a tool enforces the mode for it. The Gateway does for OpenClaw's tools on every runtime; Codex does for its own tools through its sandbox; host-only harnesses with their own tools (Muse, ACP) keep needing Full access. This replaces the paragraph from #202659 that said CLI chats use the CLI's own controls. A new sentence states that modes bound file tools and pick the exec reviewer; exec is not confined to sessionRoot unless the runtime sandboxes commands.

Effects:

  • Sessions with no mode (the policy is undefined) are unchanged: cron, Skill Workshop, completion handoffs, subagents without a mode.
  • Owner POST /tools/invoke on a mode-set session is bounded the same way (same resolver, already passed the policy).
  • Subagent attachment roots stay readable: the Gateway builds tools through the same assembly that adds subagentAttachmentRootForRun.

Evidence

  • src/gateway/tool-resolution.test.ts: an owner's loopback read on a read-only session refuses a path outside the root and lists no write; with no mode it reads. Red on the merge base (expected '{"content":[{"type":"text","text":"ou…' to contain 'escapes'), green here.
  • Real product, tier source (ocx src), isolated Gateway, a Claude CLI agent and a built-in ChatGPT agent, chat set to permissionMode: "workspace", caller with full operator scopes, asked to read a file outside the workspace:
Merge base This branch
Claude CLI read it: OUTSIDE-SECRET 91c2 refused: Path escapes sandbox root (…/workspace): …/outside.txt
Built-in refused, same error refused, same error

Exec on that Claude CLI chat is unchanged by this PR (both: exec denied: Headless runs cannot wait for interactive exec approval … security=allowlist ask=on-miss), while the built-in chat's exec goes through the auto-reviewer; that difference predates this change and is tracked separately.

…ol call

The Gateway applied a session's permission mode only to restricted senders, so an owner's Claude CLI chat in a bounded mode read files anywhere through OpenClaw's own tools. The Gateway runs those tools, so it now enforces the mode for every caller.
@clawsweeper

clawsweeper Bot commented Nov 21, 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: XS labels Nov 21, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Applies a session’s permission policy to Gateway-managed tools for every caller, including unrestricted owners using CLI chats.

Example: An owner’s Claude CLI chat uses workspace mode and requests outside.txt outside its workspace.

  • Before: The Gateway read returns OUTSIDE-SECRET 91c2.
  • After: The Gateway refuses the read with Path escapes sandbox root.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by a production-path regression and concrete supplied live results; captured required CI was still pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied live output exercises the changed resolver through a real Claude CLI agent on an isolated Gateway: an outside-root workspace-mode read succeeds on the merge base and is refused on this branch, with the built-in runtime as a stable control.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An owner selecting a bounded permission mode in a Claude CLI chat can still read outside the session root through OpenClaw tools.
Reason: Enforcing the selected mode at the tool executor provides clear user value, and the collaborator-authored PR explicitly authorizes and explains the change from the previously documented exception.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a current Gateway permission-boundary failure with a focused change and supplied live proof; no introduced correctness or security defect was found.

Priority: P1
Reviewed head: 90ba16a55e9e7549e195265a7fdad168f38e94b9

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI MCP calls and authenticated HTTP tool invocations enter the shared Gateway resolver, which passes session policy into existing tool factories and returns policy-constrained tools.

flowchart TD
  A[CLI MCP request] --> C[Gateway tool resolver]
  B[HTTP tool invocation] --> C
  D[Prepared session permission policy] --> C
  C --> E[Existing tool factories]
  E --> F[Filesystem and execution policy]
  F --> G[Tool result or refusal]
Loading

Technical review

Best possible solution:

Land the focused shared-resolver repair after required checks pass, keeping native CLI mediation in its existing stacked follow-up.

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

Current-main source shows the policy being discarded for unrestricted owners, and the PR supplies a matching real CLI before/after reproduction; this review executed no target code.

Is this the best way to solve the issue?

This is the smallest complete Gateway repair: pass the already-prepared session policy into existing factories and align workspace selection, with one meaningful boundary regression and no competing implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 743062e30ff5.

Provenance checked

  • Gateway session-policy filtering and workspace selection changes intended behavior with a stated reason (9698a5b: The restricted-sender repair preserved owner/profile behavior while carrying sender restrictions through CLI and HTTP tools; later refactors retained the condition.)
  • Documented CLI permission exception changes intended behavior with a stated reason (b7bf937: Subscription CLI fork work explicitly accepted and documented parity with unrestricted owner CLI turns; this PR replaces that exception with enforcement by the Gateway that executes the tools.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Avant: Raw commit b8980ca adds src/gateway/tool-resolution.ts:378 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: b8980ca9a0b6; files: src/gateway/tool-resolution.ts)

PR surface

Source -1, Tests +30, Docs +2. Total +31 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 5 -1
Tests 1 30 0 +30
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 37 6 +31

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.

Labels

Label changes:

  • add P1: A real owner CLI chat can bypass its explicitly selected filesystem boundary through Gateway-managed tools.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: A real owner CLI chat can bypass its explicitly selected filesystem boundary through Gateway-managed tools.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • 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.

Reviewed November 21, 2026, 12:28 AM ET / 05:28 UTC.

@obviyus
obviyus merged commit a1599a4 into main Nov 21, 2026
135 checks passed
@obviyus
obviyus deleted the fix/gateway-session-permission-mode branch November 21, 2026 06:05
@obviyus

obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Landed. A chat's permission mode now bounds OpenClaw's own tools on every runtime: the Gateway applies the session's policy to every caller, not only restricted senders, so a Claude CLI chat in a bounded mode can no longer read outside its sessionRoot through mcp__openclaw__read. Proof: regression test red on the merge base, green here; live isolated Gateway where a workspace-mode Claude CLI chat's outside read went from succeeding to Path escapes sandbox root, matching the built-in runtime.

obviyus added a commit that referenced this pull request Nov 21, 2026
…202945)

## What Problem This Solves

After #202941 the Gateway bounds OpenClaw's tools to a session's permission mode on every runtime. A CLI backend that keeps its own native tools still ignored the mode: Gemini CLI (its native file tools are never mediated) and a Claude CLI chat placed on a node (it keeps Claude's native tools). A Read only / Ask me / Auto-review chat on those routes could read and write anywhere through the CLI's own tools.

## Why This Change Was Made

The CLI tool policy already has one owner for "this run must use only Gateway-mediated tools": the mediation path used for `tools.fs.workspaceOnly`, restricted senders and delegated runs. A bounded session mode now joins that list for backends that are not already mediated:

- A backend that can run on the mediated surface (Gemini CLI with exact tool support) does so, and the Gateway enforces the mode.
- A run that cannot be mediated (node-placed Claude, a backend without exact tools or the Gateway MCP bridge) is refused before any CLI or node I/O: `CLI backend <id> uses its own tools here and cannot keep this chat's <mode> permissions. Change this chat to Full access, or choose another runtime.`
- Full access and sessions with no mode are unchanged. Ordinary Claude CLI turns are already mediated and unchanged.

No existing chat on our deployments has a bounded mode on these routes (Peanutto: 64 Claude CLI chats, none node-placed, all mode unset; team-metal: none).

## Evidence

- `prepare-tool-policy.delegation.test.ts`: a Gemini CLI turn with a `workspace` mode gets the mediated surface; a node-placed Claude turn with that mode is refused with the next step; `full` and unset keep the native surface. The two new mode cases fail on #202941's head and pass here.
- Real product, tier source (`ocx src`), isolated Gateway, Claude CLI agent, caller with full operator scopes:

| | #202941 head | This branch |
|---|---|---|
| Node-placed chat (`execHost: node`) in `workspace` mode | dispatched to the node (no node present: `Paired node needs claude-cli-skills-v1…`) | refused before dispatch: `CLI backend claude-cli uses its own tools here and cannot keep this chat's workspace permissions. Change this chat to Full access, or choose another runtime.` |
| Ordinary chat in `workspace` mode, read inside the workspace | `FORK-READ-OK 7f3a` | `FORK-READ-OK 7f3a` |

Not proven live: Gemini CLI (not installed on the test host); covered by the unit test above.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 21, 2026
…ls (#202957)

## What Problem This Solves

#202945 added a second refusal path to the CLI tool policy: a bounded session mode on a CLI backend that keeps its own native tools (Gemini CLI, a node-placed Claude CLI chat) either forced the mediated surface or refused the turn. No chat on our deployments hits that case (Peanutto: 64 Claude CLI chats, none node-placed, none with a mode; team-metal: none), and it added a rule beside the one owner we want.

## Why This Change Was Made

One rule: whoever runs a tool enforces the mode for it. The Gateway enforces the session mode on OpenClaw's own tools on every runtime (#202941, unchanged). A CLI backend's own native tools follow that CLI's permission controls; `docs/gateway/permission-modes.md` now says so instead of encoding a refusal.

## Changes

- Reverts #202945 (`prepare-tool-policy.ts` back to its prior conditions, its three test cases removed).
- One docs sentence naming Gemini CLI file tools and node-placed Claude CLI as following the CLI's own controls.

Production: +1 −14. Tests: −35.

## Evidence

- Pure revert of 8fdae41 plus docs; the code is byte-identical to its pre-#202945 state, which ran on `main` with green CI.
- #202941's Gateway enforcement and its regression test are untouched.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…ol call (openclaw#202941)

## What Problem This Solves

A chat set to a permission mode (Read only, Ask me, Auto-review) bounds file tools to its `sessionRoot` on the built-in runtime. On a Claude CLI chat it did not: the CLI calls OpenClaw's own tools through the Gateway (`mcp__openclaw__read` and friends), and the Gateway applied the session's mode only to restricted senders. An owner's Claude CLI chat in `workspace` mode read files anywhere on the host.

## Why This Change Was Made

The Gateway runs these tools, so it owns the boundary. `resolveGatewayScopedTools` now applies the session's permission policy for every caller instead of only `inheritedToolPolicySource === "sender"` (that scope came from openclaw#165418, which kept "ordinary owner/profile authority unchanged"; nothing else relies on owners being unbounded). The prepared session workspace now also applies when the session has a mode, so relative paths resolve inside the same root the policy bounds.

Rule, now in `docs/gateway/permission-modes.md`: whoever runs a tool enforces the mode for it. The Gateway does for OpenClaw's tools on every runtime; Codex does for its own tools through its sandbox; host-only harnesses with their own tools (Muse, ACP) keep needing Full access. This replaces the paragraph from openclaw#202659 that said CLI chats use the CLI's own controls. A new sentence states that modes bound file tools and pick the exec reviewer; exec is not confined to `sessionRoot` unless the runtime sandboxes commands.

Effects:
- Sessions with no mode (the policy is undefined) are unchanged: cron, Skill Workshop, completion handoffs, subagents without a mode.
- Owner `POST /tools/invoke` on a mode-set session is bounded the same way (same resolver, already passed the policy).
- Subagent attachment roots stay readable: the Gateway builds tools through the same assembly that adds `subagentAttachmentRootForRun`.

## Evidence

- `src/gateway/tool-resolution.test.ts`: an owner's loopback `read` on a `read-only` session refuses a path outside the root and lists no `write`; with no mode it reads. Red on the merge base (`expected '{"content":[{"type":"text","text":"ou…' to contain 'escapes'`), green here.
- Real product, tier source (`ocx src`), isolated Gateway, a Claude CLI agent and a built-in ChatGPT agent, chat set to `permissionMode: "workspace"`, caller with full operator scopes, asked to read a file outside the workspace:

| | Merge base | This branch |
|---|---|---|
| Claude CLI | read it: `OUTSIDE-SECRET 91c2` | refused: `Path escapes sandbox root (…/workspace): …/outside.txt` |
| Built-in | refused, same error | refused, same error |

Exec on that Claude CLI chat is unchanged by this PR (both: `exec denied: Headless runs cannot wait for interactive exec approval … security=allowlist ask=on-miss`), while the built-in chat's exec goes through the auto-reviewer; that difference predates this change and is tracked separately.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…penclaw#202945)

## What Problem This Solves

After openclaw#202941 the Gateway bounds OpenClaw's tools to a session's permission mode on every runtime. A CLI backend that keeps its own native tools still ignored the mode: Gemini CLI (its native file tools are never mediated) and a Claude CLI chat placed on a node (it keeps Claude's native tools). A Read only / Ask me / Auto-review chat on those routes could read and write anywhere through the CLI's own tools.

## Why This Change Was Made

The CLI tool policy already has one owner for "this run must use only Gateway-mediated tools": the mediation path used for `tools.fs.workspaceOnly`, restricted senders and delegated runs. A bounded session mode now joins that list for backends that are not already mediated:

- A backend that can run on the mediated surface (Gemini CLI with exact tool support) does so, and the Gateway enforces the mode.
- A run that cannot be mediated (node-placed Claude, a backend without exact tools or the Gateway MCP bridge) is refused before any CLI or node I/O: `CLI backend <id> uses its own tools here and cannot keep this chat's <mode> permissions. Change this chat to Full access, or choose another runtime.`
- Full access and sessions with no mode are unchanged. Ordinary Claude CLI turns are already mediated and unchanged.

No existing chat on our deployments has a bounded mode on these routes (Peanutto: 64 Claude CLI chats, none node-placed, all mode unset; team-metal: none).

## Evidence

- `prepare-tool-policy.delegation.test.ts`: a Gemini CLI turn with a `workspace` mode gets the mediated surface; a node-placed Claude turn with that mode is refused with the next step; `full` and unset keep the native surface. The two new mode cases fail on openclaw#202941's head and pass here.
- Real product, tier source (`ocx src`), isolated Gateway, Claude CLI agent, caller with full operator scopes:

| | openclaw#202941 head | This branch |
|---|---|---|
| Node-placed chat (`execHost: node`) in `workspace` mode | dispatched to the node (no node present: `Paired node needs claude-cli-skills-v1…`) | refused before dispatch: `CLI backend claude-cli uses its own tools here and cannot keep this chat's workspace permissions. Change this chat to Full access, or choose another runtime.` |
| Ordinary chat in `workspace` mode, read inside the workspace | `FORK-READ-OK 7f3a` | `FORK-READ-OK 7f3a` |

Not proven live: Gemini CLI (not installed on the test host); covered by the unit test above.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…ls (openclaw#202957)

## What Problem This Solves

openclaw#202945 added a second refusal path to the CLI tool policy: a bounded session mode on a CLI backend that keeps its own native tools (Gemini CLI, a node-placed Claude CLI chat) either forced the mediated surface or refused the turn. No chat on our deployments hits that case (Peanutto: 64 Claude CLI chats, none node-placed, none with a mode; team-metal: none), and it added a rule beside the one owner we want.

## Why This Change Was Made

One rule: whoever runs a tool enforces the mode for it. The Gateway enforces the session mode on OpenClaw's own tools on every runtime (openclaw#202941, unchanged). A CLI backend's own native tools follow that CLI's permission controls; `docs/gateway/permission-modes.md` now says so instead of encoding a refusal.

## Changes

- Reverts openclaw#202945 (`prepare-tool-policy.ts` back to its prior conditions, its three test cases removed).
- One docs sentence naming Gemini CLI file tools and node-placed Claude CLI as following the CLI's own controls.

Production: +1 −14. Tests: −35.

## Evidence

- Pure revert of edc2e97 plus docs; the code is byte-identical to its pre-openclaw#202945 state, which ran on `main` with green CI.
- openclaw#202941's Gateway enforcement and its regression test are untouched.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…ol call (#202941)

A chat set to a permission mode (Read only, Ask me, Auto-review) bounds file tools to its `sessionRoot` on the built-in runtime. On a Claude CLI chat it did not: the CLI calls OpenClaw's own tools through the Gateway (`mcp__openclaw__read` and friends), and the Gateway applied the session's mode only to restricted senders. An owner's Claude CLI chat in `workspace` mode read files anywhere on the host.

The Gateway runs these tools, so it owns the boundary. `resolveGatewayScopedTools` now applies the session's permission policy for every caller instead of only `inheritedToolPolicySource === "sender"` (that scope came from #165418, which kept "ordinary owner/profile authority unchanged"; nothing else relies on owners being unbounded). The prepared session workspace now also applies when the session has a mode, so relative paths resolve inside the same root the policy bounds.

Rule, now in `docs/gateway/permission-modes.md`: whoever runs a tool enforces the mode for it. The Gateway does for OpenClaw's tools on every runtime; Codex does for its own tools through its sandbox; host-only harnesses with their own tools (Muse, ACP) keep needing Full access. This replaces the paragraph from #202659 that said CLI chats use the CLI's own controls. A new sentence states that modes bound file tools and pick the exec reviewer; exec is not confined to `sessionRoot` unless the runtime sandboxes commands.

Effects:
- Sessions with no mode (the policy is undefined) are unchanged: cron, Skill Workshop, completion handoffs, subagents without a mode.
- Owner `POST /tools/invoke` on a mode-set session is bounded the same way (same resolver, already passed the policy).
- Subagent attachment roots stay readable: the Gateway builds tools through the same assembly that adds `subagentAttachmentRootForRun`.

- `src/gateway/tool-resolution.test.ts`: an owner's loopback `read` on a `read-only` session refuses a path outside the root and lists no `write`; with no mode it reads. Red on the merge base (`expected '{"content":[{"type":"text","text":"ou…' to contain 'escapes'`), green here.
- Real product, tier source (`ocx src`), isolated Gateway, a Claude CLI agent and a built-in ChatGPT agent, chat set to `permissionMode: "workspace"`, caller with full operator scopes, asked to read a file outside the workspace:

| | Merge base | This branch |
|---|---|---|
| Claude CLI | read it: `OUTSIDE-SECRET 91c2` | refused: `Path escapes sandbox root (…/workspace): …/outside.txt` |
| Built-in | refused, same error | refused, same error |

Exec on that Claude CLI chat is unchanged by this PR (both: `exec denied: Headless runs cannot wait for interactive exec approval … security=allowlist ask=on-miss`), while the built-in chat's exec goes through the auto-reviewer; that difference predates this change and is tracked separately.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit a1599a4)

Release adaptation: Insert the enforcement paragraphs because the stable baseline lacks the earlier CLI paragraph; retain stable-only guidance and clarify the native CLI distinction from #202957.

Companions: #202945/#202957 runtime changes cancel out (baseline-equivalent); #202957 documentation distinction is included here. #202306 is a separate project-move feature, not applicable. Neither #202659 CLI forking nor the adjacent sharing, file-write, role, and routing changes are dependencies.
Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
Plugin session forks (`runForkedTurn`, `forkSession`; for example Better Prompt and Skill Workshop reviews) always ran on the built-in runtime. On a Claude CLI chat signed in with a Claude subscription:

- With only the CLI's own `claude` login, `runForkedTurn` failed with `No API key found for provider "claude-cli"`.
- With a Claude subscription token stored in OpenClaw, `runForkedTurn` sent the token to the Anthropic API directly, which bills metered extra usage instead of the plan (`cliBackendDispatch` notes in `run/params.ts`).
- `forkSession` refused every CLI runtime: `Session forks are not supported for CLI runtime claude-cli.`

OpenClaw already has one owner for "run this embedded run on the subscription CLI": `cliBackendDispatch: "subscription-auth"` (Active Memory's recall uses it). The fork owner opts into it; no new path:

- `runSessionFork` sets `cliBackendDispatch: "subscription-auth"`. Eligibility is unchanged: subscription (oauth/token) or unresolvable credentials go to the CLI; API keys keep the request replay and its prompt cache.
- Dispatch accepts the fork's in-memory conversation (`sessionManager`), and sends the CLI only the tools that may execute (`toolExecutionAllow`; an empty list is a tool-free run).
- Dispatch now picks the CLI account the way a new CLI session does. Before, it passed only an explicit pin, so a stored Claude token never reached the CLI (`Not logged in · Please run /login`); Active Memory recalls had the same gap.
- Runs that grant the plugin's own tools or set `maxTokens` keep the direct route: neither reaches a CLI process.
- Dispatch carries the run's policy facts to the CLI: a run under another session's policy (a fork's `sandboxSessionKey`) passes that session's entry, the requester fields and `internal_system` provenance into the CLI's Gateway tool grant, so restricted-sender limits apply to the fork as to the chat's own turns.

Accepted: a CLI fork starts a fresh CLI session with the conversation as context, so it does not reuse the chat's cache, and each fork leaves one Claude session file under `~/.claude/projects`, as Active Memory's CLI recalls already do. The source chat's native session is never resumed or written.

Permission modes (maintainer decision, now in `docs/gateway/permission-modes.md`): the `sessionRoot` boundary is enforced on the built-in runtime; CLI-backed chats use the CLI's own controls, and owner turns' Gateway tools are not limited to `sessionRoot`. Live, on a Claude CLI chat in `workspace` mode, an ordinary turn and a fork both read a file outside the workspace through `mcp__openclaw__read`, and the same chat on the built-in runtime refuses both with `Path escapes sandbox root`. A CLI fork therefore has the same file access as the chat's own CLI turns.

Not covered: Gemini CLI on a Google login (OpenClaw cannot limit its tools under OAuth), and harnesses that own their login with no limited one-shot turn (Copilot, Muse, `acp-*`).

Real product, tier source (`ocx src`), isolated foreground Gateway, no API key in the environment or auth store; profiles: Claude subscription setup token, ChatGPT OAuth, Grok OAuth. Each chat: one turn ("Remember PELICAN-42"), then forks through a probe plugin.

| Route | `runForkedTurn` `[read, ls]` | `forkSession` | `runForkedTurn` cache read |
|---|---|---|---|
| `claude-cli`, Claude token | `PELICAN-42 \| FORK-READ-OK 7f3a` (dispatched to Claude CLI) | `PELICAN-42` | 6,985 |
| ChatGPT OAuth, built-in | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (cache read 9,856) | 10,112 |
| Codex app-server | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (19,584) | 8,704 |
| Grok OAuth | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (1,152) | 1,152 |

- `main` on the same Claude chat: `runForkedTurn` ran on the Anthropic API with the token (cache read 0, cache write 23,872), `forkSession` refused.
- Every route: source transcript hash, message count and native binding unchanged; the Claude source session file holds only the chat's own turn.
- Better Prompt 0.2.2 (`start` → `take` through `plugins.sessionAction`) produced an improved prompt on the Claude CLI chat and on the ChatGPT chat.
- Dispatch tests: a fork runs on the CLI with only its own tools from its in-memory session; plugin tool grants and output caps keep the passthrough.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit b7bf937)

Release adaptation: retain staged Gateway permission-mode documentation and enforcement; omit the superseded upstream documentation exception.

Companions: #202941 and #202646 are present-equivalent (9ec8d08 and 087c816); #201554 is staged as 5647120. #202957 is not applicable (reverts a separate native-tools path). #204219, #203999, #203901, #203919, #203601 and #203271 are independent prewarm, lifecycle, recovery, review or default-routing changes; not required for the selected fork path.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 8a592a33b7866a1306c60468e4aaf2c9fb23a93f)
tideclaw-bot added a commit that referenced this pull request Nov 24, 2026
…ol call (#202941)

Baseline adaptation: Enforce the session policy at the Gateway tool owner for owner and restricted caller paths; use the existing prepared workspace root when available.

(cherry picked from commit a1599a4)

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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

1 participant