feat(hooks): emit session prune lifecycle event#12581
feat(hooks): emit session prune lifecycle event#12581vincentkoc wants to merge 11 commits intoopenclaw:mainfrom
Conversation
Additional Comments (1)
This affects the Prompt To Fix With AIThis is a comment left during a code review.
Path: src/agents/pi-extensions/context-pruning/pruner.ts
Line: 345:355
Comment:
**Missing prune hook emission**
When `prunableToolChars < settings.minPrunableToolChars`, the function returns `outputAfterSoftTrim` without calling `emitPruneHook()`. In that scenario, earlier soft-trims may have happened (and counts/tool names are tracked), but the new `session:prune` lifecycle event will never be emitted. If the intent is “emit whenever any pruning occurred”, this early return breaks observability.
This affects the `minPrunableToolChars` guard path specifically (pruning happens, but total prunable chars is below the threshold).
How can I resolve this? If you propose a fix, please make it concise. |
Additional Comments (1)
This test mocks |
bfc1ccb to
f92900f
Compare
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
session:prunesoftTrimmedCounthardClearedCounttoolNamessessionId(when available)Related Links and Issues
Greptile Overview
Greptile Summary
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’scontexthandler 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 anInternalHookEventof typesessionand actionprune, keyed by a derived session key.Confidence Score: 4/5