Skip to content

fix(agents): keep a bounded session mode on CLIs with native tools - #202945

Merged
obviyus merged 3 commits into
mainfrom
fix/cli-native-tools-permission-mode
Nov 21, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/cli-native-tools-permission-mode

Conversation

@obviyus

@obviyus obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #202941 (the Gateway enforces the session mode on every Gateway tool call); review the last commit.

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 fix(gateway): enforce the session permission mode on every Gateway tool call #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.

…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.
A CLI backend that keeps its own native tools (Gemini CLI, node-placed Claude) ignored the session's permission mode. A bounded mode now runs those turns on the Gateway-mediated tool surface, where the Gateway enforces it, and refuses with a next step where mediation is impossible.
@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 agents Agent runtime and tooling size: XS labels Nov 21, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR mediates native CLI tools for bounded session modes and refuses runs that cannot enforce those permissions.

Example: A Claude CLI chat has execHost=node and permissionMode=workspace.

  • Before: The run proceeds toward node dispatch with native tools.
  • After: Preparation refuses the run and suggests Full access or another runtime.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful and narrowly scoped, with partial live proof, but exact-cap expansion blocks merge.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A chat displaying bounded permissions can still use CLI-native tools outside those boundaries.
Reason: The maintainer-authored direction restores the displayed permission contract through the existing policy owner.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: the permission-boundary repair is useful, but the new mediation path can widen an existing exact tool cap.

Priority: P1
Reviewed head: 142ec057d0088ea1cdfa4f30d0a5896aaad6a2ce

Before merge

  • Preserve exact tool caps when adding permission-mode mediation (P1) - For an ordinary local Claude or Gemini run with permissionMode="workspace", cliToolAvailability={native:[],openClaw:["read"]}, and workspaceOnly disabled, this new condition enters mediation even though the caller already supplied an exact surface. exactWorkspaceTools remains undefined because it is gated only by workspaceOnly, so runtimeToolsAllowPolicy becomes ["*"]. prepareCliMcpToolProjection prioritizes that wildcard, and prepare.ts materializes the resulting catalog, enabling policy-allowed write and other tools excluded by the caller. Preserve or project the exact selection for permission-mode mediation as the workspace-only path already does, and add a regression covering this input.
  • Resolve security concern: Exact caller authority is lost during mediation - The affected principal is a CLI agent admitted with a read-only exact tool surface; wildcard projection can grant workspace mutation capability despite that narrower admission.
  • Explain or restore the original intent of Exact tool selections during filesystem mediation - b10a19d: Enforce workspace-only access without broadening explicit caller tool selections.

Findings

  • [P1] Preserve exact tool caps when adding permission-mode mediation — src/agents/cli-runner/prepare-tool-policy.ts:142
  • [high] Exact caller authority is lost during mediation — src/agents/cli-runner/prepare-tool-policy.ts:142

Provenance

  • Exact tool selections during filesystem mediation changes intended behavior without addressing why it exists (b10a19d: Enforce workspace-only access without broadening explicit caller tool selections.)

Tests

  • Missing end-to-end proof: Provide redacted live Gemini output showing bounded-tool enforcement and supported-auth behavior, plus an upgrade run preserving existing session modes and settings.
Agent review details

How this fits together

CLI preparation translates session permissions and caller tool caps into native tool selections and Gateway MCP grants before starting the backend.

flowchart TD
  A[Session and caller policy] --> B[CLI tool policy]
  B --> C[Exact tool projection]
  C --> D[Gateway MCP grant]
  D --> E[CLI backend]
  B --> F[Unsupported run refusal]
Loading

Technical review

Best possible solution:

Extend the existing exact-selection preservation to bounded-mode mediation so session permissions tighten caller authority without expanding it.

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

Source establishes the native-tool bypass and the introduced exact-cap expansion; the author supplies live node-refusal output, and this read-only review ran no target code.

Is this the best way to solve the issue?

Reusing the mediation owner is the smallest appropriate repair, but its exact-selection branch must also cover the newly admitted bounded-mode runs.

Full review comments:

  • [P1] Preserve exact tool caps when adding permission-mode mediation — src/agents/cli-runner/prepare-tool-policy.ts:142
    For an ordinary local Claude or Gemini run with permissionMode="workspace", cliToolAvailability={native:[],openClaw:["read"]}, and workspaceOnly disabled, this new condition enters mediation even though the caller already supplied an exact surface. exactWorkspaceTools remains undefined because it is gated only by workspaceOnly, so runtimeToolsAllowPolicy becomes ["*"]. prepareCliMcpToolProjection prioritizes that wildcard, and prepare.ts materializes the resulting catalog, enabling policy-allowed write and other tools excluded by the caller. Preserve or project the exact selection for permission-mode mediation as the workspace-only path already does, and add a regression covering this input.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Ordinary Claude mediation and unsupported-route refusal changes intended behavior with a stated reason (77d9f42: Keep ordinary turns and child completions on a stable mediated tool surface while leaving explicit selections and node execution separate.)
  • Managed native orchestration tools keeps the original intent (3eeb12b: Retain operator-selected orchestration tools on uncapped managed turns while dropping them for restricted surfaces.)

Testing

Proof path: shipped entry point.

Security

Needs attention: The new admission path can expand caller-granted tool authority before the Gateway grant is minted.

Evidence

Security concerns:

  • [high] Exact caller authority is lost during mediation — src/agents/cli-runner/prepare-tool-policy.ts:142
    The affected principal is a CLI agent admitted with a read-only exact tool surface; wildcard projection can grant workspace mutation capability despite that narrower admission.
    Confidence: 0.97

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b10a19d adds src/agents/cli-runner/prepare-tool-policy.ts:110 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b10a19d0e551; files: src/agents/cli-runner/prepare-tool-policy.ts)
  • Marvinthebored: Raw commit 77d9f42 adds src/agents/cli-runner/prepare-tool-policy.ts:97 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 77d9f42c86bf; files: src/agents/cli-runner/prepare-tool-policy.ts)
  • Vito Cappello: Raw commit 3eeb12b adds src/agents/cli-runner/prepare-tool-policy.ts:141 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3eeb12bea80b; files: src/agents/cli-runner/prepare-tool-policy.ts)
  • Ayaan Zaidi: Raw commit 7ad0c95 adds src/agents/cli-runner/prepare-tool-policy.ts:111 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7ad0c95ab6c3; files: src/agents/cli-runner/prepare-tool-policy.ts)

PR surface

Source +11, Tests +35. Total +46 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 12 1 +11
Tests 1 35 0 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 47 1 +46

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: The change repairs an active permissions boundary, but introduces a path that expands an exact caller tool cap.
  • add merge-risk: 🚨 compatibility: Existing bounded native-tool sessions can begin refusing execution; the maintainer-authored direction explicitly accepts refusal where mediation is unavailable.
  • add merge-risk: 🚨 security-boundary: A CLI agent admitted with an exact read-only tool selection can receive additional policy-allowed tools.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The change repairs an active permissions boundary, but introduces a path that expands an exact caller tool cap.
  • merge-risk: 🚨 security-boundary: A CLI agent admitted with an exact read-only tool selection can receive additional policy-allowed tools.
  • merge-risk: 🚨 compatibility: Existing bounded native-tool sessions can begin refusing execution; the maintainer-authored direction explicitly accepts refusal where mediation is unavailable.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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:39 AM ET / 05:39 UTC.

Base automatically changed from fix/gateway-session-permission-mode to main November 21, 2026 06:05
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S and removed size: XS labels Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 1a24bb1a51a2c0393a8bfd4ad7d119bbf4128aef
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/cli-runner/prepare-tool-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@obviyus
obviyus merged commit 8fdae41 into main Nov 21, 2026
131 checks passed
@obviyus
obviyus deleted the fix/cli-native-tools-permission-mode branch November 21, 2026 06:06
@obviyus

obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Landed. A CLI chat that would keep its own native tools (Gemini CLI, node-placed Claude) now runs on the Gateway-mediated tool surface when the session has a bounded mode, so the Gateway enforces it; where that is impossible the turn is refused before any CLI or node I/O with a next step. Full access and unset modes are unchanged. Proof: unit cases red on #202941's head and green here; live isolated Gateway where a node-placed workspace-mode Claude CLI chat went from being dispatched to the node to the refusal, while an ordinary workspace-mode chat still reads inside its workspace.

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
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant