Skip to content

Fix: Plugin hooks registered but never fire #3249#3993

Closed
WallaceSociety wants to merge 1 commit intoopenclaw:mainfrom
WallaceSociety:fix-plugin-hooks-3249
Closed

Fix: Plugin hooks registered but never fire #3249#3993
WallaceSociety wants to merge 1 commit intoopenclaw:mainfrom
WallaceSociety:fix-plugin-hooks-3249

Conversation

@WallaceSociety
Copy link
Copy Markdown

@WallaceSociety WallaceSociety commented Jan 29, 2026

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.

  • types.ts: Added TYPED_HOOK_NAMES export to src\plugins\types.ts
  • imported TYPED_HOOK_NAMES into src\plugins\registry.ts and modified registerHook() to bridge to typedHooks when the event name matches a typed hook like message_received

Greptile 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

  • This PR is likely safe to merge and should resolve the reported hook firing issue.
  • Changes are localized and conceptually align hook registration with the hook runner’s lookup path; the main remaining concern is internal accounting (hookCount) consistency due to the new bridge incrementing counts.
  • src/plugins/registry.ts (hookCount accounting and ensuring the bridge doesn’t skew plugin metadata)

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@WallaceSociety WallaceSociety changed the title Fix: Plugin hooks registered but never fire Fix: Plugin hooks registered but never fire #3249 Jan 29, 2026
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +256 to +268
// 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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Takhoffman
Copy link
Copy Markdown
Contributor

Closing with Tak approval: older root complaint already addressed/superseded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants