Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions codex-rs/rollout/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,8 @@ async fn read_head_summary(path: &Path, head_limit: usize) -> io::Result<HeadTai
RolloutItem::Compacted(_) => {
// Not included in `head`; skip.
}
RolloutItem::EventMsg(ev) => {
if let EventMsg::UserMessage(user) = ev {
RolloutItem::EventMsg(ev) => match ev {
EventMsg::UserMessage(user) => {
summary.saw_user_event = true;
if summary.first_user_message.is_none() {
let message = strip_user_message_prefix(user.message.as_str()).to_string();
Expand All @@ -1140,7 +1140,17 @@ async fn read_head_summary(path: &Path, head_limit: usize) -> io::Result<HeadTai
}
}
}
}
EventMsg::ThreadGoalUpdated(event) => {
let objective = event.goal.objective.trim();
if !objective.is_empty() {
summary.saw_user_event = true;
if summary.first_user_message.is_none() {
summary.first_user_message = Some(objective.to_string());
}
}
}
_ => {}
},
}

if summary.saw_session_meta && summary.saw_user_event {
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/rollout/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn event_msg_persistence_mode(ev: &EventMsg) -> Option<EventPersistenceMode> {
| EventMsg::AgentReasoningRawContent(_)
| EventMsg::PatchApplyEnd(_)
| EventMsg::TokenCount(_)
| EventMsg::ThreadGoalUpdated(_)
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.

For the record, this won't backfill previous sessions but it's fine I guess

| EventMsg::ContextCompacted(_)
| EventMsg::EnteredReviewMode(_)
| EventMsg::ExitedReviewMode(_)
Expand Down Expand Up @@ -140,7 +141,6 @@ fn event_msg_persistence_mode(ev: &EventMsg) -> Option<EventPersistenceMode> {
| EventMsg::AgentReasoningSectionBreak(_)
| EventMsg::RawResponseItem(_)
| EventMsg::SessionConfigured(_)
| EventMsg::ThreadGoalUpdated(_)
| EventMsg::McpToolCallBegin(_)
| EventMsg::ExecCommandBegin(_)
| EventMsg::TerminalInteraction(_)
Expand Down
44 changes: 43 additions & 1 deletion codex-rs/state/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ pub fn apply_rollout_item(
pub fn rollout_item_affects_thread_metadata(item: &RolloutItem) -> bool {
match item {
RolloutItem::SessionMeta(_) | RolloutItem::TurnContext(_) => true,
RolloutItem::EventMsg(EventMsg::TokenCount(_) | EventMsg::UserMessage(_)) => true,
RolloutItem::EventMsg(
EventMsg::TokenCount(_) | EventMsg::UserMessage(_) | EventMsg::ThreadGoalUpdated(_),
) => true,
RolloutItem::EventMsg(_) | RolloutItem::ResponseItem(_) | RolloutItem::Compacted(_) => {
false
}
Expand Down Expand Up @@ -96,6 +98,14 @@ fn apply_event_msg(metadata: &mut ThreadMetadata, event: &EventMsg) {
}
}
}
EventMsg::ThreadGoalUpdated(event) => {
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.

Won't this have an impact on the title? If a reaul user message arrives after the goal, it will now look like a distinct title and start shwoing up as thread name
Maybe I'm wrong though, I can't repro

if metadata.first_user_message.is_none() {
let objective = event.goal.objective.trim();
if !objective.is_empty() {
metadata.first_user_message = Some(objective.to_string());
}
}
}
_ => {}
}
}
Expand Down Expand Up @@ -136,6 +146,7 @@ pub(crate) fn enum_to_string<T: Serialize>(value: &T) -> String {
#[cfg(test)]
mod tests {
use super::apply_rollout_item;
use super::rollout_item_affects_thread_metadata;
use crate::model::ThreadMetadata;
use chrono::DateTime;
use chrono::Utc;
Expand All @@ -151,6 +162,9 @@ mod tests {
use codex_protocol::protocol::SessionMeta;
use codex_protocol::protocol::SessionMetaLine;
use codex_protocol::protocol::SessionSource;
use codex_protocol::protocol::ThreadGoal;
use codex_protocol::protocol::ThreadGoalStatus;
use codex_protocol::protocol::ThreadGoalUpdatedEvent;
use codex_protocol::protocol::TurnContextItem;
use codex_protocol::protocol::USER_MESSAGE_BEGIN;
use codex_protocol::protocol::UserMessageEvent;
Expand Down Expand Up @@ -231,6 +245,34 @@ mod tests {
assert_eq!(metadata.title, "");
}

#[test]
fn event_msg_thread_goal_sets_first_user_message_preview() {
let mut metadata = metadata_for_test();
let item = RolloutItem::EventMsg(EventMsg::ThreadGoalUpdated(ThreadGoalUpdatedEvent {
thread_id: metadata.id,
turn_id: None,
goal: ThreadGoal {
thread_id: metadata.id,
objective: "optimize the benchmark".to_string(),
status: ThreadGoalStatus::Active,
token_budget: None,
tokens_used: 0,
time_used_seconds: 0,
created_at: 1,
updated_at: 1,
},
}));

assert!(rollout_item_affects_thread_metadata(&item));
apply_rollout_item(&mut metadata, &item, "test-provider");

assert_eq!(
metadata.first_user_message.as_deref(),
Some("optimize the benchmark")
);
assert_eq!(metadata.title, "");
}

#[test]
fn turn_context_does_not_override_session_cwd() {
let mut metadata = metadata_for_test();
Expand Down
Loading