Repository navigation
fix(plugins): warn when registerHook uses a typed hook event name - #118601
Patrick-Erichsen merged 4 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 8:37 PM ET / August 7, 2026, 00:37 UTC. ClawSweeper reviewWhat this changesAdds a plugin-load warning, regression tests, and hook documentation when legacy Merge readinessThe warning is a correct, bounded repair for the silent legacy-to-typed hook mismatch. Keep this PR open while the five failed current-head checks are diagnosed or rerun; their causes were unavailable, so they cannot be treated as unrelated. Priority: P1 Review scores
Verification
How this fits togetherPlugin loading records legacy internal hooks separately from typed lifecycle hooks. The typed runner later dispatches only typed registrations, while loader diagnostics reach gateway logs during plugin startup. flowchart LR
A[Plugin author] --> B[Legacy registerHook]
A --> C[Typed api.on]
B --> D[Plugin load diagnostics]
C --> E[Typed hook registry]
D --> F[Gateway logs]
E --> G[Typed hook runner]
G --> H[Lifecycle handler]
Decision needed
Why: The patch itself is source-correct and has real gateway proof, but the unavailable required-check logs prevent safely classifying the current merge blocker. Before merge
Agent review detailsSecurityNone. PR surfaceSource +99, Docs +8. Total +107 across 3 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 options
Maintainer options:
Technical reviewBest possible solution: Land the diagnostic only after the exact-head failures are understood or pass, while retaining Do we have a high-confidence way to reproduce the issue? Yes—current source proves that legacy registrations and typed dispatch use separate stores, and the PR body supplies an after-fix real gateway transcript using a plugin with the affected call. Is this the best way to solve the issue? Yes for the stated silent-failure problem: warning at the legacy registrar is the narrowest maintainable repair because bridging legacy handlers into typed dispatch would change their incompatible decision contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ec023a433614. 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 (6 earlier review cycles)
|
058c403 to
450a820
Compare
api.registerHook registers into the legacy internal-hook path, while typed lifecycle events (before_tool_call, message_received, ...) are dispatched exclusively by the typed hook runner. Registrations under typed names silently never fired since openclaw#117372 moved the write to legacyInternalHooks. Emit a registration diagnostic pointing to the public api.on(...) API so plugin authors see the no-op at load time instead of trusting a false "loaded". Related to openclaw#116965 Co-Authored-By: deepseek-v4-flash <[email protected]>
450a820 to
981aab1
Compare
Condense the inline comment in createToolHookRegistrars and replace the internal registerTypedHook migration reference with the public api.on(...) API, matching the emitted warning and hooks docs. Behavior and tests unchanged.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
Patrick-Erichsen
left a comment
There was a problem hiding this comment.
Approved for landing at exact head 6cde47609551dbe3f2fe8ea3825495d76f96f2f5.
- Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/31136448053
- Fresh autoreview is clean (0.99 confidence); the final tree preserves the reviewed three-file patch exactly.
- The development-gateway evidence in the PR demonstrates the intended legacy
registerHookwarning while registration behavior remains intact.
Remaining mechanical gate: the queued ClawSweeper refresh must finish on this exact head, then the repository-native prepare/merge guards will run.
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
* origin/main: (58 commits) fix(test): restart shared gateway after migration convergence (openclaw#120089) fix(ui): make active-run steering reliable (openclaw#120083) fix(telegram): preserve voice fallback text test(swift): preserve queued websocket frames (openclaw#120106) fix: reject missing oxlint shard selectors (openclaw#120096) test(channels): align prerelease fallback catalog spec (openclaw#120092) fix(node-cli): warn when systemd user lingering is disabled after install (openclaw#118430) fix(diagnostics): preserve CLI turn usage totals (openclaw#120100) fix(gateway): derive lock and coordinator paths from the resolved state dir (openclaw#120110) fix(release): isolate private Telegram QA harness (openclaw#120088) test(agents): exercise execution attribution ingress guard fix(gateway): defer attribution until admission succeeds refactor(agents): centralize exact execution attribution fix(google): accept base64url provider media (openclaw#116204) fix(plugins): warn when registerHook uses a typed hook event name (openclaw#118601) fix(canvas): serve Content-Length on A2UI HEAD responses (openclaw#117961) fix(gateway): make doctor dreaming timestamp comparators NaN-safe (openclaw#118749) fix(heartbeat): explain target-none skips (openclaw#119689) fix(security): stop recommending retired install-policy bypasses (openclaw#120011) fix(plugins): preserve startup release during repair (openclaw#120085) ... # Conflicts: # CHANGELOG.md # src/config/sessions/session-accessor.sqlite-transcript-write.ts
…enclaw#118601) * [AI] fix(plugins): warn when registerHook uses a typed hook event name api.registerHook registers into the legacy internal-hook path, while typed lifecycle events (before_tool_call, message_received, ...) are dispatched exclusively by the typed hook runner. Registrations under typed names silently never fired since openclaw#117372 moved the write to legacyInternalHooks. Emit a registration diagnostic pointing to the public api.on(...) API so plugin authors see the no-op at load time instead of trusting a false "loaded". Related to openclaw#116965 Co-Authored-By: deepseek-v4-flash <[email protected]> * [AI] fix(plugins): point registerHook comment at public api.on API Condense the inline comment in createToolHookRegistrars and replace the internal registerTypedHook migration reference with the public api.on(...) API, matching the emitted warning and hooks docs. Behavior and tests unchanged. --------- Co-authored-by: deepseek-v4-flash <[email protected]> Co-authored-by: Patrick Erichsen <[email protected]>
What Problem This Solves
Plugins that register typed lifecycle hooks through the legacy
api.registerHookAPI get no warning when those handlers cannot receive typed events: registration returns OK,plugins inspectreports "loaded", butbefore_tool_call/message_receivedhandlers never fire, leaving structural-interception plugins (memory rules, security guards, prompt-injection filters) silently disabled.api.registerHook("before_tool_call", ...)registers into the legacy internal-hook path, while tool execution reads only the typed hook runner — the handler never fires, with no diagnostic or warning (false green "loaded")registerHook, pointing plugin authors to the publicapi.on(...); document the boundary in the hooks docssrc/plugins/registry-registrars-tools-hooks.ts(typed-name diagnostic inregisterHook),src/plugins/loader.registration.test-utils.ts(2 regression tests),docs/automation/hooks.md(migration note)command:new,gateway:startup,message:received, ...) still registers and dispatches throughtriggerInternalHook; the typed hook runner execution path is untouched; no behavior is removedChange Type (select all)
Scope (select all)
Linked Issue/PR
Motivation
api.registerHookis a public Plugin SDK surface that silently no-ops for typed lifecycle event names since the hook runner migration:registerHook("before_tool_call", ...)registers intoregistry.hooks+registry.legacyInternalHooks, whilegetHooksForName(src/plugins/hooks.ts) reads onlyregistry.typedHooks. The regression is invisible to operators: the plugin loads, inspect shows "loaded", and no log line ever appears — so memory guards and security policies fail open without any signal.The legacy handler signature (
InternalHookEvent, void return) cannot express the typed blocking semantics (block/requireApproval), so restoring interception forbefore_tool_callthrough the legacy path is a Plugin SDK contract decision. This PR fixes the silence — the part that hides the failure from operators and plugin authors — with a bounded registration diagnostic plus migration guidance, without changing the SDK contract or the execution path.Evidence
api.registerHook(["before_tool_call"], handler)now receives awarndiagnostic at registration time naming the typed event and the replacement API, instead of silently registering a handler that never fires.fix/hook-migration-diagnostic-116965(head058c403e32e). Real dev gateway (node scripts/run-node.mjs --dev gateway, isolated~/.openclaw-devstate) with a real plugin (hook-diagnostic-evidence) that callsapi.registerHook(["before_tool_call"], ...).CI=true pnpm install --frozen-lockfile~/.openclaw-dev/extensions/hook-diagnostic-evidence/{openclaw.plugin.json, package.json, index.cjs}whereindex.cjscallsapi.registerHook(["before_tool_call"], () => {})~/.openclaw-dev/openclaw.jsonplugins.load.paths+plugins.allowCI=true node scripts/run-with-env.mjs OPENCLAW_SKIP_CHANNELS=1 -- node scripts/run-node.mjs --dev gatewayBehavior matrix (event name passed to
api.registerHook=> result):before_tool_call/message_receivedthroughregisterHookgets an immediate registration warning naming the typed event and the replacement API.type:actionevents (gateway:startup,command:new) register exactly as before — no warning, samelegacyInternalHooksentries.registerHookcovers internal event keys only; typed lifecycle names are dispatched exclusively by the typed hook runner.api.on(...)(unchanged path); actualbefore_tool_callinterception semantics (legacy handlers cannot return blocking results by design — that is the documented reason for the migration).Root Cause
api.registerHook(src/plugins/registry-registrars-tools-hooks.ts) writes toregistry.hooks+registry.legacyInternalHooks, while the typed hook runner (src/plugins/hooks.tsgetHooksForName/hasHooks) reads onlyregistry.typedHooks. This semantic mismatch predates #117372: immediately beforee4d1b7e0d38,registerHookalready wrote throughregisterInternalHookinto legacy internal-hook state, while typed dispatch already selected onlyregistry.typedHooks. #117372 changed the storage ownership from global legacy state to registry-owned legacy state; it did not introduce the mismatch.Regression Test Plan
src/plugins/loader.registration.test-utils.ts(181 tests, +2 new):warns when registerHook is used with a typed hook event name— asserts both the diagnostic text and that the legacy registration still lands inlegacyInternalHookskeeps legacy type:action events diagnostic-free in registerHook— assertsgateway:startup/command:newproduce no typed-name warningsrc/plugins/contracts/boundary-invariants.test.ts+src/plugins/loader.hooks-and-runtime.test-utils.ts— 2 shards passedUser-visible / Behavior Changes
Plugin authors who call
api.registerHookwith a typed lifecycle event name now see a clear registration warning (inpluginsdiagnostics and gateway logs) telling them the handler will not be invoked and to use the publicapi.on(...)API. No existing registration, event dispatch, or config behavior changes; no output is removed.Security Impact
Human Verification
before_tool_callthroughregisterHook(warning emitted); legacytype:actionregistration matrix (no warning).registerHookcall (diagnostic per typed name); unknown event names (no diagnostic); duplicate-hook error path unchanged.api.on(...)plugins end-to-end interception (unchanged path, covered by existing typed-hook tests).Compatibility / Migration
api.on(...)when they see the warningBest-fix Verdict
legacyInternalHooks) would silently degrade blocking semantics (legacy handlers return void) and is a maintainer-owned contract decision.registerHookregistrar, so every plugin path (file, directory, manifest, SDK consumer) gets it.block/requireApprovaland it changes public dispatch semantics. (2) Hard error on typed names; rejected because it would break currently loading plugins instead of warning. (3) Migration diagnostic (chosen).AI Assistance
registerHook→registry.legacyInternalHooksvsgetHooksForName→registry.typedHooks, and history across the refactor(plugins): move plugin contributions into the registry bundle #117372 registry refactor.Risks and Mitigations
type:actionhooks keep working.Related to #116965