mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Merge branch 'rhan/oob-turn-metadata' into rhan/oob-queue
This commit is contained in:
@@ -46,6 +46,7 @@ pub(crate) struct CodexTurnEvent {
|
||||
pub(crate) collaboration_mode: ModeKind,
|
||||
pub(crate) personality: Option<Personality>,
|
||||
pub(crate) num_input_images: usize,
|
||||
pub(crate) is_first_turn: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn build_track_events_context(
|
||||
@@ -412,6 +413,7 @@ struct CodexTurnEventParams {
|
||||
collaboration_mode: Option<&'static str>,
|
||||
personality: Option<String>,
|
||||
num_input_images: usize,
|
||||
is_first_turn: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -768,6 +770,7 @@ fn codex_turn_event_params(
|
||||
collaboration_mode: Some(collaboration_mode_mode(turn_event.collaboration_mode)),
|
||||
personality: personality_mode(turn_event.personality),
|
||||
num_input_images: turn_event.num_input_images,
|
||||
is_first_turn: turn_event.is_first_turn,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,6 +221,7 @@ fn turn_event_serializes_expected_shape() {
|
||||
collaboration_mode: ModeKind::Plan,
|
||||
personality: Some(Personality::Pragmatic),
|
||||
num_input_images: 2,
|
||||
is_first_turn: true,
|
||||
},
|
||||
),
|
||||
});
|
||||
@@ -247,7 +248,8 @@ fn turn_event_serializes_expected_shape() {
|
||||
"sandbox_network_access": true,
|
||||
"collaboration_mode": "plan",
|
||||
"personality": "pragmatic",
|
||||
"num_input_images": 2
|
||||
"num_input_images": 2,
|
||||
"is_first_turn": true
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ pub(crate) struct SessionState {
|
||||
pub(crate) active_connector_selection: HashSet<String>,
|
||||
pub(crate) pending_session_start_source: Option<codex_hooks::SessionStartSource>,
|
||||
granted_permissions: Option<PermissionProfile>,
|
||||
next_turn_is_first: bool,
|
||||
}
|
||||
|
||||
impl SessionState {
|
||||
@@ -51,6 +52,7 @@ impl SessionState {
|
||||
active_connector_selection: HashSet::new(),
|
||||
pending_session_start_source: None,
|
||||
granted_permissions: None,
|
||||
next_turn_is_first: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +75,16 @@ impl SessionState {
|
||||
self.previous_turn_settings = previous_turn_settings;
|
||||
}
|
||||
|
||||
pub(crate) fn set_next_turn_is_first(&mut self, value: bool) {
|
||||
self.next_turn_is_first = value;
|
||||
}
|
||||
|
||||
pub(crate) fn take_next_turn_is_first(&mut self) -> bool {
|
||||
let is_first_turn = self.next_turn_is_first;
|
||||
self.next_turn_is_first = false;
|
||||
is_first_turn
|
||||
}
|
||||
|
||||
pub(crate) fn clone_history(&self) -> ContextManager {
|
||||
self.history.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user