Skip to content

fork conversation from a previous message - #2575

Merged
aibrahim-oai merged 8 commits into
mainfrom
new_conversation
Aug 23, 2025
Merged

aibrahim-oai merged 8 commits into
mainfrom
new_conversation

Conversation

@aibrahim-oai

@aibrahim-oai aibrahim-oai commented Aug 22, 2025 •

Copy link
Copy Markdown
Contributor

This can be the underlying logic in order to start a conversation from a previous message. will need some love in the UI.

Base for building this: #2588

@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 suggestions.

Reply with @codex fix comments to fix any unresolved comments.

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, or 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 fix this CI failure" or "@codex address that feedback".

Comment on lines +412 to +432
// Derive config from overrides (or defaults) for the new conversation.
let new_conv_params = overrides.unwrap_or_default();
let config = match derive_config_from_params(
new_conv_params,
self.codex_linux_sandbox_exe.clone(),
) {
Ok(config) => config,
Err(err) => {
let error = JSONRPCErrorError {
code: INVALID_REQUEST_ERROR_CODE,
message: format!("error deriving config: {err}"),
data: None,
};
self.outgoing.send_error(request_id, error).await;
return;
}
};

match self
.conversation_manager
.fork_conversation(conversation_id.0, drop_last_messages, config)

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] Preserve base settings when forking conversations

In process_fork_conversation the config for the new session is built from overrides.unwrap_or_default() and derive_config_from_params (codex_message_processor.rs:412-433). No attempt is made to read the existing conversation's configuration, even though ForkConversationParams promises the fork keeps prior settings. When overrides are absent the forked session uses server defaults, potentially switching model or sandbox unexpectedly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The client can make sure the config is overiden correctly

Comment on lines +149 to +178
/// Return a prefix of `items` obtained by dropping the last `n` user messages
/// and all items that follow them.
fn truncate_after_dropping_last_messages(
items: Vec<crate::models::ResponseItem>,
n: usize,
) -> Vec<crate::models::ResponseItem> {
if n == 0 || items.is_empty() {
return items;
}

// Walk backwards counting only `user` Message items, find cut index.
let mut count = 0usize;
let mut cut_index = 0usize;
for (idx, item) in items.iter().enumerate().rev() {
if let crate::models::ResponseItem::Message { role, .. } = item
&& role == "user"
{
count += 1;
if count == n {
// Cut everything from this user message to the end.
cut_index = idx;
break;
}
}
}
if count < n {
// If fewer than n messages exist, drop everything.
return Vec::new();
}
items.into_iter().take(cut_index).collect()

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] Truncation ignores trailing assistant messages

truncate_after_dropping_last_messages counts only user messages when deciding where to cut history (conversation_manager.rs:149-179). The protocol docs state drop_last_messages should remove the last N user or assistant messages (mcp_protocol.rs:169-172). If the conversation ends with an assistant reply, requesting to drop one message deletes the preceding user turn as well, yielding a fork starting earlier than intended.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's ok

Comment thread codex-rs/core/src/codex.rs Resolved
Comment thread codex-rs/core/src/codex.rs Resolved
@aibrahim-oai
aibrahim-oai changed the base branch from main to move_models August 22, 2025 21:11
@aibrahim-oai
aibrahim-oai changed the base branch from move_models to main August 22, 2025 22:06
@aibrahim-oai
aibrahim-oai changed the base branch from main to move_models August 22, 2025 22:15
@aibrahim-oai
aibrahim-oai changed the base branch from move_models to main August 22, 2025 22:15
@aibrahim-oai
aibrahim-oai requested a review from bolinfest August 22, 2025 22:23

@bolinfest bolinfest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Questions on naming and code organization.

Comment thread codex-rs/core/src/codex.rs Resolved
Comment thread codex-rs/core/src/codex.rs Resolved
Comment thread codex-rs/protocol/src/protocol.rs Resolved
Comment thread codex-rs/protocol/src/protocol.rs Resolved
@aibrahim-oai
aibrahim-oai requested a review from bolinfest August 22, 2025 23:51
@aibrahim-oai
aibrahim-oai merged commit 311ad0c into main Aug 23, 2025
@aibrahim-oai
aibrahim-oai deleted the new_conversation branch August 23, 2025 00:06
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 23, 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.

2 participants