Repository navigation
fork conversation from a previous message - #2575
Conversation
There was a problem hiding this comment.
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".
| // 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) |
There was a problem hiding this comment.
[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 👍 / 👎.
There was a problem hiding this comment.
The client can make sure the config is overiden correctly
| /// 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() |
There was a problem hiding this comment.
[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 👍 / 👎.
4aa2a92 to
682ec7f
Compare
1300e24 to
22b8377
Compare
5980798 to
682ec7f
Compare
bolinfest
left a comment
There was a problem hiding this comment.
Questions on naming and code organization.
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