Skip to content

[compaction] normalize legacy context compaction history#23785

Open
rhan-oai wants to merge 1 commit into
mainfrom
rhan/compaction-legacy
Open

[compaction] normalize legacy context compaction history#23785
rhan-oai wants to merge 1 commit into
mainfrom
rhan/compaction-legacy

Conversation

@rhan-oai
Copy link
Copy Markdown
Collaborator

@rhan-oai rhan-oai commented May 21, 2026

Why

This follows up on #22809.

Older persisted sessions can still contain context_compaction history items from before the remote-compaction wire contract moved to compaction_trigger inputs and compaction outputs. If those legacy items are sent through the prompt path unchanged, the backend rejects the request with an invalid enum error, which can leave compaction retrying and consuming quota.

Issues resolved:

What changed

  • Normalize legacy ResponseItem::ContextCompaction entries before prompt history is prepared.
  • Convert legacy entries that still have encrypted content into current ResponseItem::Compaction entries so compacted history survives.
  • Drop payload-less legacy context-compaction entries.
  • Treat any remaining context_compaction entries as non-API messages alongside compaction_trigger.
  • Add coverage for the legacy history normalization path.

Verification

  • Added legacy_context_compaction_items_are_not_sent_to_prompt in codex-rs/core/src/context_manager/history_tests.rs.

@rhan-oai rhan-oai changed the title [compaction] sanitize legacy context compaction history [compaction] normalize legacy context compaction history May 21, 2026
@rhan-oai rhan-oai marked this pull request as ready for review May 21, 2026 00:30
@rhan-oai rhan-oai requested a review from a team as a code owner May 21, 2026 00:30
@rhan-oai rhan-oai requested a review from dylan-hurd-oai May 21, 2026 00:31
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: 7b9bc73b7b

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

ResponseItem::CompactionTrigger => false,
ResponseItem::Other => false,
| ResponseItem::Compaction { .. } => true,
ResponseItem::ContextCompaction { .. }
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 encrypted context_compaction during replay

When resuming an older rollout, rollout_reconstruction.rs replays each persisted RolloutItem::ResponseItem through history.record_items(...), which first calls this predicate. Returning false here drops every legacy context_compaction item before for_prompt() can run normalize_legacy_context_compaction_items, so sessions whose suffix contains {"type":"context_compaction","encrypted_content":...} lose the compacted encrypted summary instead of converting it to ResponseItem::Compaction, leaving the resumed prompt without the compacted prior context.

Useful? React with 👍 / 👎.

@rhan-oai rhan-oai removed the request for review from dylan-hurd-oai May 21, 2026 00:35
@rhan-oai rhan-oai force-pushed the rhan/compaction-legacy branch from 7b9bc73 to 38f370a Compare May 21, 2026 00:41
@rhan-oai
Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

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

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

@rhan-oai rhan-oai requested a review from dylan-hurd-oai May 21, 2026 00:58
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