← Back to PRs

#15877: fix(hooks): add debug logging to triggerInternalHook

by Shuai-DaiDai open 2026-02-14 00:39 View on GitHub →
stale size: S
## Problem Users report that hooks (like session-memory) register successfully but do not appear to trigger when events occur (#15827). Currently there is no visibility into whether: - Handlers are being found for an event - The hook system is being invoked at all ## Solution Add debug logging to `triggerInternalHook()` to help diagnose hook execution: 1. Log when no handlers are found for an event (helps identify registration issues) 2. Log how many handlers are being triggered (helps verify execution) ## Changes ```typescript // Before: silent return if no handlers if (allHandlers.length === 0) { return; } // After: debug logging if (allHandlers.length === 0) { console.debug(`Hook: no handlers for ${eventKey}`); return; } console.debug(`Hook: triggering ${allHandlers.length} handler(s) for ${eventKey}`); ``` ## Debugging Workflow With this change, users can now: 1. Enable verbose logging 2. Run `/new` command 3. Check logs for "Hook: triggering..." or "Hook: no handlers..." 4. Determine if issue is registration or execution Related to #15827 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds debug output in `triggerInternalHook()` to make internal hook execution observable, logging when no handlers are registered and when handlers are about to run. The change sits in the core internal hooks dispatch path (`src/hooks/internal-hooks.ts`), which is invoked from command handling, gateway startup, and agent bootstrap flows. The added logs are intended to help distinguish between “hook system not invoked” vs “invoked but no matching handlers registered.” <h3>Confidence Score: 4/5</h3> - Mostly safe to merge, but logging should be aligned with the repo’s logging controls. - The functional change is small and localized (adds diagnostics only), but using `console.debug` in a core dispatch path is inconsistent with the repo’s logging approach and may not respect user-configured verbosity or could create noisy output. - src/hooks/internal-hooks.ts <sub>Last reviewed commit: ed1d030</sub> <!-- greptile_other_comments_section --> **Context used:** - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs