feat(hooks): post_compact event with realized compaction outcome#218
Merged
emal-avala merged 1 commit intomainfrom Apr 23, 2026
Merged
feat(hooks): post_compact event with realized compaction outcome#218emal-avala merged 1 commit intomainfrom
emal-avala merged 1 commit intomainfrom
Conversation
Pairs with PreCompact (which fires before compaction with estimates). PostCompact fires AFTER compaction finishes, carrying the ground-truth delta: messages_before, messages_after, and actual tokens freed. Audit hooks can now record both the forecast and the reality, which matters because the three compaction paths (microcompact, LLM compaction, context collapse fallback) don't always free what the estimate predicted — e.g. LLM compaction can be blocked by a cancel, and the collapse fallback frees a different shape of context. Wiring: - New HookEvent::PostCompact variant with snake_case serde - fire_post_compact_hooks(messages_before, messages_after, freed_tokens) on QueryEngine - /compact handler fires it after microcompact, including for no-op compactions (freed=0) so hooks see every user-invoked /compact - run_turn_with_sink fires it once at the end of the auto-compact block with the cumulative delta across all paths taken; skipped when nothing actually changed so hooks aren't spammed every turn - HOOK_EVENT_CATALOG, format_hook_event, parse_hook_event, and the module-header docs all updated 3 new tests: schema serde round-trip, dispatcher fires for PostCompact, and parse_hook_event handles both snake_case and hyphenated forms. Existing format_hook_event_covers_every_variant now asserts PostCompact is mapped, and parse_hook_event_covers_every_variant_in_catalog keeps the catalog and parser in lock-step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pairs with `PreCompact` (which fires before compaction with an estimated tokens-freed number). `PostCompact` fires after compaction finishes, carrying the ground-truth delta: `messages_before`, `messages_after`, and the actual `freed_tokens`.
Audit hooks can now record both the forecast and the reality. That matters because the three compaction paths — microcompact, LLM compaction, and the context-collapse fallback — don't always free what the estimate predicted. LLM compaction can be blocked by a cancel; the collapse fallback frees a different shape of context; and in the no-op case nothing changes at all.
Wiring
Test plan