Skip to content

Add compact lifecycle hooks (started by vincentkoc - external contrib)#19905

Merged
eternal-openai merged 20 commits intomainfrom
codex/fix-compact-hooks-lifecycle
May 7, 2026
Merged

Add compact lifecycle hooks (started by vincentkoc - external contrib)#19905
eternal-openai merged 20 commits intomainfrom
codex/fix-compact-hooks-lifecycle

Conversation

@eternal-openai
Copy link
Copy Markdown
Contributor

@eternal-openai eternal-openai commented Apr 28, 2026

Based on work from Vincent K - #19060

CleanShot 2026-04-29 at 20 47 40@2x

Why

Compaction rewrites the conversation context that future model turns receive, but hooks currently have no deterministic lifecycle point around that rewrite. This adds compact lifecycle hooks so users can audit manual and automatic compaction, surface hook messages in the UI, and run post-compaction follow-up without overloading tool or prompt hooks.

What Changed

  • Added PreCompact and PostCompact hook events across hook config, discovery, dispatch, generated schemas, app-server notifications, analytics, and TUI hook rendering.
  • Added trigger matching for compact hooks with the documented manual and auto matcher values.
  • Wired PreCompact before both local and remote compaction, and PostCompact after successful local or remote compaction.
  • Kept compact hook command input to lifecycle metadata: session id, Codex turn id, transcript path, cwd, hook event name, model, and trigger.
  • Made compact stdout handling consistent with other hooks: plain stdout is ignored as debug output, while malformed JSON-looking stdout is reported as failed hook output.
  • Added integration coverage for compact hook dispatch, trigger matching, post-compact execution, and the audited behavior that decision:"block" does not block compaction.

Out of Scope

  • Hook-specific compaction blocking is not implemented; decision:"block" and exit-code-2 blocking semantics are intentionally unsupported for PreCompact.
  • Custom compaction instructions are not exposed to compact hooks in this PR.
  • Compact summaries, summary character counts, and summary previews are not exposed to compact hooks in this PR.

Verification

  • cargo test -p codex-hooks
  • cargo test -p codex-core manual_pre_compact_block_decision_does_not_block_compaction
  • cargo test -p codex-app-server hooks_list
  • cargo test -p codex-core config_schema_matches_fixture
  • cargo test -p codex-tui hooks_browser

Docs

The developer documentation for Codex hooks should be updated alongside this feature to document PreCompact and PostCompact, the manual/auto matcher values, and the compact hook payload fields.

@eternal-openai eternal-openai changed the title Fix compact lifecycle hooks Align compact hooks with documented lifecycle semantics Apr 28, 2026
@eternal-openai eternal-openai changed the title Align compact hooks with documented lifecycle semantics Add compact lifecycle hooks Apr 28, 2026
@eternal-openai eternal-openai changed the title Add compact lifecycle hooks Add compact lifecycle hooks (started by vincentkoc - external contrib) Apr 28, 2026
@eternal-openai eternal-openai marked this pull request as ready for review April 29, 2026 21:24
@eternal-openai eternal-openai requested a review from a team as a code owner April 29, 2026 21:24
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f050381923

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/compact_remote.rs Outdated
Stopped,
}

pub(crate) async fn run_post_compact_hooks(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

very non blocking nit: these methods look very boilerplate (most of request parameters are repeated, event emmiting, etc.)

…ks-lifecycle

# Conflicts:
#	codex-rs/app-server/src/config_api.rs
#	codex-rs/core/config.schema.json
#	codex-rs/core/src/session/turn.rs
#	codex-rs/tui/src/chatwidget/tests/helpers.rs
…ks-lifecycle

# Conflicts:
#	codex-rs/hooks/src/engine/mod.rs
@eternal-openai eternal-openai merged commit 527d52d into main May 7, 2026
26 checks passed
@eternal-openai eternal-openai deleted the codex/fix-compact-hooks-lifecycle branch May 7, 2026 01:08
@github-actions github-actions Bot locked and limited conversation to collaborators May 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants