Repository navigation
fix(agents): keep a bounded session mode on CLIs with native tools - #202945
Conversation
…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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherCLI 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]
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 743062e30ff5. Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: The new admission path can expand caller-granted tool authority before the Gateway grant is minted. EvidenceSecurity concerns:
What I checked:
Likely related people:
PR surfaceSource +11, Tests +35. Total +46 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 21, 2026, 12:39 AM ET / 05:39 UTC. |
|
|
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. |
…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]>
…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]>
…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]>
…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]>
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: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.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 aworkspacemode gets the mediated surface; a node-placed Claude turn with that mode is refused with the next step;fulland 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.ocx src), isolated Gateway, Claude CLI agent, caller with full operator scopes:execHost: node) inworkspacemodePaired node needs claude-cli-skills-v1…)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.workspacemode, read inside the workspaceFORK-READ-OK 7f3aFORK-READ-OK 7f3aNot proven live: Gemini CLI (not installed on the test host); covered by the unit test above.