Repository navigation
fix: CLI and MCP tool completions skip plugin hooks - #155206
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 22, 2026, 4:53 AM ET / 08:53 UTC (Revision 3). ClawSweeper reviewWhat this changesRestores plugin completion notifications for CLI and Gateway MCP tools, with canonical names, approved arguments, duplicate suppression, and isolated result snapshots. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful fix for a source-confirmed gap on current main. Both earlier review findings are resolved, and the supplied runtime evidence exercises the changed production paths. Priority: P2 Review scores
Verification
How this fits togetherCLI backends and the Gateway MCP endpoint execute agent tool calls. Their completion handlers notify plugins that observe results, errors, and timing while preserving the tool consumer’s response. flowchart TD
A[Agent tool request] --> B[Policy and approval]
B --> C[CLI tool execution]
B --> D[Gateway MCP execution]
C --> E[Completion tracking]
D --> E
E --> F[Isolated plugin notification]
E --> G[Tool response and bookkeeping]
Decision needed
Why: The source review found no concrete security defect, but ClawSweeper cannot substitute for the explicitly required maintainer approval. Before merge
Agent review detailsSecurityNone. PR surfaceSource +88, Tests +273. Total +361 across 10 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep completion observation at the existing CLI and MCP execution owners, preserving approved arguments and consumer results through the shared isolation boundary. Do we have a high-confidence way to reproduce the issue? Yes: registering paired tool hooks and completing CLI or loopback MCP calls reaches current-main owners that omit the after hook. This review established the path from source; the supplied baseline run independently reports zero completion callbacks. Is this the best way to solve the issue? Yes: dispatching through the existing completion owners and shared hook helper repairs the missing contract without introducing another API or changing execution policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 65230df0304d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
✅ Maintainer security changes approvedA maintainer approved this revision with an explicit security approval comment.
A later push requires a fresh approval comment for an external contributor's PR. |
|
/allow-security-sensitive-change |
|
landpr-approve-unrelated-red |
|
Merged as ca97ceb. CLI and MCP tool calls now notify completion observers with canonical names and approved arguments, without double-counting Gateway-owned results or letting observers alter caller responses. Verified through a real Gateway with a loaded plugin and synthetic CLI backend, including denied/error calls, wrong-token rejection, duplicate events, and a mutating/throwing observer. Focused regressions and affected type checks passed. Thanks @iuiu-py for the contribution. |
* commit '80b9608a25e191a17e1466d750c2f76a38a38507': fix(tooling): declare tsx CLI shim exports test(gateway): reuse session PR access state fixtures (#155626) test(heartbeat): await wake registration before advancing coalescing time refactor(status): share plugin health section assembly (#155390) fix: CLI and MCP tool completions skip plugin hooks (#155206) fix(update): preserve failures and retain running worker code (#153764) fix(sqlite): drain idle coordinators at lifecycle teardown fix(test): prepare SQLite compile-cache probes before launch fix(test): preserve owned compiler caches in Vitest workers fix(ios): assistant files are not downloadable in chat (#155195) fix(heartbeat): avoid timeouts for busy scheduled polls (#148333) test(gateway): hold SSH approval until pending assertions finish test(update): cover launcher permission rollback on Linux (#155615) fix(edit): avoid duplicate replacements from legacy arguments (#155513) feat(browser): support Lightpanda connection-scoped CDP replies (#154342) improve(ci): speed up compatible Control UI tests with Bun (#154585) test(gateway): prepare remaining approval fixtures before requests (#155589) fix(doctor): exclude retained agents from automatic session import
Closes openclaw#155081 ## What Problem This Solves Fixes missing `after_tool_call` notifications for CLI-backed and Gateway loopback MCP tool calls, including plugins with canonical tool-name matchers. ## User Impact Plugins receive completion outcomes with canonical names, final arguments for approved calls, results or errors, and timing when a start was observed. Gateway-owned MCP calls are not counted again when the CLI echoes their results. Permissions and tool responses stay unchanged; observers remain best-effort and nonblocking. ## Why This Change Was Made Dispatch completion hooks from the existing CLI and Gateway execution owners through the shared hook runner. Native completion names use the same normalization as before hooks (`Bash` → `exec`, `WebFetch` → `web_fetch`), and the permission owner records final approved arguments for the matching run and call. Reuse existing call records for duplicate-terminal handling, preserve named result-only events and run identity, and leave loopback MCP completion with the Gateway. The shared completion helper gives observers detached result snapshots. If a result cannot be isolated, it warns and skips that best-effort notification without changing the tool result or completion bookkeeping. Before-message-write mutation behavior is unchanged. No new hook API, configuration, schema, or retention policy is introduced. ## Evidence A normal built Gateway loaded a matcher-scoped observer plugin and a documented synthetic CLI backend. Its child executed approved shell commands and an HTTP fetch, and used the Gateway's generated authenticated MCP grant to execute a file-writing plugin tool. | Observed callbacks | Baseline `6ca2a41` before / after | Candidate `ab3cef6` before / after | | --- | ---: | ---: | | Native `exec` | 3 / 0 | 3 / 3 | | Native `web_fetch` | 1 / 0 | 1 / 1 | | Gateway MCP tool | 3 / 0 | 3 / 3 | - The child executed rewritten command/URL inputs; completion observers received the approved arguments, including rewritten MCP arguments. - Seven distinct completion IDs were observed. Repeated CLI terminal records did not add a second Gateway MCP completion. - Denied actions produced no artifact; real shell exit 7 and MCP execution errors remained errors. A wrong MCP token returned HTTP 401 without executing the tool. - An observer mutated MCP result content/details and then threw. The actual HTTP/tool consumer still received the original result. Owned Gateway/child processes settled and listening ports closed. - The existing loaded-plugin HTTP regression failed all three plain, opaque and shared-memory cases on the previous head. It now verifies unchanged HTTP responses and internal completion results before and after registry replacement. Opaque/shared-memory results produce a warning and no observer notification; authoritative results remain mutable by their owner. - An earlier candidate exposed stale native arguments in completion events despite executing rewritten arguments. That retained failure was fixed at the permission producer, and the strict runtime oracle was preserved. The final agent turn took 819 ms; the complete isolated proof process took 13.8 s. This is synthetic-backend proof of OpenClaw's registered CLI/MCP paths, **not** a native Claude/Gemini/Codex integration run. No paid model or live provider credentials were used. The final isolation correction passed the three loaded-plugin HTTP cases (6.06 s test time / 32.23 s command wall time), the 41-test CLI consumer suite (24.14 s), and the affected `gateway-root` test-type project (11.05 s). Scoped type-aware lint, formatting, whitespace and line-cap checks passed. The exact `ab3cef6` build passed in 341.15 s. Earlier focused repair checks covered 232 distinct tests across CLI completion, native execution/permission, tool naming and MCP owners. A hosted test-type failure in a true-only fixture marker was corrected without widening the production type; its affected `agents-other` project passed in 10.05 s. Those receipts remain separate from the final correction checks above. Co-authored-by: wangzifei <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #155081
What Problem This Solves
Fixes missing
after_tool_callnotifications for CLI-backed and Gateway loopback MCP tool calls, including plugins with canonical tool-name matchers.User Impact
Plugins receive completion outcomes with canonical names, final arguments for approved calls, results or errors, and timing when a start was observed. Gateway-owned MCP calls are not counted again when the CLI echoes their results. Permissions and tool responses stay unchanged; observers remain best-effort and nonblocking.
Why This Change Was Made
Dispatch completion hooks from the existing CLI and Gateway execution owners through the shared hook runner. Native completion names use the same normalization as before hooks (
Bash→exec,WebFetch→web_fetch), and the permission owner records final approved arguments for the matching run and call.Reuse existing call records for duplicate-terminal handling, preserve named result-only events and run identity, and leave loopback MCP completion with the Gateway. The shared completion helper gives observers detached result snapshots. If a result cannot be isolated, it warns and skips that best-effort notification without changing the tool result or completion bookkeeping. Before-message-write mutation behavior is unchanged. No new hook API, configuration, schema, or retention policy is introduced.
Evidence
A normal built Gateway loaded a matcher-scoped observer plugin and a documented synthetic CLI backend. Its child executed approved shell commands and an HTTP fetch, and used the Gateway's generated authenticated MCP grant to execute a file-writing plugin tool.
538cb1ebefore / afterab3cef6before / afterexecweb_fetchThe final agent turn took 819 ms; the complete isolated proof process took 13.8 s. This is synthetic-backend proof of OpenClaw's registered CLI/MCP paths, not a native Claude/Gemini/Codex integration run. No paid model or live provider credentials were used.
The final isolation correction passed the three loaded-plugin HTTP cases (6.06 s test time / 32.23 s command wall time), the 41-test CLI consumer suite (24.14 s), and the affected
gateway-roottest-type project (11.05 s). Scoped type-aware lint, formatting, whitespace and line-cap checks passed. The exactab3cef6build passed in 341.15 s.Earlier focused repair checks covered 232 distinct tests across CLI completion, native execution/permission, tool naming and MCP owners. A hosted test-type failure in a true-only fixture marker was corrected without widening the production type; its affected
agents-otherproject passed in 10.05 s. Those receipts remain separate from the final correction checks above.