Unify rollout reconstruction with resume/fork TurnContext hydration#12612
Unify rollout reconstruction with resume/fork TurnContext hydration#12612charley-oai wants to merge 42 commits intomainfrom
Conversation
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 859ea16a31
ℹ️ 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".
|
Security review completed. No security issues were found in this pull request. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d4efe495b
ℹ️ 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".
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1ab8c7d01
ℹ️ 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".
|
@codex review this |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9506d61000
ℹ️ 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".
|
@codex review this |
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
codex-rs/core/src/codex.rs
Outdated
| } | ||
| RolloutItem::EventMsg(EventMsg::ThreadRolledBack(rollback)) => { | ||
| history.drop_last_n_user_turns(rollback.num_turns); | ||
| let mut turns_to_drop = |
There was a problem hiding this comment.
a bit strange to run two version of this logic in parallel, one to drop user messages, another to drop turns
There was a problem hiding this comment.
I think we can't unify them because history only contains model-visible data whereas our stack of user turns contains metadata needed to fetch previous_model and reference_context_item
| let push_replayed_turn = |replayed_segments: &mut Vec<RolloutReplayMetaSegment>, | ||
| active_turn: ActiveRolloutTurn| { | ||
| replayed_segments.push(RolloutReplayMetaSegment::Turn(Box::new( | ||
| ReplayedRolloutTurn { |
There was a problem hiding this comment.
we are copying the struct into almost the same struct ActiveRolloutTurn -- >ReplayedRolloutTurn.
There was a problem hiding this comment.
The conversion serves to eliminate dead/unused fields
- dropping turn_id, which is only needed while matching lifecycle events
- dropping saw_user_message, which is only needed to decide whether the span counts as a user turn at all
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: acec761d88
ℹ️ 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".
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06f8e6b316
ℹ️ 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".
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37cacb2dab
ℹ️ 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".
|
@codex review this |
|
Codex Review: Didn't find any major issues. Delightful! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
258153b to
ff322b4
Compare
Summary
This PR unifies rollout history reconstruction and resume/fork metadata hydration under a single
reconstruct_history_from_rolloutimplementation.The current shape is intentionally eager and simple:
previous_modelandreference_context_itemin the same reconstruction passlast_rollout_regular_turn_context_lookupscanRolloutReconstructionThe replay code now stays focused on the part we want to keep eager long-term:
previous_modelreference_context_itemIt does not try to introduce lazy/reverse history loading yet.
What Changed
Unified replay output
reconstruct_history_from_rolloutnow returns:historyprevious_modelreference_context_itemResume and fork use that output directly instead of doing a second bespoke rollout traversal.
Simpler replay shape
The reconstruction logic in
codex-rs/core/src/codex/rollout_reconstruction.rswas simplified back to an eager forward replay.That removed the temporary reverse/tail-scan scaffolding and keeps the implementation closer to mainline behavior while still unifying metadata accounting with history replay.
TurnContext persistence contract
TurnContextItempersistence is now treated as the replay source of truth for eager resume metadata.The important behavior is:
TurnContextItemso resume can recoverprevious_modelTurnContextItemTurnContextItemThat last case matters for resume after compaction: otherwise replay can keep an older
previous_model, which causes bad model-mismatch warnings and duplicate<model_switch>injections.Behavior Preserved
drop_last_n_user_turnsreference_context_itembut still allowsprevious_modelto come from the last surviving user turnTests
Targeted validation run:
cargo test -p codex-core reconstruct_history_rollback_ --libcargo test -p codex-core record_initial_history_resumed_ --libcargo test -p codex-core record_context_updates_and_set_reference_context_item_persists_full_reinjection_to_rollout --libcargo test -p codex-core record_context_updates_and_set_reference_context_item_updates_baseline_without_emitting_diffs --libcargo test -p codex-core --test all suite::resume::resume_switches_models_preserves_base_instructions -- --nocapturecargo test -p codex-core --test all suite::resume::resume_model_switch_is_not_duplicated_after_pre_turn_override -- --nocapturecargo test -p codex-coretools::js_repl::tests::js_repl_can_attach_image_via_view_image_tooljust fmtjust fix -p codex-corePer repo workflow, tests were not rerun after the final
fmt/fixstep.