Skip to content

Plugin hooks exist in type system but some are never called in execution flow #6535

@ryancnelson

Description

@ryancnelson

Issue Description

While exploring the plugin hook system, I noticed that several hooks are defined in the type system and documented as available, but don't appear to have integration points in the actual execution flow.

Current Hook Status

✅ Working (4/12 hooks)

  1. before_agent_start - Called in src/agents/pi-embedded-runner/run/attempt.ts
  2. agent_end - Called in src/agents/pi-embedded-runner/run/attempt.ts
  3. message_received - Called in src/auto-reply/reply/dispatch-from-config.ts
  4. tool_result_persist - Called in src/agents/session-tool-result-guard-wrapper.ts

❓ Possibly Missing Integration (8/12 hooks)

  1. before_tool_call - Has types and runner function, but no call sites found
  2. after_tool_call - Has types and runner function, but no call sites found
  3. message_sending - Has types and runner function, but no call sites found
  4. message_sent - Has types and runner function, but no call sites found
  5. before_compaction - Has types and runner function, but no call sites found
  6. after_compaction - Has types and runner function, but no call sites found
  7. session_start - Has types and runner function, but no call sites found
  8. session_end - Has types and runner function, but no call sites found
  9. gateway_start - Has types and runner function, but no call sites found
  10. gateway_stop - Has types and runner function, but no call sites found

Technical Details

All hooks have complete infrastructure:

  • Type definitions in src/plugins/types.ts (lines 295-301)
  • Runner functions in src/plugins/hooks.ts
  • Exported in hook runner interface

The missing piece appears to be the actual calls to the runner functions in the execution flow.

Verification Steps

I searched for hook calls in the codebase:

Working hooks found:

grep -r "\.runBeforeAgentStart\|\.runAgentEnd\|\.runMessageReceived\|\.runToolResultPersist" src/ --include="*.ts"

Returns multiple call sites.

Other hooks not found:

grep -r "\.runBeforeToolCall\|\.runAfterToolCall\|\.runMessageSending\|\.runMessageSent\|\.runBeforeCompaction\|\.runAfterCompaction\|\.runSessionStart\|\.runSessionEnd\|\.runGatewayStart\|\.runGatewayStop" src/ --include="*.ts"

Returns no results.

Impact

Plugin developers can register handlers for these hooks, but the handlers may never execute since the runner functions aren't called in the execution flow.

Possible Solution

The infrastructure exists - it might just need the missing hookRunner.runXXX() calls added to the appropriate execution points:

  • Tool hooks: Could be added to tool execution handlers
  • Message hooks: Could be added to message dispatch flows
  • Compaction hooks: Could be added to compaction workflows
  • Session/gateway hooks: Could be added to lifecycle management

Let me know if this analysis is helpful or if I'm missing something about how these hooks are supposed to work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions