Repository navigation
feat(plugins): allow per-turn tool narrowing in prompt hooks - #114151
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 3:05 PM ET / 19:05 UTC. ClawSweeper reviewWhat this changesAdds an optional Merge readinessThis PR remains necessary as the implementation candidate for the open per-turn tool-surface request. The supplied branch evidence shows a narrowing-only plugin contract, real embedded-runtime proof that the submitted provider tool list becomes empty, explicit Codex fail-closed behavior, and a maintainer acceptance; no concrete patch defect is evident from the available review material. Keep it open for normal merge handling while the exact-head checks finish. Priority: P2 Review scores
Verification
How this fits togetherPrompt hooks run after OpenClaw has assembled the host-approved prompt and tool surface. This change lets hooks further narrow that surface before an embedded or Copilot runtime submits the model request, while the Codex app-server adapter rejects a restriction it cannot represent in its per-turn upstream protocol. flowchart LR
A[Host tool policy] --> B[Prompt build hooks]
B --> C[Combined narrowing policy]
C --> D[Embedded model submission]
C --> E[Copilot model submission]
C --> F[Codex app-server adapter]
D --> G[Filtered tool schemas]
E --> G
F --> H[Fail-closed error when restrictive]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +372, Tests +470, Docs +8. Total +850 across 28 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the documented narrowing-only hook contract after the exact-head checks pass, preserving host-required tools and the explicit Codex rejection until upstream offers a safe per-turn tool override. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR implements a requested plugin capability rather than fixing a reported failure. The supplied real embedded-runtime capture nevertheless demonstrates the intended after-fix request path. Is this the best way to solve the issue? Yes, based on the supplied branch evidence and accepted maintainer direction: aggregate only narrowing restrictions in hooks, enforce them at submission boundaries that support them, and reject restrictions at the Codex boundary rather than silently widening the model-visible tool surface. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 6beaff450e6e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
5746b32 to
4c6da95
Compare
|
Updated the branch to The proof uses two real I also accepted and fixed a repository-autoreview finding: a mixed array such as One correction to the previous review: I could not reproduce the claimed prompt-mutation registry blocker. These exact checks return no matches at either the reviewed base or the current head: At the reviewed base, I also rechecked the documented native Codex app-server boundary against Codex commit @clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Maintainer decision: accepted.
I personally verified the upstream Codex boundary before accepting this:
That makes the documented Codex rejection accurate. Waiting for a future upstream per-turn tool API would unnecessarily block a useful safe capability in the runtimes that can enforce it today. The latest ClawSweeper review has no patch findings, sufficient live proof, and one optional move: confirm this contract and take the PR out of draft once exact-head checks are settled. Both conditions are now satisfied. |
|
Merged via squash.
|
* origin/main: (151 commits) feat(plugins): allow per-turn tool narrowing in prompt hooks (openclaw#114151) docs(hooks): mark pairing hook observation-only (openclaw#116055) docs(control-ui): document composer capability menu (openclaw#115858) fix(build): bound declaration memory use (openclaw#116021) fix: Slack replies recover after gateway startup replay (openclaw#115991) fix(azure-speech): keep valid voices from malformed catalogs (openclaw#115067) fix(agents): prevent model runtime startup timeout (openclaw#116039) fix(ui): explain unavailable MCP tool catalogs (openclaw#115994) fix(skills): run experience review outside released request roots (openclaw#116040) docs(security): add safe Gmail reader setup (openclaw#116041) chore: refresh browser gateway runtime (openclaw#116043) test: isolate gateway sequence lifecycle coverage docs: note gateway reconnect sequence fix test: cover gateway sequence reset on restart test: cover gateway sequence reset on reconnect fix: reset gateway event sequence on reconnect fix(codex): avoid transcript mirror snapshot churn (openclaw#115070) fix(test): stop cross-file state leaks in media suites (openclaw#116027) feat(hooks): add persistent hook session mode (openclaw#75918) fix(memory): return early for blank searches (openclaw#116034) ...
* origin/main: (39 commits) feat(apple): media renditions, Now Playing, video upload (#116051) feat(android): media renditions, MediaSession, video upload (#116037) feat(cli): run agent exec against the ambient config, composed in memory (#116038) fix #95351: [Feature]: Generic JSONL line-parsing hook for CliBackendPlugin (native tool-card support beyond claude-stream-json) (#95386) feat(plugins): allow per-turn tool narrowing in prompt hooks (#114151) docs(hooks): mark pairing hook observation-only (#116055) docs(control-ui): document composer capability menu (#115858) fix(build): bound declaration memory use (#116021) fix: Slack replies recover after gateway startup replay (#115991) fix(azure-speech): keep valid voices from malformed catalogs (#115067) fix(agents): prevent model runtime startup timeout (#116039) fix(ui): explain unavailable MCP tool catalogs (#115994) fix(skills): run experience review outside released request roots (#116040) docs(security): add safe Gmail reader setup (#116041) chore: refresh browser gateway runtime (#116043) test: isolate gateway sequence lifecycle coverage docs: note gateway reconnect sequence fix test: cover gateway sequence reset on restart test: cover gateway sequence reset on reconnect fix: reset gateway event sequence on reconnect ...
…w#114151) * feat(plugins): allow per-turn tool narrowing in prompt hooks * fix(hooks): keep prompt tool policy baseline internal * fix(test): track active tools in embedded session fixture * test(agents): preserve active tool fixture state --------- Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Plugins can already replace or trim prompt text in
before_prompt_build, but they cannot remove tool schemas from the model request for a zero-tool turn. A lean prompt can therefore still carry the full tool surface and its prefill cost.This adds optional
toolsAllowoutput tobefore_prompt_build.[]removes optional tools for that turn while preserving host-required tools; omission preserves the host-resolved tool surface.Closes #112466
Why This Change Was Made
The restriction is applied at the concrete model-submission boundary, after normal host, sandbox, channel, and runtime tool policy has resolved. This makes the hook narrowing-only: it cannot re-enable a tool already removed by the host.
Multiple hook restrictions retain true intersection semantics, including overlapping glob policies. Tool Search and code-mode catalogs are narrowed alongside visible schemas so hidden tools cannot be recovered through a control tool. Each prompt build derives from a preserved host baseline, allowing a later build to change or omit its restriction without inheriting stale catalog or active-tool state.
The embedded runner and Copilot harness apply the per-turn restriction. The native Codex app-server adapter rejects restrictive hook values because its
turn/startcontract has no dynamic-tool override; silently ignoring the restriction would widen the model-visible surface.User Impact
toolsAllow: []to remove optional tools while host-required tools remain available.toolsAllowremains backward compatible.Evidence
Real embedded runtime proof
Tested at
4c6da95712with two realnode openclaw.mjs agent --localturns. Both used the normal external-plugin loader and an OpenAI-compatible loopback provider that recorded the actual/v1/chat/completionsrequest body.The provider therefore saw the concrete submitted surface change from 37 tools to zero, while the model turn still completed successfully.
Automated validation
node scripts/build-all.mjspassed; all 146 public plugin SDK subpaths verified.Maintainer verification - July 29, 2026
Exact PR head:
6f55530bb2801139492fd2afeefe89430979b7f8Anchored to reviewed
origin/main:877fa6178ac6be0d7354e20ffbff02f93b307213. The signed anchor keeps the original contributor head4c6da95712bdeffbcf686c1a68b3ee3339806dd7as parent 1 and current main as parent 2.Verdict: best fix; no blocking findings. The rewrite keeps policy aggregation in the hook runner, enforcement at each runtime submission boundary, required host tools explicit, and Codex fail-closed where its upstream turn protocol cannot enforce dynamic tools.
Exact-head proof:
before_prompt_build: 2 passed, 118 skipped.before_prompt_build: 2 passed, 139 skipped.git diff --checkpassed.gpt-5.6-sol, score 0.86).Known proof gaps: Blacksmith Testbox is unavailable on this host because its CLI is not authenticated. Broader type lanes also hit unrelated workspace issues outside this diff: missing
weriftdeclarations, missing@openclaw/session-url-contract/parseresolution, and sparse-checkout omissions for UI core-test inputs.Docs:
docs/plugins/hooks.mdanddocs/concepts/agent-loop.mdnow describe optional-tool narrowing and Codex rejection behavior.State: ready for merge once exact-head GitHub checks settle.