Fix: Plugin hooks registered but never fire #3249#3993
Fix: Plugin hooks registered but never fire #3249#3993WallaceSociety wants to merge 1 commit intoopenclaw:mainfrom
Conversation
| // Bridge to typed hooks: if any event matches a PluginHookName, also register | ||
| // in typedHooks so the hook runner can find it. This allows plugins to use | ||
| // either api.registerHook() or api.on() for typed hooks like message_received. | ||
| for (const event of normalizedEvents) { | ||
| if (TYPED_HOOK_NAMES.has(event as PluginHookName)) { | ||
| registry.typedHooks.push({ | ||
| pluginId: record.id, | ||
| hookName: event as PluginHookName, | ||
| handler: handler as unknown as PluginHookHandlerMap[PluginHookName], | ||
| priority: opts?.priority, | ||
| source: record.source, | ||
| } as TypedPluginHookRegistration); | ||
| record.hookCount += 1; |
There was a problem hiding this comment.
[P1] record.hookCount is incremented twice for typed hook events registered via api.registerHook().
registerHook() already pushes a legacy hook into registry.hooks, but the new bridge also does record.hookCount += 1 for each typed event (src/plugins/registry.ts:256-269). Since hookCount is also incremented in registerTypedHook() (src/plugins/registry.ts:464), this likely makes hookCount inconsistent across registration paths (legacy vs typed), and can over-count for multi-event registrations. Consider either not adjusting hookCount in the bridge, or explicitly defining whether hookCount should include typed hook registrations and keep that consistent across both APIs.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugins/registry.ts
Line: 256:268
Comment:
[P1] `record.hookCount` is incremented twice for typed hook events registered via `api.registerHook()`.
`registerHook()` already pushes a legacy hook into `registry.hooks`, but the new bridge also does `record.hookCount += 1` for each typed event (src/plugins/registry.ts:256-269). Since `hookCount` is also incremented in `registerTypedHook()` (src/plugins/registry.ts:464), this likely makes `hookCount` inconsistent across registration paths (legacy vs typed), and can over-count for multi-event registrations. Consider either not adjusting `hookCount` in the bridge, or explicitly defining whether `hookCount` should include typed hook registrations and keep that consistent across both APIs.
How can I resolve this? If you propose a fix, please make it concise.|
Closing with Tak approval: older root complaint already addressed/superseded |
Root Cause
The codebase had two separate hook systems that weren't properly connected:
Legacy hooks: api.registerHook() → registry.hooks
Typed hooks: api.on() → registry.typedHooks
The hook runner's hasHooks() and execution logic only checked registry.typedHooks, but the log message counted registry.hooks — creating a misleading situation where hooks appeared registered but never fired.
registerHook()to bridge totypedHookswhen the event name matches a typed hook likemessage_receivedGreptile Overview
Greptile Summary
This PR fixes a mismatch between plugin hook registration and execution by bridging legacy
api.registerHook()registrations into the typed hook registry when the event name matches a typed hook (e.g.message_received). It also corrects the global hook runner init log to report the number of typed hooks (the only ones the runner checks).Overall, this aligns registration and execution so hooks that appear registered will actually fire through the typed hook runner path.
Confidence Score: 4/5
hookCount) consistency due to the new bridge incrementing counts.(2/5) Greptile learns from your feedback when you react with thumbs up/down!