Skip to content

Conversation

@owenlin0
Copy link
Contributor

@owenlin0 owenlin0 commented Nov 18, 2025

This PR allows clients to render historical messages when resuming a thread via thread/resume by reading from the list of EventMsg payloads loaded from the rollout, and then transforming them into Turns and ThreadItems to be returned on the Thread object.

This is implemented by leveraging SessionConfiguredNotification which returns this list of EventMsg objects when resuming a conversation, and then applying a stateful ThreadHistoryBuilder that parses from this EventMsg log and transforms it into Turns and ThreadItems.

Note that we only persist a subset of EventMsgs in a rollout as defined in policy.rs, so we lose fidelity whenever we resume a thread compared to when we streamed the thread's turns originally. However, this behavior is at parity with the legacy API.

@owenlin0 owenlin0 force-pushed the owen/return_items_on_thread_resume branch 3 times, most recently from ad05a7f to 4f4d6ff Compare November 18, 2025 22:57
@owenlin0 owenlin0 marked this pull request as ready for review November 18, 2025 23:01
@owenlin0
Copy link
Contributor Author

@codex review this

Copy link
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.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 58 to 60
EventMsg::TokenCount(_) => true,
EventMsg::EnteredReviewMode(_) => true,
EventMsg::ExitedReviewMode(_) => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge Capture review events in thread history

When a session entered review mode before being persisted, should_persist_event_msg records both EnteredReviewMode and ExitedReviewMode events in the rollout, but ThreadHistoryBuilder::handle_event just returns true for those variants without emitting any ThreadItem. As a result, resuming a thread that contains a completed review will produce thread.turns with the entire review interaction missing, so clients cannot render the prior review turn even though the data was recorded in the rollout. This affects any thread/resume response for threads that used review mode.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is explicit - we need a bit more thought on how to represent review mode and will handle this as a followup

Copy link
Collaborator

@bolinfest bolinfest left a comment

Choose a reason for hiding this comment

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

Thanks for doing this: this is a big blocker for the v1-v2 upgrade!

I'm biased but I think ideally #6847 would land first :P


/// This function should handle all EventMsg variants that can be persisted in a rollout file.
/// See `should_persist_event_msg` in `codex-rs/core/rollout/policy.rs`.
fn handle_event(&mut self, event: &EventMsg) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maintaining this bool return value feels like quite a bit of work. I feel like it's mainly for the benefit of the tests internally, so it's not clear to me that it's worth it, but I'll defer to you whether you think it helps ensure correctness of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah feels annoying, removed!

/// Only populated on a `thread/resume` response for now. For all other
/// responses and notifications returning a Thread, the turns field
/// will be an empty list.
pub turns: Vec<Turn>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this should live on Thread. We should not feel obligated to load the full list of items for a thread/list request, for example.

Building on #6847, I think this should go on ThreadResumeResponse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For turns I think it'd be nice to follow the include pattern in the future, if we wanted to: https://platform.openai.com/docs/api-reference/responses/create#responses_create-include

so by default we don't return Turns on thread/list which I agree we shouldn't do (unless the client specifically asked for it)


let thread = match read_summary_from_rollout(
session_configured.rollout_path.as_path(),
let mut thread = match read_summary_from_rollout(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be able to drop the mut with #6847.

@owenlin0 owenlin0 force-pushed the owen/return_items_on_thread_resume branch 2 times, most recently from b13567e to 7c7ce49 Compare November 19, 2025 05:31
@owenlin0 owenlin0 enabled auto-merge (squash) November 19, 2025 15:43
@owenlin0 owenlin0 force-pushed the owen/return_items_on_thread_resume branch from 554705f to b776b18 Compare November 19, 2025 15:44
@owenlin0 owenlin0 merged commit 1924500 into main Nov 19, 2025
25 checks passed
@owenlin0 owenlin0 deleted the owen/return_items_on_thread_resume branch November 19, 2025 15:58
@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2025
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.

3 participants