Skip to content

Comments

feat(hooks): emit compaction lifecycle hooks#16788

Open
vincentkoc wants to merge 22 commits intoopenclaw:mainfrom
vincentkoc:vincentkoc-code/hooks-compaction-lifecycle
Open

feat(hooks): emit compaction lifecycle hooks#16788
vincentkoc wants to merge 22 commits intoopenclaw:mainfrom
vincentkoc:vincentkoc-code/hooks-compaction-lifecycle

Conversation

@vincentkoc
Copy link
Contributor

@vincentkoc vincentkoc commented Feb 15, 2026

Why

Compaction is a critical lifecycle boundary for observability and guardrails, but runtime hook visibility was incomplete. This PR adds explicit compaction lifecycle emissions so operators and plugins can reliably track pre/post compaction state. lobster-biscuit

Split Context

This PR was split from closed umbrella PR #9761: #9761.

Detailed Changes

  • Internal hook emissions added in compaction flow:
    • session:compact:before
    • session:compact:after
  • Plugin hook wiring added in compaction flow:
    • before_compaction
    • after_compaction
  • Hook metadata now includes counts/token-oriented context (without full message snapshots)
  • Added focused test coverage for compaction hook emission and payload shape

Related Links, Issues and Resolutions

Greptile Summary

Adds internal (session:compact:before, session:compact:after) and plugin (before_compaction, after_compaction) hook emissions to the compaction flow with count/token metadata. The implementation correctly passes context including sessionId, agentId, sessionKey, workspaceDir, and messageProvider to plugin hooks, addressing previous concerns about missing sessionId. The PR also includes a subtle bug fix changing cwd: resolvedWorkspace to cwd: effectiveWorkspace to properly respect sandbox settings.

  • Internal hooks emit structured events with message counts and token estimates before/after compaction
  • Plugin hooks receive metadata without full message snapshots (by design per TODOs Feature: Pre-compaction hook for memory preservation #7175, Feature request: session:compact hook event #9611)
  • Test coverage validates hook emission, payload structure, and edge cases (empty transcripts, missing sessionKey)
  • compactedCount correctly measures total reduction from validated transcript through both history limiting and compaction
  • Previous thread concerns about missing sessionId in plugin context have been resolved

Confidence Score: 4/5

  • Safe to merge with high confidence - well-tested hook implementation with proper error handling
  • The implementation is solid with comprehensive test coverage and proper error handling. Previous concerns about missing sessionId have been addressed. The change from resolvedWorkspace to effectiveWorkspace is a legitimate bug fix. Hook payloads intentionally omit full message snapshots per design decisions documented in TODOs. Loses one point only due to the documentation formatting issue already flagged in previous threads (missing blank line before heading).
  • No files require special attention - all changes are well-structured and tested

Last reviewed commit: 85d9ced

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@vincentkoc
Copy link
Contributor Author

@greptileai i addressed your one issue on duplicate comment in the docs/readme. The PR should be ready to merge, can you please update your PR score?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: L

Projects

None yet

2 participants