Skip to content

revert(agents): drop the bounded-mode branch for CLIs with native tools - #202957

Merged
obviyus merged 1 commit into
mainfrom
cut/revert-202945
Nov 21, 2026
Merged

obviyus merged 1 commit into
mainfrom
cut/revert-202945

Conversation

@obviyus

@obviyus obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

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

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

Evidence

Reverts #202945. It added a second refusal path for a case no current chat hits. A CLI backend's own native tools follow that CLI's permission controls; the docs say so. The Gateway keeps enforcing the mode on OpenClaw's tools (#202941).
@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 agents Agent runtime and tooling 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: a7e1626250ec3da7a6bfe00da7c14fbb33d712bd
  • 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.

@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. 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

Removes session-mode-driven mediation and refusal for native CLI tools while retaining Gateway enforcement for OpenClaw tools.

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

  • Before: The turn is refused before node dispatch because its native tools cannot enforce the session mode.
  • After: The turn may dispatch to the node, with native tools governed by Claude CLI controls.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation matches the approved direction and has green exact-head checks, but the changed user-visible route lacks after-change runtime proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Maintenance · Worth it: Yes · Fix scope: Complete
User problem: A bounded session mode can prevent a native CLI chat from starting even when the operator intends to use that CLI's own permission controls.
Reason: The maintainer-authored PR explicitly chooses executor-owned enforcement, explains the reversal, and limits the change to that choice.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR makes an explicit, narrowly implemented policy choice; no introduced correctness defect was identified.

Priority: P2
Reviewed head: a7e1626250ec3da7a6bfe00da7c14fbb33d712bd

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Show a reviewed-head native CLI turn with a bounded session mode proceeding under CLI controls, alongside an ordinary mediated Claude turn retaining Gateway containment.
Agent review details

How this fits together

CLI turn preparation selects native or Gateway-mediated tools before backend execution; the Gateway independently enforces session policy when executing OpenClaw tools.

flowchart TD
  A[Session and caller policy] --> B[CLI tool policy preparation]
  B --> C[Native CLI tools]
  B --> D[Gateway mediated tools]
  C --> E[CLI permission controls]
  D --> F[Gateway session enforcement]
  E --> G[Tool result]
  F --> G
Loading

Technical review

Best possible solution:

Retain the focused revert and documented executor-owned policy split, with the changed CLI route demonstrated through the shipped entry point.

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

Source shows that a node-placed Claude turn with workspace mode reaches the dedicated refusal on current main and bypasses that removed condition in this PR; this review executed no target code.

Is this the best way to solve the issue?

The diff is the smallest complete implementation of the recorded direction: remove the session-mode-only branch and its obsolete tests, retain existing authority checks, and clarify the native-tool exception in the permission documentation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Native CLI bounded-mode mediation and refusal changes intended behavior with a stated reason (8fdae41: Prevent bounded-mode chats from using native tools outside the session boundary by mediating them or refusing before CLI or node I/O.)
  • Permission-mode executor ownership documentation keeps the original intent (a1599a4: Place OpenClaw tool enforcement at the Gateway that executes those tools, independently of runtime-native controls.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • 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)
  • 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)
  • Peter Steinberger: Raw commit b10a19d adds src/agents/cli-runner/prepare-tool-policy.ts:93 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)

PR surface

Source -12, Tests -35, Docs 0. Total -47 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 13 -12
Tests 1 0 35 -35
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 2 49 -47

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 P2: This is a narrow, maintainer-directed CLI policy adjustment without evidence of an urgent affected deployment.
  • add merge-risk: 🚨 security-boundary: Bounded session modes cease forcing mediation or refusal for native CLI tools; the maintainer-authored PR explicitly accepts CLI-owned controls for that surface.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a narrow, maintainer-directed CLI policy adjustment without evidence of an urgent affected deployment.
  • merge-risk: 🚨 security-boundary: Bounded session modes cease forcing mediation or refusal for native CLI tools; the maintainer-authored PR explicitly accepts CLI-owned controls for that surface.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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, 1:25 AM ET / 06:25 UTC.

@obviyus
obviyus merged commit d31a943 into main Nov 21, 2026
126 checks passed
@obviyus
obviyus deleted the cut/revert-202945 branch November 21, 2026 08:16
@obviyus

obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as d31a943. Reverts #202945: a bounded session mode on a CLI that keeps its own native tools is no longer refused or rerouted; those tools follow the CLI's own permission controls, as docs/gateway/permission-modes.md now states. The Gateway still enforces the mode on OpenClaw's own tools (#202941).

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

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime security-sensitive-changed size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant