Skip to content

feat(plugins): let plugin forks read, ls and run owner exec under the session's policy - #200636

Merged
obviyus merged 3 commits into
mainfrom
fork-core-tools
Nov 17, 2026
Merged

obviyus merged 3 commits into
mainfrom
fork-core-tools

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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

clawsweeper Bot commented Nov 17, 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.

@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Control UI run of the ported /better plugin on this branch (dist build, real Anthropic): the Better button, progress from the fork's tool events, Cancel leaving the draft untouched, and the improved prompt placed above the typed draft with the chat still at 4 messages (nothing sent).

Better button with a typed draft

Progress rows from the fork tool events

Cancel leaves the draft and sends nothing

Improved prompt above the typed draft, not sent

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling plugin: file-transfer size: XL labels Nov 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

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

  • Before: The fork rejects these core tools before calling the model.
  • After: The helper can inspect the project under session policy; commands requiring human approval are denied without creating an approval request.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, demonstrated behavior with a focused implementation; the introduced ratchet failure prevents readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied source-Gateway runs record real-provider fork tool execution and stable parent prefixes, supported by inspected Control UI screenshots of the ported helper and production-path policy/approval regression coverage.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: A background prompt helper cannot inspect project files through the supported fork API.
Reason: The maintainer-authored direction has a concrete plugin consumer and extends the existing owner without a new configuration surface.

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
Reviewed head: 2948a8c0f689855639be184b05b6b709044a829b

Before merge

  • Reword the comment that trips the session-identity ratchet (P2) - The reflow puts was replaced together on one source line. check-session-identity-ratchet.mts counts that literal phrase in comments, and this file has no baseline allowance, so the change introduces a ratchet violation. The exact-head baseline job reports session-identity failed (exit 1). Rephrase the explanation without changing its meaning or increasing the baseline.

Findings

  • [P2] Reword the comment that trips the session-identity ratchet — src/plugins/runtime/types.ts:73
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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:

  • [P2] Reword the comment that trips the session-identity ratchet — src/plugins/runtime/types.ts:73
    The reflow puts was replaced together on one source line. check-session-identity-ratchet.mts counts that literal phrase in comments, and this file has no baseline allowance, so the change introduces a ratchet violation. The exact-head baseline job reports session-identity failed (exit 1). Rephrase the explanation without changing its meaning or increasing the baseline.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Plugin fork tool ownership and optional anchor changes intended behavior with a stated reason (def6349: Expose hidden plugin-owned tool turns while preserving source requester policy and rejecting unrelated core tools.)
  • Cache-preserving fork execution keeps the original intent (2a7ca16: Reuse the parent's request prefix while gating execution separately and sharing one fork primitive.)
  • Plugin subagent grants changes intended behavior with a stated reason (08f4a19: Permit manifest-declared plugin-owned catalog tools such as Skill Workshop; this PR explains why core-built identities must remain excluded.)
  • Exec tool assembly keeps the original intent (625945b: The cold-start refactor carried existing assembly into this module; this PR reuses its noninteractive approval mechanism for hidden forks rather than adding another approval path.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm check:session-identity-ratchet --base 7b0adbb --no-merge-base
  • git diff --check

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit def6349 adds src/gateway/server-plugin-forked-turn.ts:38 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: def63496ca8f; files: src/gateway/server-plugin-forked-turn.ts)
  • Peter Steinberger: Raw commit 04d809b adds src/agents/session-fork-run.ts:94 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 04d809bceec0; files: src/agents/session-fork-run.ts)
  • Vincent Koc: Raw commit 625945b adds src/agents/agent-tools.assembly.ts:293 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 625945b7ae01; files: src/agents/agent-tools.assembly.ts)

PR surface

Source +25, Tests +160, Docs +12. Total +197 across 9 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 5 44 19 +25
Tests 3 656 496 +160
Docs 1 22 10 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 722 525 +197

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.

Review metrics

Metric Value Why it matters
Production versus tests Production +44/−19; tests and fixtures +656/−496 Most apparent test growth is a shared fixture extraction; the remaining additions exercise distinct tool-policy and approval boundaries.

Labels

Label changes:

  • add P2: Useful plugin SDK improvement with a narrow CI repair and no demonstrated urgent runtime regression.
  • add merge-risk: 🚨 compatibility: The public fork contract accepts additional core tools and an omitted anchor, while grant validation intentionally rejects core-factory impersonation; this direction is recorded in the maintainer-authored PR.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Useful plugin SDK improvement with a narrow CI repair and no demonstrated urgent runtime regression.
  • merge-risk: 🚨 compatibility: The public fork contract accepts additional core tools and an omitted anchor, while grant validation intentionally rejects core-factory impersonation; this direction is recorded in the maintainer-authored PR.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 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.
@obviyus
obviyus merged commit 38a0e8d into main Nov 17, 2026
130 checks passed
@obviyus
obviyus deleted the fork-core-tools branch November 17, 2026 19:00
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 38a0e8d.

  • Gap: a plugin fork could run only the plugin's own tools, so it could not read the project; and a manifest could claim a core tool id such as exec in contracts.tools, which widened the chat's tool profile.
  • Fix: runForkedTurn accepts read, ls and owner-only exec under the chat's own policy, never asks for exec approval, and defaults through to the latest message. The catalog marks plugin-built ids, and only those may be claimed.
  • Proof: new e2e red on main and green here; forked-turn, prefix-stability, Skill Workshop and catalog suites green; live Anthropic/OpenAI probe and a Control UI run of the ported /better plugin; local review of this exact head clean; CI green.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
… 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]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
… 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]>
obviyus added a commit that referenced this pull request Nov 24, 2026
…#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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 25, 2026
…#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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…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]>
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. P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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