Skip to content

[codex] Compact when comp_hash changes - #27520

Merged
aibrahim-oai merged 7 commits into
mainfrom
codex/compact-on-comp-hash-change
Jun 11, 2026
Merged

[codex] Compact when comp_hash changes#27520
aibrahim-oai merged 7 commits into
mainfrom
codex/compact-on-comp-hash-change

Conversation

@aibrahim-oai

@aibrahim-oai aibrahim-oai commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • snapshot comp_hash into TurnContext when the turn is created and use that snapshot as the downstream source of truth
  • persist the turn hash in rollout context and recover it into previous-turn settings during resume and fork replay
  • compact existing history with the previous model only when both adjacent turns provide hashes and the values differ
  • record comp_hash_changed as the compaction reason
  • cover ordinary transitions, resume, and missing-hash compatibility with end-to-end tests

Why

History produced under one compaction-compatible model configuration may not be safe to carry directly into another. Compacting at the turn boundary converts that history before context updates and the new user message are added. Persisting the turn snapshot in TurnContextItem makes the same protection work after resuming a rollout.

A missing hash is not treated as evidence of incompatibility. None → Some, Some → None, and None → None do not trigger compaction; only Some(previous) → Some(current) with unequal values does.

Stack

Testing

  • just test -p codex-core pre_sampling_compact_ — 6 passed
  • just test -p codex-core turn_context_item_uses_turn_context_comp_hash_snapshot — passed
  • just fix -p codex-core -p codex-protocol -p codex-analytics -p codex-models-manager

@aibrahim-oai
aibrahim-oai force-pushed the codex/add-comp-hash-model-info branch from 64e76ec to 5a77281 Compare June 11, 2026 02:48
@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-on-comp-hash-change branch from 35ea7a5 to 67cd3d9 Compare June 11, 2026 02:48
@aibrahim-oai
aibrahim-oai marked this pull request as ready for review June 11, 2026 02:54
@aibrahim-oai
aibrahim-oai requested a review from a team as a code owner June 11, 2026 02:54

Copy link
Copy Markdown
Contributor Author

@codex review

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

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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67cd3d9a67

ℹ️ 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/tests/suite/compact.rs Outdated
Comment on lines +2415 to +2416
model_info_with_comp_hash(previous_model, "hash-a"),
model_info_with_comp_hash(next_model, "hash-b"),

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.

P2 Badge Add legacy resume coverage for missing comp_hash

This test seeds both the saved and target models with comp_hash values, so it misses legacy resumed rollouts where TurnContextItem.comp_hash is absent and the new path must compact once from None -> Some. Please add integration coverage for that behavior per guidance.

Useful? React with 👍 / 👎.

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

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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e31456182

ℹ️ 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/turn.rs Outdated
Comment on lines +804 to +808
let comp_hash_changed = previous_turn_settings
.comp_hash
.as_deref()
.zip(turn_context.comp_hash.as_deref())
.is_some_and(|(previous, current)| previous != current);

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.

P2 Badge Treat missing comp_hash as incompatible

When a user resumes a rollout written before comp_hash was persisted, previous_turn_settings.comp_hash is None while the current model metadata can now have Some(...); Option::zip makes that look unchanged, so the pre-turn compaction is skipped and the first upgraded turn can send history that was never compacted for the advertised compatibility hash. Fresh evidence: this version still gates the decision on Option::zip here, so None -> Some cannot trigger the one-time recovery compaction.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

@codex review

aibrahim-oai added a commit that referenced this pull request Jun 11, 2026
## Summary
- add optional `comp_hash` metadata to `ModelInfo`
- update `ModelInfo` fixtures for the shared schema change
- keep older model responses compatible by defaulting the field to
`None`

## Why
The models endpoint needs an opaque identifier for compaction-compatible
model configurations. This PR only exposes that value in model metadata;
it does not add it to turn context or change runtime behavior.

Follow-up #27520 carries the value through turn context and rollouts,
then uses it to trigger compaction.

## Stack
- based on #27115
- functionality follow-up: #27520

## Testing
- `just test -p codex-protocol
model_info_defaults_availability_nux_to_none_when_omitted`
- `just fix -p codex-core -p codex-protocol -p codex-analytics -p
codex-models-manager`
Base automatically changed from codex/add-comp-hash-model-info to codex/turn-sampling-phases June 11, 2026 03:31
@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-on-comp-hash-change branch from 9681a29 to 3cc928a Compare June 11, 2026 03:39
@aibrahim-oai
aibrahim-oai changed the base branch from codex/turn-sampling-phases to codex/add-comp-hash-model-info June 11, 2026 03:40
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

@codex review

aibrahim-oai added a commit that referenced this pull request Jun 11, 2026
## Summary
- add optional `comp_hash` metadata to `ModelInfo`
- update `ModelInfo` fixtures for the shared schema change
- keep older model responses compatible by defaulting the field to
`None`

## Why
The models endpoint needs an opaque identifier for compaction-compatible
model configurations. This PR only exposes that value in model metadata;
it does not add it to turn context or change runtime behavior.

Follow-up #27520 carries the value through turn context and rollouts,
then uses it to trigger compaction.

## Stack
- based directly on `main`
- replaces #27519, which was accidentally merged into the wrong base
branch
- functionality follow-up: #27520

## Testing
- `just test -p codex-protocol
model_info_defaults_availability_nux_to_none_when_omitted`
- `just fix -p codex-core -p codex-protocol -p codex-analytics -p
codex-models-manager`
Base automatically changed from codex/add-comp-hash-model-info to main June 11, 2026 03:42
@aibrahim-oai
aibrahim-oai enabled auto-merge (squash) June 11, 2026 03:43
@aibrahim-oai
aibrahim-oai merged commit ba4925b into main Jun 11, 2026
44 of 47 checks passed
@aibrahim-oai
aibrahim-oai deleted the codex/compact-on-comp-hash-change branch June 11, 2026 04:11
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 11, 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