Merge branch 'rhan/oob-turn-metadata' into rhan/oob-queue

This commit is contained in:
rhan-oai
2026-03-25 13:52:56 -07:00
committed by GitHub
6 changed files with 152 additions and 1 deletions
+22
View File
@@ -173,6 +173,7 @@ use crate::config::types::McpServerConfig;
use crate::config::types::ShellEnvironmentPolicy;
use crate::context_manager::ContextManager;
use crate::context_manager::TotalTokenUsageBreakdown;
use crate::context_manager::is_user_turn_boundary;
use crate::environment_context::EnvironmentContext;
use crate::error::CodexErr;
use crate::error::Result as CodexResult;
@@ -785,6 +786,17 @@ pub(crate) fn session_loop_termination_from_handle(
.shared()
}
fn initial_history_has_prior_user_turns(conversation_history: &InitialHistory) -> bool {
conversation_history.scan_rollout_items(rollout_item_is_user_turn_boundary)
}
fn rollout_item_is_user_turn_boundary(item: &RolloutItem) -> bool {
match item {
RolloutItem::ResponseItem(item) => is_user_turn_boundary(item),
_ => false,
}
}
/// Context for an initialized model agent
///
/// A session has at most 1 running task at a time, and can be interrupted by user input.
@@ -2159,6 +2171,11 @@ impl Session {
SessionSource::SubAgent(_)
)
};
let has_prior_user_turns = initial_history_has_prior_user_turns(&conversation_history);
{
let mut state = self.state.lock().await;
state.set_next_turn_is_first(!has_prior_user_turns);
}
match conversation_history {
InitialHistory::New => {
// Defer initial context insertion until the first real turn starts so
@@ -6020,6 +6037,10 @@ pub(crate) async fn run_turn(
let submission_type = turn_context
.submission_type
.unwrap_or(SubmissionType::Prompt);
let is_first_turn = {
let mut state = sess.state.lock().await;
state.take_next_turn_is_first()
};
sess.services.analytics_events_client.track_turn_event(
tracking,
CodexTurnEvent {
@@ -6040,6 +6061,7 @@ pub(crate) async fn run_turn(
matches!(item, UserInput::Image { .. } | UserInput::LocalImage { .. })
})
.count(),
is_first_turn,
},
);
}