Skip to content

feat: retain remote compaction truncation parity in v2#23728

Merged
jif-oai merged 8 commits into
mainfrom
jif/truncation-in-compaction
May 21, 2026
Merged

feat: retain remote compaction truncation parity in v2#23728
jif-oai merged 8 commits into
mainfrom
jif/truncation-in-compaction

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented May 20, 2026

Why

Remote compaction now has two implementations: the existing server-rebuilt v1 path and the newer client-rebuilt v2 path behind remote_compaction_v2. The v1 path bounds retained user/developer/system history before installing the compaction item, while v2 was previously carrying the full retained history forward. That made the two paths diverge for large pre-compaction transcripts even though they are meant to preserve the same compaction contract.

This aligns v2 with the retained-history budget expected from v1 so switching the feature flag does not materially change which pre-compaction messages survive into the rebuilt history.

What changed

  • Apply a retained-message character budget while rebuilding v2 compacted history in core/src/compact_remote_v2.rs.
  • Keep newest retained messages first, truncate the boundary message with the shared truncate_text(...) helper, and drop older retained messages once the budget is exhausted.
  • Preserve non-text retained message content such as images while truncating text content.
  • Use the current 64_000 token retained-message default translated to the existing 4x character budget.

Testing

  • cargo test -p codex-core compact_remote_v2::tests::
  • Added focused coverage for newest-first retention and truncating multipart retained messages without dropping images.

@jif-oai jif-oai requested a review from a team as a code owner May 20, 2026 18:56
@jif-oai jif-oai changed the title feat: truncation for remote v2 feat: retain remote compaction truncation parity in v2 May 20, 2026
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: 9ba2639bde

ℹ️ 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_v2.rs Outdated
Comment thread codex-rs/core/src/compact_remote_v2.rs Outdated
Comment thread codex-rs/core/src/compact_remote_v2.rs Outdated
Comment thread codex-rs/core/src/compact_remote_v2.rs Outdated
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented May 21, 2026

@codex review

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: 7396339ef5

ℹ️ 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_v2.rs Outdated
Comment thread codex-rs/core/src/compact_remote_v2.rs Outdated
Comment thread codex-rs/core/src/compact_remote_v2.rs Outdated
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented May 21, 2026

@codex review

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: 576f84c9d0

ℹ️ 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_v2.rs
Comment thread codex-rs/core/src/compact_remote_v2.rs
Comment thread codex-rs/core/src/compact_remote_v2.rs
ContentItem::InputText { text } | ContentItem::OutputText { text } => {
approx_token_count(text)
}
ContentItem::InputImage { .. } => 0,
Copy link
Copy Markdown
Contributor

@starr-openai starr-openai May 21, 2026

Choose a reason for hiding this comment

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

0 for image?

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.

Those are not encoded in the same way
This was already the case in v1

@jif-oai jif-oai merged commit 94442b7 into main May 21, 2026
31 checks passed
@jif-oai jif-oai deleted the jif/truncation-in-compaction branch May 21, 2026 13:07
@github-actions github-actions Bot locked and limited conversation to collaborators May 21, 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.

2 participants