Repository navigation
feat(plugins): let plugin forks read, ls and run owner exec under the session's policy - #200636
Conversation
… session's policy - runForkedTurn accepts read, ls and exec. They join only the fork's run-time allow list, never the plugin grant, so the session's own tool policy must already allow them. - exec runs only on the owner's turns, and a fork never creates an exec approval request: a command that needs approval is denied (existing nonInteractiveApproval rule). - through is optional; the fork reads through the session's latest message by default. - A manifest may claim a core catalog id only when core builds no tool for it, so contracts.tools cannot widen a profile with exec or read.
|
🦞👀 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: needs changes before merge. What this changesThis PR lets plugin forks use session-authorized read, ls and owner exec, makes the transcript anchor optional, and rejects additional core-tool impersonation grants. Example: A prompt-improvement plugin requests read, ls and exec on an owner's coding session.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this maintainer-authored PR adds a useful plugin capability through existing owners, but a reflowed comment introduces a mechanically repairable CI failure. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherThe Gateway plugin adapter resolves the source conversation and requester, the existing fork owner admits and runs background inference, and existing tool and exec owners enforce effects. flowchart TD
A[Plugin helper request] --> B[Gateway plugin adapter]
B --> C[Source turn and requester]
C --> D[Session policy admission]
D --> E[Existing fork runner]
E --> F[Tool execution gate]
F --> G[Filesystem and exec owners]
E --> H[Plugin settlement]
Technical reviewBest possible solution: Keep the existing-owner implementation and reword the type comment to clear the ratchet without expanding its baseline. Do we have a high-confidence way to reproduce the issue? Current-main source rejects these requested core tools through plugin ownership validation, and the introduced comment independently matches the failing CI scanner; no target code was executed. Is this the best way to solve the issue? The adapter, existing fork execution allowlist and existing noninteractive exec policy form a focused implementation; the shared test fixture serves both suites and adds no production owner. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 46982ac40764. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +25, Tests +160, Docs +12. Total +197 across 9 files. Added test files: 2. 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. Review metrics
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 17, 2026, 9:45 AM ET / 14:45 UTC. |
The catalog marks the ids plugins build (pluginBuilt). A declared catalog id is accepted only when marked, so core-built ids without a factory family (sessions_create, skills_search, skills_read) and future core tools are refused.
|
Landed in 38a0e8d.
|
… session's policy (openclaw#200636) ## What Problem This Solves A plugin can fork a chat with `runForkedTurn` and reuse its prompt cache, but the fork could only run tools the plugin registered itself. A fork that needs to look at the project (read a file, list a folder, run `rg`) had no way to do it: `read`, `ls` and `exec` are core tools, and `runForkedTurn` refused every core tool. This blocks porting pi-better's `/better`, whose helper reads the code before rewriting a prompt. The same check had a hole the other way: a plugin could list a core tool id such as `exec` or `write` in its manifest's `contracts.tools`, register a tool by that name, and get it accepted. That grant widens the chat's tool profile, and at run time the name resolves to the core tool. ## User Impact - A plugin fork may run `read`, `ls` and `exec` when the chat's own tool policy already allows them. They are never added to that policy: a chat on the `messaging` profile still refuses them. - `exec` in a fork runs only on the owner's turns, and a fork never asks for exec approval: a command the agent's exec approvals would ask about is denied, and no approval request is created. Allowlist entries ("Always allow") and full-permission exec apply as for the chat's own turns. - `through` is optional: without it the fork reads through the chat's latest message, as `forkSession` already does. - A manifest may claim a core catalog id only when the catalog marks it plugin-built (`browser`, `canvas`, `memory_search`, `memory_get`, `skill_workshop`, `code_execution`, `x_search`). ## Why This Change Was Made - **One path, no new policy.** `read`, `ls` and `exec` passed in `tools` skip the plugin grant and go straight to the fork's existing run-time allow list (`toolExecutionAllow`), after the existing `prepareSessionFork` policy check. Every chat tool stays listed in the request, so the provider serves the cached prefix; other calls still return "not available in this background run". - **Owner-only exec.** `exec` is not on `GATEWAY_OWNER_ONLY_CORE_TOOLS`, so `runSessionFork` keeps it out of the allow list unless the anchored turn's requester is the owner. - **No approval cards from a hidden run.** Tool assembly sets the existing `nonInteractiveApproval` rule (already used by swarm collectors and worker placement) for session-fork runs. YOLO (`security=full`, `ask=off`) never reaches approval; allowlist entries are the agent's and match on the same workspace. An agent with `askFallback: full` or `allowlist` is still denied in a fork rather than run unattended. - **Loophole.** The catalog now records which ids a plugin builds (`pluginBuilt`, on the 7 ids bundled plugins declare), and `resolvePluginSubagentToolsAlsoAllow` accepts a declared catalog id only when it is marked. This fails closed: every core-built id is refused, including `sessions_create`, `skills_search` and `skills_read`, which have no factory family, and any core tool added later without the mark. A contract test pins the marked set to the ids bundled plugin manifests declare. - `process` is never offered to a fork. The forked-turn e2e was over the file line cap, so its Gateway fixture moved to `gateway-plugin-forked-turn.test-support.ts` and the new case has its own file. ## Evidence **Red on `main`, green here.** New case `gateway-plugin-forked-turn-session-tools.e2e.test.ts`. Run on `main` with every assertion soft, each case fails for its own reason: the owner fork with `read`/`ls`/`exec` is refused before running; a fork without `through` fails; non-owner `exec` never runs; the unmatched `exec` never reaches `approval_required`; the plugin claiming `write` is accepted (`ok: true`); the plugin claiming `exec` on a `messaging` chat settles instead of being refused and makes 2 extra model calls. On this branch: `read` returns the file, `write` returns the refusal as a tool result and creates no file, owner `exec` runs, non-owner `exec` is refused, the unmatched `exec` under `allowlist`/`on-miss` returns `approval_required` with `exec.approval.list` empty, both claims are refused. **Unchanged suites:** `gateway-plugin-forked-turn.e2e` (7), `agent-tools.prefix-stability`, Skill Workshop (16 files), `session-fork-run`, session model-context limits, `server-plugins`, `agent-tools.runtime-plugin-tool-grant`, fork transport. **Live, real providers** (source Gateway, recording proxy; pi-better's `/better` ported as a plugin that forks with `read`, `ls`, `exec`). Per provider: turn 1 with the plugin disabled, turn 2 enabled, `/better`, turn 3 while the helper works, turn 4 disabled again. | | Anthropic `claude-sonnet-5-5` | OpenAI `gpt-5.6-luna` | |---|---|---| | Parent requests across plugin off → on → off: same system / tools / cache key, history only extends | yes (5 requests) | yes (6 requests) | | Helper request 1: same system / tools / cache key as the parent's last request, history prefix kept | yes, 7 / 7 | yes, 12 / 12 | | Helper request 1: cache read / input | 19,176 / 20,222 (94.8%) | 11,599 / 12,224 (94.9%) | | The chat's own turn 3, from the same cache: cache read / input | 19,176 / 19,773 (97.0%) | 11,599 / 11,886 (97.6%) | | Helper requests 2–4: cache read / input | 97.3–98.9% | 98.6–99.5% | | Tools the helper ran | `ls`, `exec` | `ls`, `read` | | Turn 3 started and finished while the helper was running | yes | yes | The helper's first request reads exactly as many cached tokens as the chat's own next turn: everything turn 2's request cached. The uncached part is the chat's last reply (a response, so no request had cached it yet), the per-turn runtime context, and pi-better's ~2 KB helper task, about 1,040 tokens on Anthropic. Only the helper task is new because of the fork. On this ~19k-token chat that is 5%; on a chat with 60k–150k tokens of history the same suffix is 1–2%. **SDK impact.** `runForkedTurn` gains no field; `through` becomes optional and `tools` accepts `read`, `ls` and `exec`. `plugin-sdk-impact` (ClawHub, 2,663 eligible releases: 2,239 complete, 422 partial, 2 failed; bundled source at `main` `eca93934b5a6`): `runtime.subagent.runForkedTurn` has 0 public consumers and 1 bundled (Skill Workshop, own tool only, unchanged). `manifest.contracts.tools` declaring `exec`, `read`, `ls`, `write`, `edit`, `process` or `apply_patch`: 0 public, 0 bundled for each, so the stricter claim rule breaks no observed plugin. Coverage is incomplete, so this is not proof of no use. Advisor (`forkSession`) is unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
… session's policy (#200636) ## What Problem This Solves A plugin can fork a chat with `runForkedTurn` and reuse its prompt cache, but the fork could only run tools the plugin registered itself. A fork that needs to look at the project (read a file, list a folder, run `rg`) had no way to do it: `read`, `ls` and `exec` are core tools, and `runForkedTurn` refused every core tool. This blocks porting pi-better's `/better`, whose helper reads the code before rewriting a prompt. The same check had a hole the other way: a plugin could list a core tool id such as `exec` or `write` in its manifest's `contracts.tools`, register a tool by that name, and get it accepted. That grant widens the chat's tool profile, and at run time the name resolves to the core tool. ## User Impact - A plugin fork may run `read`, `ls` and `exec` when the chat's own tool policy already allows them. They are never added to that policy: a chat on the `messaging` profile still refuses them. - `exec` in a fork runs only on the owner's turns, and a fork never asks for exec approval: a command the agent's exec approvals would ask about is denied, and no approval request is created. Allowlist entries ("Always allow") and full-permission exec apply as for the chat's own turns. - `through` is optional: without it the fork reads through the chat's latest message, as `forkSession` already does. - A manifest may claim a core catalog id only when the catalog marks it plugin-built (`browser`, `canvas`, `memory_search`, `memory_get`, `skill_workshop`, `code_execution`, `x_search`). ## Why This Change Was Made - **One path, no new policy.** `read`, `ls` and `exec` passed in `tools` skip the plugin grant and go straight to the fork's existing run-time allow list (`toolExecutionAllow`), after the existing `prepareSessionFork` policy check. Every chat tool stays listed in the request, so the provider serves the cached prefix; other calls still return "not available in this background run". - **Owner-only exec.** `exec` is not on `GATEWAY_OWNER_ONLY_CORE_TOOLS`, so `runSessionFork` keeps it out of the allow list unless the anchored turn's requester is the owner. - **No approval cards from a hidden run.** Tool assembly sets the existing `nonInteractiveApproval` rule (already used by swarm collectors and worker placement) for session-fork runs. YOLO (`security=full`, `ask=off`) never reaches approval; allowlist entries are the agent's and match on the same workspace. An agent with `askFallback: full` or `allowlist` is still denied in a fork rather than run unattended. - **Loophole.** The catalog now records which ids a plugin builds (`pluginBuilt`, on the 7 ids bundled plugins declare), and `resolvePluginSubagentToolsAlsoAllow` accepts a declared catalog id only when it is marked. This fails closed: every core-built id is refused, including `sessions_create`, `skills_search` and `skills_read`, which have no factory family, and any core tool added later without the mark. A contract test pins the marked set to the ids bundled plugin manifests declare. - `process` is never offered to a fork. The forked-turn e2e was over the file line cap, so its Gateway fixture moved to `gateway-plugin-forked-turn.test-support.ts` and the new case has its own file. ## Evidence **Red on `main`, green here.** New case `gateway-plugin-forked-turn-session-tools.e2e.test.ts`. Run on `main` with every assertion soft, each case fails for its own reason: the owner fork with `read`/`ls`/`exec` is refused before running; a fork without `through` fails; non-owner `exec` never runs; the unmatched `exec` never reaches `approval_required`; the plugin claiming `write` is accepted (`ok: true`); the plugin claiming `exec` on a `messaging` chat settles instead of being refused and makes 2 extra model calls. On this branch: `read` returns the file, `write` returns the refusal as a tool result and creates no file, owner `exec` runs, non-owner `exec` is refused, the unmatched `exec` under `allowlist`/`on-miss` returns `approval_required` with `exec.approval.list` empty, both claims are refused. **Unchanged suites:** `gateway-plugin-forked-turn.e2e` (7), `agent-tools.prefix-stability`, Skill Workshop (16 files), `session-fork-run`, session model-context limits, `server-plugins`, `agent-tools.runtime-plugin-tool-grant`, fork transport. **Live, real providers** (source Gateway, recording proxy; pi-better's `/better` ported as a plugin that forks with `read`, `ls`, `exec`). Per provider: turn 1 with the plugin disabled, turn 2 enabled, `/better`, turn 3 while the helper works, turn 4 disabled again. | | Anthropic `claude-sonnet-5-5` | OpenAI `gpt-5.6-luna` | |---|---|---| | Parent requests across plugin off → on → off: same system / tools / cache key, history only extends | yes (5 requests) | yes (6 requests) | | Helper request 1: same system / tools / cache key as the parent's last request, history prefix kept | yes, 7 / 7 | yes, 12 / 12 | | Helper request 1: cache read / input | 19,176 / 20,222 (94.8%) | 11,599 / 12,224 (94.9%) | | The chat's own turn 3, from the same cache: cache read / input | 19,176 / 19,773 (97.0%) | 11,599 / 11,886 (97.6%) | | Helper requests 2–4: cache read / input | 97.3–98.9% | 98.6–99.5% | | Tools the helper ran | `ls`, `exec` | `ls`, `read` | | Turn 3 started and finished while the helper was running | yes | yes | The helper's first request reads exactly as many cached tokens as the chat's own next turn: everything turn 2's request cached. The uncached part is the chat's last reply (a response, so no request had cached it yet), the per-turn runtime context, and pi-better's ~2 KB helper task, about 1,040 tokens on Anthropic. Only the helper task is new because of the fork. On this ~19k-token chat that is 5%; on a chat with 60k–150k tokens of history the same suffix is 1–2%. **SDK impact.** `runForkedTurn` gains no field; `through` becomes optional and `tools` accepts `read`, `ls` and `exec`. `plugin-sdk-impact` (ClawHub, 2,663 eligible releases: 2,239 complete, 422 partial, 2 failed; bundled source at `main` `7b0a97a4c96e`): `runtime.subagent.runForkedTurn` has 0 public consumers and 1 bundled (Skill Workshop, own tool only, unchanged). `manifest.contracts.tools` declaring `exec`, `read`, `ls`, `write`, `edit`, `process` or `apply_patch`: 0 public, 0 bundled for each, so the stricter claim rule breaks no observed plugin. Coverage is incomplete, so this is not proof of no use. Advisor (`forkSession`) is unchanged. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 38a0e8d) Co-authored-by: RomneyDa <[email protected]>
…#204411) Closes #204405. Companion plugin change: [Better Prompt #1](obviyus/openclaw-better-prompt#1). ## What Problem This Solves A person with `operator.sessions.write` but no `operator.write` gets "Ask an admin to grant write access" when a plugin runs a helper (`runForkedTurn`) on their own chat. The plugin's Gateway method is admitted for that session, but the fork was then admitted again as a new, sessionless `agent` launch, which needs general write access. ## Fix - **One admission path.** When a plugin method that declares `sessionAccess` calls `runForkedTurn`, the fork runs as a run of the session that request admitted: same `sessionKey` and agent required, the session resource's `retainSession` lifetime fences resets and replacements, and the `agent` admission goes through the existing own-session run check (`bindInProcessSessionRun`). This holds for every caller, whatever other scopes they hold. Calls without `sessionAccess` keep the sessionless path. A session key named by a plugin is never a grant by itself. - **One tool-eligibility owner.** The owner-only `exec` rule from #200636 moves from the run's execution allow list into `prepareSessionFork`, the admission check that already refuses denied tools before any model call. `exec` is admitted only when the anchored turn came from the owner and, when the fork came through a `sessionAccess` method with a signed-in caller, only when that caller sent the turn. Otherwise a request with `exec` returns `{ status: "refused", reason: "tool_policy" }`; `read` and `ls` stay under the session's own policy. No channel-specific checks. ## User Impact - A session writer can run a plugin helper on their own chat. Forks there may `read` and `ls`; a request with `exec` is refused unless that person is the owner and sent the turn. - Full writers through a `sessionAccess` method get the same fork as through any other method. - Behavior change for plugin authors: a fork requesting `exec` on a turn that did not come from the owner used to run with `exec` unavailable inside the run; it is now refused before any model call, so the plugin sees the refusal and can retry with `read`/`ls`. `runForkedTurn` gains no field. Docs: `docs/plugins/sdk-runtime.md`. - No config, schema, protocol or dependency change. ## Evidence **Head E2E, real model (2026-11-24).** Scratch source Gateway on a random port with isolated state, trusted-proxy sign-in over TLS, a WebChat client with only `operator.sessions.write`, and [Qwen3-4B-Instruct-2507 Q4_K_M](https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/tree/a06e946bb6b655725eafa393f4a9745d460374c9) on llama.cpp. A scratch plugin exposes a `sessionAccess` method and a plain `operator.write` method, both calling `runForkedTurn`; the workspace file holds a random reference that appears nowhere else. ```text connect: [email protected], scopes [operator.sessions.write] sessions.create → own chat; chat.send → real model turn, agent_end observed plain RPC (operator.write) → denied: missing scope: operator.write sessionAccess RPC, tools=[exec] → refused: tool_policy (no model call) sessionAccess RPC, tools=[read] → settled; after_tool_call read {path: notes.txt}, no error fork reply "PINE-73878" == file-only reference: true checks: broadDenied, execRefused, readSettled, readToolRan, markerReturned all true; exit 0 ``` **Base side** (recorded at reproduction, before this takeover): on the unpatched base the session writer's fork failed after the outer plugin RPC was admitted. **Regression tests** (`gateway-plugin-forked-turn-session-tools.e2e.test.ts`, real Gateway, scripted model): session writer own chat → `read` settles, `exec` refused, plain `operator.write` RPC denied; full writer through a `sessionAccess` method → owner `exec` runs as through the plain method; signed-in admin → `exec` runs on their own WebChat turn, refused through `sessionAccess` on another owner's Telegram turn, while the plain method still runs it there; non-owner turn → `[read, ls, exec]` refused with no model call, `[read, ls]` settles. 3/3 pass. `pnpm check:changed` green; importer tests of every changed source pass. **Size.** Production code +65/−19 against the merge base. The growth is the session binding: `runPluginForkedTurn` checks the admitted target, retains the session lifetime and passes the bound run (+23 net), and `prepareInProcessAgentExecution` admits it through the own-session path (+7 net). The `exec` rule moves into `prepareSessionFork` (+8 net); the rest is scope/type plumbing and doc comments. The earlier revision's scope sniffing, `read`/`ls` allowlist, WebChat requester check and `requiredForkProfileId` are gone. Reported by @etzelm in [the downstream issue](obviyus/openclaw-better-prompt#1). ## Worked on by - @etzelm Co-authored-by: etzelm <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…#204411) Closes #204405. Companion plugin change: [Better Prompt #1](obviyus/openclaw-better-prompt#1). A person with `operator.sessions.write` but no `operator.write` gets "Ask an admin to grant write access" when a plugin runs a helper (`runForkedTurn`) on their own chat. The plugin's Gateway method is admitted for that session, but the fork was then admitted again as a new, sessionless `agent` launch, which needs general write access. - **One admission path.** When a plugin method that declares `sessionAccess` calls `runForkedTurn`, the fork runs as a run of the session that request admitted: same `sessionKey` and agent required, the session resource's `retainSession` lifetime fences resets and replacements, and the `agent` admission goes through the existing own-session run check (`bindInProcessSessionRun`). This holds for every caller, whatever other scopes they hold. Calls without `sessionAccess` keep the sessionless path. A session key named by a plugin is never a grant by itself. - **One tool-eligibility owner.** The owner-only `exec` rule from #200636 moves from the run's execution allow list into `prepareSessionFork`, the admission check that already refuses denied tools before any model call. `exec` is admitted only when the anchored turn came from the owner and, when the fork came through a `sessionAccess` method with a signed-in caller, only when that caller sent the turn. Otherwise a request with `exec` returns `{ status: "refused", reason: "tool_policy" }`; `read` and `ls` stay under the session's own policy. No channel-specific checks. - A session writer can run a plugin helper on their own chat. Forks there may `read` and `ls`; a request with `exec` is refused unless that person is the owner and sent the turn. - Full writers through a `sessionAccess` method get the same fork as through any other method. - Behavior change for plugin authors: a fork requesting `exec` on a turn that did not come from the owner used to run with `exec` unavailable inside the run; it is now refused before any model call, so the plugin sees the refusal and can retry with `read`/`ls`. `runForkedTurn` gains no field. Docs: `docs/plugins/sdk-runtime.md`. - No config, schema, protocol or dependency change. **Head E2E, real model (2026-11-24).** Scratch source Gateway on a random port with isolated state, trusted-proxy sign-in over TLS, a WebChat client with only `operator.sessions.write`, and [Qwen3-4B-Instruct-2507 Q4_K_M](https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/tree/a06e946bb6b655725eafa393f4a9745d460374c9) on llama.cpp. A scratch plugin exposes a `sessionAccess` method and a plain `operator.write` method, both calling `runForkedTurn`; the workspace file holds a random reference that appears nowhere else. ```text connect: [email protected], scopes [operator.sessions.write] sessions.create → own chat; chat.send → real model turn, agent_end observed plain RPC (operator.write) → denied: missing scope: operator.write sessionAccess RPC, tools=[exec] → refused: tool_policy (no model call) sessionAccess RPC, tools=[read] → settled; after_tool_call read {path: notes.txt}, no error fork reply "PINE-73878" == file-only reference: true checks: broadDenied, execRefused, readSettled, readToolRan, markerReturned all true; exit 0 ``` **Base side** (recorded at reproduction, before this takeover): on the unpatched base the session writer's fork failed after the outer plugin RPC was admitted. **Regression tests** (`gateway-plugin-forked-turn-session-tools.e2e.test.ts`, real Gateway, scripted model): session writer own chat → `read` settles, `exec` refused, plain `operator.write` RPC denied; full writer through a `sessionAccess` method → owner `exec` runs as through the plain method; signed-in admin → `exec` runs on their own WebChat turn, refused through `sessionAccess` on another owner's Telegram turn, while the plain method still runs it there; non-owner turn → `[read, ls, exec]` refused with no model call, `[read, ls]` settles. 3/3 pass. `pnpm check:changed` green; importer tests of every changed source pass. **Size.** Production code +65/−19 against the merge base. The growth is the session binding: `runPluginForkedTurn` checks the admitted target, retains the session lifetime and passes the bound run (+23 net), and `prepareInProcessAgentExecution` admits it through the own-session path (+7 net). The `exec` rule moves into `prepareSessionFork` (+8 net); the rest is scope/type plumbing and doc comments. The earlier revision's scope sniffing, `read`/`ls` allowlist, WebChat requester check and `requiredForkProfileId` are gone. Reported by @etzelm in [the downstream issue](obviyus/openclaw-better-prompt#1). - @etzelm Co-authored-by: etzelm <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 56f8670) Release adaptation: Carry the admitted session resource through the existing release plugin runtime scope wrapper. No request-authority SDK backport is required. Companion audit reported no later same-path edits; the turn-grant series and changelog/corpus mentions do not supply a fork dependency. Co-authored-by: RomneyDa <[email protected]>
…openclaw#204411) Closes openclaw#204405. Companion plugin change: [Better Prompt #1](obviyus/openclaw-better-prompt#1). ## What Problem This Solves A person with `operator.sessions.write` but no `operator.write` gets "Ask an admin to grant write access" when a plugin runs a helper (`runForkedTurn`) on their own chat. The plugin's Gateway method is admitted for that session, but the fork was then admitted again as a new, sessionless `agent` launch, which needs general write access. ## Fix - **One admission path.** When a plugin method that declares `sessionAccess` calls `runForkedTurn`, the fork runs as a run of the session that request admitted: same `sessionKey` and agent required, the session resource's `retainSession` lifetime fences resets and replacements, and the `agent` admission goes through the existing own-session run check (`bindInProcessSessionRun`). This holds for every caller, whatever other scopes they hold. Calls without `sessionAccess` keep the sessionless path. A session key named by a plugin is never a grant by itself. - **One tool-eligibility owner.** The owner-only `exec` rule from openclaw#200636 moves from the run's execution allow list into `prepareSessionFork`, the admission check that already refuses denied tools before any model call. `exec` is admitted only when the anchored turn came from the owner and, when the fork came through a `sessionAccess` method with a signed-in caller, only when that caller sent the turn. Otherwise a request with `exec` returns `{ status: "refused", reason: "tool_policy" }`; `read` and `ls` stay under the session's own policy. No channel-specific checks. ## User Impact - A session writer can run a plugin helper on their own chat. Forks there may `read` and `ls`; a request with `exec` is refused unless that person is the owner and sent the turn. - Full writers through a `sessionAccess` method get the same fork as through any other method. - Behavior change for plugin authors: a fork requesting `exec` on a turn that did not come from the owner used to run with `exec` unavailable inside the run; it is now refused before any model call, so the plugin sees the refusal and can retry with `read`/`ls`. `runForkedTurn` gains no field. Docs: `docs/plugins/sdk-runtime.md`. - No config, schema, protocol or dependency change. ## Evidence **Head E2E, real model (2026-11-24).** Scratch source Gateway on a random port with isolated state, trusted-proxy sign-in over TLS, a WebChat client with only `operator.sessions.write`, and [Qwen3-4B-Instruct-2507 Q4_K_M](https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/tree/a06e946bb6b655725eafa393f4a9745d460374c9) on llama.cpp. A scratch plugin exposes a `sessionAccess` method and a plain `operator.write` method, both calling `runForkedTurn`; the workspace file holds a random reference that appears nowhere else. ```text connect: [email protected], scopes [operator.sessions.write] sessions.create → own chat; chat.send → real model turn, agent_end observed plain RPC (operator.write) → denied: missing scope: operator.write sessionAccess RPC, tools=[exec] → refused: tool_policy (no model call) sessionAccess RPC, tools=[read] → settled; after_tool_call read {path: notes.txt}, no error fork reply "PINE-73878" == file-only reference: true checks: broadDenied, execRefused, readSettled, readToolRan, markerReturned all true; exit 0 ``` **Base side** (recorded at reproduction, before this takeover): on the unpatched base the session writer's fork failed after the outer plugin RPC was admitted. **Regression tests** (`gateway-plugin-forked-turn-session-tools.e2e.test.ts`, real Gateway, scripted model): session writer own chat → `read` settles, `exec` refused, plain `operator.write` RPC denied; full writer through a `sessionAccess` method → owner `exec` runs as through the plain method; signed-in admin → `exec` runs on their own WebChat turn, refused through `sessionAccess` on another owner's Telegram turn, while the plain method still runs it there; non-owner turn → `[read, ls, exec]` refused with no model call, `[read, ls]` settles. 3/3 pass. `pnpm check:changed` green; importer tests of every changed source pass. **Size.** Production code +65/−19 against the merge base. The growth is the session binding: `runPluginForkedTurn` checks the admitted target, retains the session lifetime and passes the bound run (+23 net), and `prepareInProcessAgentExecution` admits it through the own-session path (+7 net). The `exec` rule moves into `prepareSessionFork` (+8 net); the rest is scope/type plumbing and doc comments. The earlier revision's scope sniffing, `read`/`ls` allowlist, WebChat requester check and `requiredForkProfileId` are gone. Reported by @etzelm in [the downstream issue](obviyus/openclaw-better-prompt#1). ## Worked on by - @etzelm Co-authored-by: etzelm <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>




What Problem This Solves
A plugin can fork a chat with
runForkedTurnand reuse its prompt cache, but the fork could only run tools the plugin registered itself. A fork that needs to look at the project (read a file, list a folder, runrg) had no way to do it:read,lsandexecare core tools, andrunForkedTurnrefused every core tool. This blocks porting pi-better's/better, whose helper reads the code before rewriting a prompt.The same check had a hole the other way: a plugin could list a core tool id such as
execorwritein its manifest'scontracts.tools, register a tool by that name, and get it accepted. That grant widens the chat's tool profile, and at run time the name resolves to the core tool.User Impact
read,lsandexecwhen the chat's own tool policy already allows them. They are never added to that policy: a chat on themessagingprofile still refuses them.execin a fork runs only on the owner's turns, and a fork never asks for exec approval: a command the agent's exec approvals would ask about is denied, and no approval request is created. Allowlist entries ("Always allow") and full-permission exec apply as for the chat's own turns.throughis optional: without it the fork reads through the chat's latest message, asforkSessionalready does.browser,canvas,memory_search,memory_get,skill_workshop,code_execution,x_search).Why This Change Was Made
read,lsandexecpassed intoolsskip the plugin grant and go straight to the fork's existing run-time allow list (toolExecutionAllow), after the existingprepareSessionForkpolicy check. Every chat tool stays listed in the request, so the provider serves the cached prefix; other calls still return "not available in this background run".execis not onGATEWAY_OWNER_ONLY_CORE_TOOLS, sorunSessionForkkeeps it out of the allow list unless the anchored turn's requester is the owner.nonInteractiveApprovalrule (already used by swarm collectors and worker placement) for session-fork runs. YOLO (security=full,ask=off) never reaches approval; allowlist entries are the agent's and match on the same workspace. An agent withaskFallback: fullorallowlistis still denied in a fork rather than run unattended.pluginBuilt, on the 7 ids bundled plugins declare), andresolvePluginSubagentToolsAlsoAllowaccepts a declared catalog id only when it is marked. This fails closed: every core-built id is refused, includingsessions_create,skills_searchandskills_read, which have no factory family, and any core tool added later without the mark. A contract test pins the marked set to the ids bundled plugin manifests declare.processis never offered to a fork.The forked-turn e2e was over the file line cap, so its Gateway fixture moved to
gateway-plugin-forked-turn.test-support.tsand the new case has its own file.Evidence
Red on
main, green here. New casegateway-plugin-forked-turn-session-tools.e2e.test.ts. Run onmainwith every assertion soft, each case fails for its own reason: the owner fork withread/ls/execis refused before running; a fork withoutthroughfails; non-ownerexecnever runs; the unmatchedexecnever reachesapproval_required; the plugin claimingwriteis accepted (ok: true); the plugin claimingexecon amessagingchat settles instead of being refused and makes 2 extra model calls. On this branch:readreturns the file,writereturns the refusal as a tool result and creates no file, ownerexecruns, non-ownerexecis refused, the unmatchedexecunderallowlist/on-missreturnsapproval_requiredwithexec.approval.listempty, both claims are refused.Unchanged suites:
gateway-plugin-forked-turn.e2e(7),agent-tools.prefix-stability, Skill Workshop (16 files),session-fork-run, session model-context limits,server-plugins,agent-tools.runtime-plugin-tool-grant, fork transport.Live, real providers (source Gateway, recording proxy; pi-better's
/betterported as a plugin that forks withread,ls,exec). Per provider: turn 1 with the plugin disabled, turn 2 enabled,/better, turn 3 while the helper works, turn 4 disabled again.claude-sonnet-5-5gpt-5.6-lunals,execls,readThe helper's first request reads exactly as many cached tokens as the chat's own next turn: everything turn 2's request cached. The uncached part is the chat's last reply (a response, so no request had cached it yet), the per-turn runtime context, and pi-better's ~2 KB helper task, about 1,040 tokens on Anthropic. Only the helper task is new because of the fork. On this ~19k-token chat that is 5%; on a chat with 60k–150k tokens of history the same suffix is 1–2%.
SDK impact.
runForkedTurngains no field;throughbecomes optional andtoolsacceptsread,lsandexec.plugin-sdk-impact(ClawHub, 2,663 eligible releases: 2,239 complete, 422 partial, 2 failed; bundled source atmain7b0a97a4c96e):runtime.subagent.runForkedTurnhas 0 public consumers and 1 bundled (Skill Workshop, own tool only, unchanged).manifest.contracts.toolsdeclaringexec,read,ls,write,edit,processorapply_patch: 0 public, 0 bundled for each, so the stricter claim rule breaks no observed plugin. Coverage is incomplete, so this is not proof of no use. Advisor (forkSession) is unchanged.