Skip to content

2026.6.5: before_tool_call/after_tool_call hooks of local extensions register but never fire (regression from 2026.5.27) #91918

Closed

Description

@vokaplok

Summary

After upgrading a long-running install from 2026.5.27 → 2026.6.5, before_tool_call / after_tool_call hooks of local (global-dir) extensions register successfully but never fire during agent runs. Hook-based safety/observability plugins (an approval gate on before_tool_call, a tool-call logger on after_tool_call) silently stop working. Rolling back to 2026.5.27 (same configs, same manifests) restores hook firing.

Environment

  • openclaw 2026.6.5 (5181e4f), upgraded from 2026.5.27 (27ae826)
  • Node v22.22.0 (nvm), Ubuntu 24.04
  • Extensions in ~/.openclaw/extensions/<name>/ with openclaw.plugin.json manifests, enabled via plugins.allow + plugins.entries.<name>.enabled: true
  • openclaw doctor --fix ran clean after upgrade (legacy agentRuntime keys + openai-codex-responses api migrated)

Repro

  1. Extension registering a blocking hook:
    export default function register(api) {
      api.logger.info('[gate] registered');
      api.on('before_tool_call', (event) => {
        if ((event.params?.command || '').includes('curl')) {
          return { block: true, blockReason: 'blocked by gate' };
        }
      });
    }
  2. On 2026.5.27: agent run attempting curl -X POST … → blocked, blockReason returned to the model. ✅
  3. On 2026.6.5: same run → command executes, hook handler never invoked. ❌ Registration log line appears (both at gateway boot and at run start), but the handler does not run. An after_tool_call logger plugin shows the same: registration logged, zero events captured.

Verified through both an openclaw agent --agent … --message … run and a normal channel-originated embedded run.

What we tried

  • Added activation.onCapabilities: ["hook"] to all extension manifests → plugins now load at gateway boot (visible in the "http server listening (N plugins: …)" line) instead of lazily, registration logs appear — hooks still never fire.
  • Added explicit per-plugin hook policy in config (plugins.entries.<name>.hooks.timeouts.before_tool_call) → no change.
  • openclaw plugins registry --refresh → no change.
  • Interesting data point: a before_prompt_build hook (with hooks.timeouts configured) does fire on 6.5. The breakage seems specific to the tool-call hook path for these plugins.
  • During state migration, doctor logged: Left plugin install index in place because shared SQLite state has conflicting plugin install metadata for: … (3 stock plugins) — possibly related, possibly noise.

In dist/agent-tools.before-tool-call-*.js the path is gated by getGlobalHookRunner()?.hasHooks("before_tool_call") — it looks like the runtime hook registrations from these plugins don't land in (or aren't visible to) the runner instance consulted there.

Expected

before_tool_call/after_tool_call handlers of enabled local extensions fire in agent runs, as on 2026.5.27 — or, if extra activation/permission config is now required, a doctor warning + docs note saying so.

Workaround

Pinned to 2026.5.27.

Activity

  1. clawsweeper commented on Jun 10, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 15, 2026, 1:18 PM ET / 17:18 UTC.

    Summary
    Keep this open: current main and the latest release still contain the single/global hook-runner visibility split, while the proof-positive fix remains an open unmerged PR. The issue is security-relevant because a registered local before_tool_call gate can be skipped before native tool execution.

    Reproducibility: yes. at source level with high confidence. Current main preserves a gateway-bound global runner across a later default activation, and tool execution asks only that runner whether before_tool_call hooks exist.

    Next step
    Do not queue a new automated fix PR because #92016 already owns the implementation path and the issue is security-sensitive.

    Security
    Needs attention: This issue is security-sensitive because a local fail-closed tool-call gate can be registered but skipped at execution time.

    Review details

    Best possible solution:

    Land #92016 or an equivalent core plugin-runtime fix that makes tool-call dispatch see the canonical live hook registry without requiring new activation or timeout configuration.

    Do we have a high-confidence way to reproduce the issue?

    Yes, at source level with high confidence. Current main preserves a gateway-bound global runner across a later default activation, and tool execution asks only that runner whether before_tool_call hooks exist.

    Is this the best way to solve the issue?

    Yes, the best path is to fix hook-registry lifecycle ownership rather than add activation, timeout, or permission configuration. The open linked PR targets that owner boundary, but this issue should remain open until that work is merged or replaced.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Until the linked fix or equivalent lands, local extensions can appear registered while fail-closed before_tool_call policy hooks remain invisible to tool execution.
    • Audit and observability plugins using after_tool_call can silently miss the same tool events through the global-runner split.
    • The linked fix changes hook-registry lifecycle semantics, so maintainers still need compatibility and security-boundary review before closing this issue.

    Codex review notes: model internal, reasoning high; reviewed against 8ded75628437.

    Label changes

    Label changes:

    • remove clawsweeper:linked-pr-open: Current issue advisory state no longer selects this label.

    Label justifications:

    • P1: This is a stable-release regression that can silently disable safety and observability hooks during normal agent tool execution.
    • impact:security: A configured before_tool_call gate can stop enforcing the tool-execution boundary while commands continue to run.
    Evidence reviewed

    Security concerns:

    • [high] Restore the blocking hook boundary — src/agents/agent-tools.before-tool-call.ts:1041
      The global runner consulted by runBeforeToolCallHook() can lack the active plugin registry's before_tool_call handler, so native tool execution can proceed without the configured block or approval decision.
      Confidence: 0.93

    What I checked:

    • Global runner is still bound to one registry: Current main initializes the global hook runner by creating a HookRunner over the passed registry and storing that exact runner globally; it does not compose live active or pinned registries. (src/plugins/hook-runner-global.ts:32, 8ded75628437)
    • Gateway/default activation can preserve a stale runner: activatePluginRegistry still preserves the existing gateway hook runner when a later default-mode activation occurs, then sets the active registry without reinitializing the global runner. (src/plugins/loader.ts:1712, 8ded75628437)
    • Current tests lock in the visibility split: The focused loader test activates a default registry after a gateway-bindable registry, asserts the active registry changed, and then asserts the preserved global runner still does not see the later registry's hook. (src/plugins/loader.test.ts:4104, 8ded75628437)
    • Tool-call dispatch depends on that global runner: runBeforeToolCallHook calls getGlobalHookRunner() and returns early when that runner reports no before_tool_call hooks, matching the silent-bypass shape in the report. (src/agents/agent-tools.before-tool-call.ts:1041, 8ded75628437)
    • After-tool dispatch uses the same runner surface: The embedded tool completion handler falls back to getGlobalHookRunner() before firing after_tool_call, which supports the report that both tool-hook directions can disappear through the same runner visibility split. (src/agents/embedded-agent-subscribe.handlers.tools.ts:1669, 8ded75628437)
    • Latest release still has the old logic: v2026.6.6 points at 8c802aa and still contains the same preserveGatewayHookRunner branch, so the fix is not shipped in the latest release. (src/plugins/loader.ts:1708, 8c802aa68351)

    Likely related people:

    • amknight: Authored the open linked PR that directly targets the hook-runner/registry lifecycle problem for this issue. (role: current fix owner; confidence: high; commits: 32e6695e0464; files: src/plugins/hook-runner-global.ts, src/plugins/runtime.ts, src/plugins/loader.ts)
    • vincentkoc: Authored recent global hook-runner lifecycle and gateway live-hook preservation commits in the implicated plugin runtime surface. (role: hook-runtime contributor; confidence: high; commits: d22279d2e873, f41bdf3c543a, 7f5a5a34dbf8; files: src/plugins/runtime.ts, src/plugins/hook-runner-global.ts, src/plugins/loader.ts)
    • steipete: Authored the merged work that wired before_tool_call into tool execution, which is the contract this regression breaks. (role: introduced before-tool-call execution wiring; confidence: medium; commits: 8eb11bd3044a; files: src/agents/pi-tools.before-tool-call.ts, src/agents/agent-tools.before-tool-call.ts)
    • zhang-guiping: Current-main blame for the extracted loader, hook-runner, and before-tool-call files points to a recent large refactor/import commit; useful routing context, not root-cause attribution. (role: recent area contributor; confidence: medium; commits: ba1be23821da; files: src/plugins/loader.ts, src/plugins/hook-runner-global.ts, src/agents/agent-tools.before-tool-call.ts)
    How this review workflow works
    • 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.
  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    and removed
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    on Jun 10, 2026
  3. juno02139 commented on Jun 16, 2026

    @juno02139

    Still present in the latest release v2026.6.6 — with a security-boundary impact

    Confirming this regression is live in v2026.6.6 (8c802aa) and that it defeats a real tenant-isolation control, in support of #92016.

    Setup: an in-tree plugin registers a before_tool_call hook that returns a block for tool calls whose sessionKey originates from an untrusted Discord channel (a per-channel tool gate). register() runs once at boot (trustedChannels=15 blockAllTools=true); the sister plugin's after_tool_call fires normally.

    Symptom: on v2026.6.6, a Discord channel-origin native exec runs un-gated — the before_tool_call handler is never invoked (no plugin log line for the turn, no block), so the gate is silently bypassed. On v2026.6.5 (5181e4f) the identical call is blocked as designed. So the runner/registry split this issue describes is still shipping in the latest release, and its practical effect here is that a plugin-enforced tenant wall fails open — an untrusted channel can execute native tools.

    Repro (live, 2026-06-15): @bot run \date`from an untrusted Discord channel →v2026.6.6returned a fresh real date with no block;v2026.6.5returned the cached value with an explicit "blocked" caveat + a block-audit event. We've pinned back tov2026.6.5` pending #92016.

  4. locked as resolved and limited conversation to collaborators on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions