Skip to content

fix: CLI and MCP tool completions skip plugin hooks - #155206

Merged
obviyus merged 6 commits into
openclaw:mainfrom
iuiu-py:fix/after-tool-call-cli-mcp-155081
Sep 22, 2026
Merged

obviyus merged 6 commits into
openclaw:mainfrom
iuiu-py:fix/after-tool-call-cli-mcp-155081

Conversation

@iuiu-py

@iuiu-py iuiu-py commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #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 538cb1e 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.

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M labels Sep 21, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 22, 2026, 4:53 AM ET / 08:53 UTC (Revision 3).

ClawSweeper review

What this changes

Restores 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
Reviewed head: ab3cef62554356652071b0374c5a14d31c3d4d87
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant production-boundary evidence and both prior findings resolved.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured before/after Gateway run exercises the registered CLI and authenticated MCP completion owners with real shell, HTTP, and file effects, reporting seven correct callbacks and preserved responses under observer failure. Native vendor integrations are outside that evidence; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured before/after Gateway run exercises the registered CLI and authenticated MCP completion owners with real shell, HTTP, and file effects, reporting seven correct callbacks and preserved responses under observer failure. Native vendor integrations are outside that evidence; no stored-data contract changes.
Evidence reviewed 8 items Reviewed change identity: Reviewed the pinned merge-base-to-head production and test changes. Checkout and original PR head are ab3cef6; endpoint drift was not attributed to the PR. The supplied test merge is stale and was not used to claim removal of current-main behavior.
Current main still needs the repair: Current-main CLI completion handling emits activity and performs bookkeeping without dispatching after_tool_call. The current-main MCP handler likewise runs before-tool policy and returns outcomes without the completion hook. No merged replacement is established by the supplied related-item context.
Earlier findings resolved: CLI completion names now use the same normalization as native before hooks. Compared with the previously reviewed revision, the shared completion helper now clones results through the existing isolation owner inside its guarded block. The loaded-plugin HTTP regression checks unchanged responses and internal results for plain, opaque, and shared-memory values across registry replacement.
Findings None None.
Security None None.

How this fits together

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

Decision needed

Question Recommendation
Can the current revision receive the repository-required security approval for its CLI tool-policy changes? Approve the reviewed revision: An eligible maintainer reviews the execution-policy changes and records the required security approval for this head.

Why: The source review found no concrete security defect, but ClawSweeper cannot substitute for the explicitly required maintainer approval.

Before merge

  • Complete next step (P2) - An eligible maintainer must review this revision’s tool-policy changes and post the required /allow-security-sensitive-change approval.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +88, Tests +273. Total +361 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 113 25 +88
Tests 5 389 116 +273
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 502 141 +361

Review metrics

None.

Technical review

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after Gateway run exercises the registered CLI and authenticated MCP completion owners with real shell, HTTP, and file effects, reporting seven correct callbacks and preserved responses under observer failure. Native vendor integrations are outside that evidence; no stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured before/after Gateway run exercises the registered CLI and authenticated MCP completion owners with real shell, HTTP, and file effects, reporting seven correct callbacks and preserved responses under observer failure. Native vendor integrations are outside that evidence; no stored-data contract changes.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Restores existing plugin completion observers for CLI and MCP calls with a bounded runtime repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured before/after Gateway run exercises the registered CLI and authenticated MCP completion owners with real shell, HTTP, and file effects, reporting seven correct callbacks and preserved responses under observer failure. Native vendor integrations are outside that evidence; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after Gateway run exercises the registered CLI and authenticated MCP completion owners with real shell, HTTP, and file effects, reporting seven correct callbacks and preserved responses under observer failure. Native vendor integrations are outside that evidence; no stored-data contract changes.

Evidence

What I checked:

  • Reviewed change identity: Reviewed the pinned merge-base-to-head production and test changes. Checkout and original PR head are ab3cef6; endpoint drift was not attributed to the PR. The supplied test merge is stale and was not used to claim removal of current-main behavior. (ab3cef625543)
  • Current main still needs the repair: Current-main CLI completion handling emits activity and performs bookkeeping without dispatching after_tool_call. The current-main MCP handler likewise runs before-tool policy and returns outcomes without the completion hook. No merged replacement is established by the supplied related-item context. (src/agents/cli-runner/execute-events.ts:125, 65230df0304d)
  • Earlier findings resolved: CLI completion names now use the same normalization as native before hooks. Compared with the previously reviewed revision, the shared completion helper now clones results through the existing isolation owner inside its guarded block. The loaded-plugin HTTP regression checks unchanged responses and internal results for plain, opaque, and shared-memory values across registry replacement. (src/agents/harness/hook-helpers.ts:43, ab3cef625543)
  • After-fix production-path evidence: The captured PR body, sourceRevision a180dc444858468bf4f7fc5fb7901f05d90f7b07ada655db8c4982613af53dfd, reports a built Gateway with a loaded observer plugin and synthetic CLI child. Baseline completion counts were zero; candidate counts were three exec, one web_fetch, and three MCP callbacks. It records rewritten inputs reaching execution and observers, duplicate suppression, denied actions without artifacts, HTTP 401 for a wrong token, preserved execution errors, and unchanged consumer results after observer mutation and failure. This covers OpenClaw’s registered boundaries, not native vendor integrations. (ab3cef625543)
  • Authority and compatibility review: The permission owner records approved arguments after the existing live-authority checks; the recorded values serve completion observation and do not grant execution authority. MCP authorization remains immediately before execution. The patch adds no configuration, protocol parameters, dependencies, or stored-data format. Uncloneable results warn and skip best-effort observation while preserving authoritative outcomes. (src/agents/cli-runner/execute-plugin.ts:213, ab3cef625543)
  • Established plugin contract: The hook reference defines after_tool_call as observation of results, errors, and duration, permits fire-and-forget dispatch, and requires canonical tool names for matchers. The repair uses that existing contract rather than adding a parallel plugin API. Its proof does not claim compatibility with the external Codex runtime or protocol. Public docs: docs/plugins/hooks/reference.md. (docs/plugins/hooks/reference.md:39, ab3cef625543)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-21T21:34:56.878Z sha 9d9030e :: needs real behavior proof before merge. :: [P2] Normalize native CLI names before dispatching completion hooks
  • reviewed 2026-09-22T06:36:32.658Z sha 95a6d5c :: blocked before merge. :: [P2] Isolate the MCP result before passing it to completion observers

@obviyus obviyus self-assigned this Sep 22, 2026
@obviyus
obviyus requested review from a team as code owners September 22, 2026 06:28
@obviyus obviyus changed the title fix(agents): dispatch after_tool_call when CLI and MCP tools complete fix: CLI and MCP tool completions skip plugin hooks Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Maintainer security changes approved

A maintainer approved this revision with an explicit security approval comment.

A later push requires a fresh approval comment for an external contributor's PR.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 22, 2026
@obviyus

obviyus commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

/allow-security-sensitive-change

@obviyus

obviyus commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-unrelated-red
pr: 155206
head: ab3cef6
run: 35706233795 attempt: 1
failed: checks-node-changed-extensions-bundle-17 job=106676287075 conclusion=failure
failed: checks-node-compact-large-10 job=106676287078 conclusion=failure
failed: checks-node-compact-large-13 job=106676287163 conclusion=failure
failed: checks-node-compact-large-14 job=106676287220 conclusion=failure
failed: checks-node-compact-large-17 job=106676287131 conclusion=failure
failed: checks-node-compact-large-6 job=106676287177 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit ca97ceb into openclaw:main Sep 22, 2026
197 of 205 checks passed
@obviyus

obviyus commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

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.

vincentkoc added a commit that referenced this pull request Sep 22, 2026
* 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
@iuiu-py
iuiu-py deleted the fix/after-tool-call-cli-mcp-155081 branch September 23, 2026 02:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: after_tool_call is almost never dispatched since 2026.9.3 while before_tool_call fires normally

2 participants