Hooks errors

Common error signatures

Errors in the hook system typically fall into three categories:

Where errors originate

The following functions are the most common raise sites. The symptom you observe upstream — a hook silently not firing, a fire() call returning no results, or a script handler crashing — usually traces back to one of these:

How to diagnose

  1. Read the execution log first. Call HookRegistry.get_execution_log() (optionally with event_filter) immediately after a failed fire() or fire_sync() call. The log shows which HookRule and HookDefinition were attempted and where execution stopped.

  2. Check get_stats() for silent failures. If fire() returns an empty list when you expected results, call HookRegistry.get_stats() to verify that hooks are registered for the event and that the HookMatcher.matches() call is returning True for your context.

  3. Validate your HookConfig in isolation. Load the config with HookConfig.from_yaml() and call get_hooks_for_event() for the relevant HookEvent before wiring it into a HookRegistry. This confirms the YAML parsed correctly and the right rules are present.

  4. Verify Python handler registration. If the error message indicates an unresolved handler, confirm that every handler name referenced in your HookDefinition objects appears as a key in the python_handlers dict you passed to HookExecutor or HookExecutorSync.

  5. Check context keys for script hooks. run_evaluate_session(), apply_learned_patterns(), and run_pre_compact() all receive a context: dict[str, Any]. Print the context dict at the call site and compare it against the keys the script expects — missing keys are the most common cause of KeyError in these handlers.

Source files

Tags: hooks, webhooks, events, automation