← Back to PRs

#13032: feat(hooks): add unified session:before_end hook event

by TGambit65 open 2026-02-10 02:17 View on GitHub →
size: S
This PR adds a new `session:before_end` hook event that fires before a session is cleared (e.g., via `/new`, `/reset`, `/compact`, or auto-reset). This allows plugins to perform cleanup tasks like context summarization or memory flushing before the session transcript is lost. Relates to Discussion #12164 and PR #12162. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a new plugin hook event (`session_before_end`) intended to fire right before a session is cleared (manual compaction and session resets/auto-resets). It wires new hook runner entrypoints in `src/plugins/hooks.ts` and attempts to invoke the hook from the compaction command and from session initialization when a reset is detected. Key issues to address before merge: - The new shared plugin registry (`getPluginRegistry`) is never initialized (no call to `setPluginRegistry`), so the hook will never run. - `session_before_end` is documented as sequential but is currently executed in parallel because it uses `runVoidHook`. - The reset “reason” mapping misclassifies explicit resets (e.g. `/reset`) as `auto`. - The hook is awaited during `initSessionState`, so a slow plugin can directly delay handling incoming messages (needs an explicit decision on timeout/backgrounding vs blocking semantics). <h3>Confidence Score: 2/5</h3> - This PR is not safe to merge until the hook wiring and execution semantics are corrected. - The `session_before_end` hook currently won’t fire at all due to an uninitialized shared registry, and the implementation contradicts its own sequential-execution contract (it runs handlers in parallel). Additionally, explicit reset reasons are misreported, and the hook can block session initialization with unbounded plugin runtime. - src/plugins/registry.ts, src/plugins/hooks.ts, src/auto-reply/reply/session.ts <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs