Skip to content

fix(codex): detect compaction boundary when a system-role message follows the user turn - #205

Open
Bjorgz wants to merge 1 commit into
raine:mainfrom
Bjorgz:fix/compact-detect-trailing-system-message
Open

Bjorgz wants to merge 1 commit into
raine:mainfrom
Bjorgz:fix/compact-detect-trailing-system-message

Conversation

@Bjorgz

@Bjorgz Bjorgz commented Nov 8, 2026

Copy link
Copy Markdown

Fixes #204.

Claude Code 2.1.319 appends a system-role message after the user turn whenever a UserPromptSubmit hook or an output style emits text, so the compaction instruction (CRITICAL: Respond with TEXT ONLY… + Your task is to create a detailed summary…) sits in the final user message while messages.last() is that system message. is_compact_messages_request only looked at messages.last(), so with the normal (cache-safe) system prompt neither detection path matched and native compaction never triggered on such installs.

Change: skip trailing system-role messages and check the last user message. Any other trailing role (e.g. assistant) still means the request is not a compaction boundary, so the existing "markers must be in the final user message" behaviour is kept.

Tests: compact_request_detected_when_hook_system_message_follows_user (the captured 2.1.319 shape) and compact_message_not_detected_when_assistant_message_follows_user; the existing compaction detection tests pass unchanged.

Verified against a live Claude Code 2.1.319 session through the proxy: /compact produced zero server_compaction_* events before the change; the same request shape with the instruction as the final user message triggers server_compaction_triggered + server_compaction_completed in ~5 s.

🤖 Generated with Claude Code

…lows the user turn

Claude Code 2.1.319 appends a `system`-role message after the user turn
whenever a UserPromptSubmit hook or an output style emits text, so the
compaction instruction sits in the final user message while
`messages.last()` is that system message. With the normal (cache-safe)
system prompt neither detection path matched and native compaction never
triggered on such installs.

Skip trailing `system` messages and check the last user message; any other
trailing role still means "not a boundary".

Fixes raine#204

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Codex server compaction never triggers when Claude Code appends a system-role message after the user turn (hooks / output styles)

1 participant