Skip to content

Support compact SessionStart hooks#21272

Open
abhinav-oai wants to merge 2 commits intomainfrom
abhinav/session-start-compact
Open

Support compact SessionStart hooks#21272
abhinav-oai wants to merge 2 commits intomainfrom
abhinav/session-start-compact

Conversation

@abhinav-oai
Copy link
Copy Markdown
Collaborator

@abhinav-oai abhinav-oai commented May 5, 2026

Why

Compaction replaces the live conversation history, so hooks that use SessionStart to re-inject durable model context need a way to run again after that rewrite.

Related: #19905 adds dedicated compact lifecycle hooks

What

  • add compact as a supported SessionStart source and matcher value
  • change pending SessionStart state from a single slot to a small FIFO queue so resume / startup / clear can be preserved alongside a later compact
  • drain all queued SessionStart sources before the next model request, preserving their original order

Testing

The new integration coverage verifies both the basic compact matcher path and the stacked resume -> compact case where both hooks contribute additionalContext to the next model turn.

@abhinav-oai abhinav-oai marked this pull request as ready for review May 5, 2026 23:53
@abhinav-oai abhinav-oai requested a review from a team as a code owner May 5, 2026 23:53
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: 87e22371bc

ℹ️ 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/session/mod.rs Outdated
}
{
let mut state = self.state.lock().await;
state.set_pending_session_start_source(Some(codex_hooks::SessionStartSource::Compact));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Preserve pending startup source when compacting pre-turn

This unconditionally overwrites any pending Startup/Resume/Clear source. run_turn runs pre-sampling compaction before run_pending_session_start_hooks, so a resumed/cleared long thread that compacts before its first turn will lose the original SessionStart hook and run only compact, skipping durable context intended for resume/startup.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

interesting, because SessionStart is fired when the turn starts we can have the following edge case

resume long thread
pending = resume

first turn begins
pre-sampling compaction runs
pending = compact

before model request
pending is skipped <-- bug!
fire compact

we need to be able to queue up multiple pending so this happens instead

resume long thread
pending = [resume]

first turn begins
pre-sampling compaction runs
pending = [resume, compact]

before model request
fire resume
fire compact

@abhinav-oai abhinav-oai force-pushed the abhinav/session-start-compact branch from 87e2237 to 2bf5efd Compare May 6, 2026 00:09
@abhinav-oai
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Delightful!

ℹ️ 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".

Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request May 6, 2026
- anomalyco/opencode#25959 keep-alive newlines on POST /session/:id/message [merge-after-nits]
- anomalyco/opencode#25855 wide-text paste-summary order fix via Intl.Segmenter [merge-after-nits]
- openai/codex#21290 extract codex-file-watcher crate from core [merge-after-nits]
- openai/codex#21272 add 'compact' SessionStartSource with FIFO queue [merge-after-nits]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant