← Back to PRs

#12581: feat(hooks): emit session prune lifecycle event

by vincentkoc open 2026-02-09 10:34 View on GitHub →
docs agents stale
## Why Context pruning changes model input quality and cost, but there was no dedicated internal lifecycle signal for pruning actions. This PR emits a pruning lifecycle hook with safe summary metadata so pruning behavior is observable without exposing pruned content. Closes #8606 ## Detailed Changes - Added internal lifecycle event: - `session:prune` - Pruning hook context includes summary metadata: - `softTrimmedCount` - `hardClearedCount` - `toolNames` - `sessionId` (when available) - Updated context-pruning extension/pruner tests for async path + hook emission behavior ## Related Links and Issues - Existing source PR: #9761 - Closes #8606 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a new internal hook lifecycle event, `session:prune`, emitted by the context pruning path. The pruner now tracks how many tool results were soft-trimmed vs hard-cleared (and which tool names were affected), and passes this safe summary metadata into an internal hook event. The context-pruning extension’s `context` handler was updated to be async to await pruning, and tests were updated to cover the async path and hook emission behavior. Within the codebase, this integrates into the existing internal hook system (`src/hooks/internal-hooks.ts`) by creating and triggering an `InternalHookEvent` of type `session` and action `prune`, keyed by a derived session key. <h3>Confidence Score: 4/5</h3> - This PR is mostly safe to merge, but there is one correctness issue around the emitted hook event timestamp semantics that should be clarified/fixed. - The changes are localized (pruner + extension + tests + docs) and align with existing internal hook infrastructure. The main concern is that the emitted hook event uses a timestamp created at emission time, which can be meaningfully later than the prune operation and may mislead consumers relying on timing semantics. - src/agents/pi-extensions/context-pruning/pruner.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs