mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Report turn retry and user wait timings
This commit is contained in:
@@ -407,6 +407,9 @@ fn sample_turn_profile() -> TurnProfile {
|
||||
after_last_sampling_ms: 134,
|
||||
sampling_request_count: 2,
|
||||
sampling_retry_count: 1,
|
||||
sampling_retry_delay_ms: 50,
|
||||
request_user_input_count: 1,
|
||||
request_user_input_wait_ms: 250,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3333,6 +3336,9 @@ fn turn_event_serializes_expected_shape() {
|
||||
after_last_sampling_ms: 134,
|
||||
sampling_request_count: 2,
|
||||
sampling_retry_count: 1,
|
||||
sampling_retry_delay_ms: 50,
|
||||
request_user_input_count: 1,
|
||||
request_user_input_wait_ms: 250,
|
||||
duration_ms: Some(1234),
|
||||
started_at: Some(455),
|
||||
completed_at: Some(456),
|
||||
@@ -3406,6 +3412,9 @@ fn turn_event_serializes_expected_shape() {
|
||||
"after_last_sampling_ms": 134,
|
||||
"sampling_request_count": 2,
|
||||
"sampling_retry_count": 1,
|
||||
"sampling_retry_delay_ms": 50,
|
||||
"request_user_input_count": 1,
|
||||
"request_user_input_wait_ms": 250,
|
||||
"duration_ms": 1234,
|
||||
"started_at": 455,
|
||||
"completed_at": 456
|
||||
|
||||
@@ -824,6 +824,9 @@ pub(crate) struct CodexTurnEventParams {
|
||||
pub(crate) after_last_sampling_ms: u64,
|
||||
pub(crate) sampling_request_count: u32,
|
||||
pub(crate) sampling_retry_count: u32,
|
||||
pub(crate) sampling_retry_delay_ms: u64,
|
||||
pub(crate) request_user_input_count: u32,
|
||||
pub(crate) request_user_input_wait_ms: u64,
|
||||
pub(crate) duration_ms: Option<u64>,
|
||||
pub(crate) started_at: Option<u64>,
|
||||
pub(crate) completed_at: Option<u64>,
|
||||
|
||||
@@ -113,6 +113,9 @@ pub struct TurnProfile {
|
||||
pub after_last_sampling_ms: u64,
|
||||
pub sampling_request_count: u32,
|
||||
pub sampling_retry_count: u32,
|
||||
pub sampling_retry_delay_ms: u64,
|
||||
pub request_user_input_count: u32,
|
||||
pub request_user_input_wait_ms: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -2433,6 +2433,9 @@ fn codex_turn_event_params(
|
||||
after_last_sampling_ms,
|
||||
sampling_request_count,
|
||||
sampling_retry_count,
|
||||
sampling_retry_delay_ms,
|
||||
request_user_input_count,
|
||||
request_user_input_wait_ms,
|
||||
} = profile;
|
||||
let token_usage = turn_state.token_usage.clone();
|
||||
let codex_error = turn_state.codex_error.as_ref();
|
||||
@@ -2503,6 +2506,9 @@ fn codex_turn_event_params(
|
||||
after_last_sampling_ms,
|
||||
sampling_request_count,
|
||||
sampling_retry_count,
|
||||
sampling_retry_delay_ms,
|
||||
request_user_input_count,
|
||||
request_user_input_wait_ms,
|
||||
duration_ms: completed.duration_ms,
|
||||
started_at,
|
||||
completed_at: Some(completed.completed_at),
|
||||
|
||||
@@ -942,6 +942,9 @@ async fn turn_start_tracks_turn_event_analytics() -> Result<()> {
|
||||
"toolBlockingMs": params["tool_blocking_ms"],
|
||||
"samplingRequestCount": params["sampling_request_count"],
|
||||
"samplingRetryCount": params["sampling_retry_count"],
|
||||
"samplingRetryDelayIsPositive": params["sampling_retry_delay_ms"]
|
||||
.as_u64()
|
||||
.is_some_and(|duration| duration > 0),
|
||||
"responseRequestCount": response_mock.requests().len(),
|
||||
}),
|
||||
json!({
|
||||
@@ -949,6 +952,7 @@ async fn turn_start_tracks_turn_event_analytics() -> Result<()> {
|
||||
"toolBlockingMs": 0,
|
||||
"samplingRequestCount": 2,
|
||||
"samplingRetryCount": 1,
|
||||
"samplingRetryDelayIsPositive": true,
|
||||
"responseRequestCount": 2,
|
||||
})
|
||||
);
|
||||
@@ -1047,12 +1051,18 @@ async fn turn_profile_tracks_blocking_tool_and_follow_up_sampling() -> Result<()
|
||||
.is_some_and(|duration| duration > 0),
|
||||
"samplingRequestCount": params["sampling_request_count"],
|
||||
"samplingRetryCount": params["sampling_retry_count"],
|
||||
"requestUserInputCount": params["request_user_input_count"],
|
||||
"requestUserInputWaitIsPositive": params["request_user_input_wait_ms"]
|
||||
.as_u64()
|
||||
.is_some_and(|duration| duration > 0),
|
||||
"status": params["status"],
|
||||
}),
|
||||
json!({
|
||||
"toolBlockingIsPositive": true,
|
||||
"samplingRequestCount": 2,
|
||||
"samplingRetryCount": 0,
|
||||
"requestUserInputCount": 1,
|
||||
"requestUserInputWaitIsPositive": true,
|
||||
"status": "completed",
|
||||
})
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Shared retry and transport fallback decisions for Responses requests.
|
||||
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::client::ModelClientSession;
|
||||
use crate::session::session::Session;
|
||||
@@ -42,6 +43,11 @@ pub(crate) async fn handle_retryable_response_stream_error(
|
||||
)
|
||||
.await;
|
||||
*retries = 0;
|
||||
if matches!(request, ResponsesStreamRequest::Sampling) {
|
||||
turn_context
|
||||
.turn_timing_state
|
||||
.record_sampling_retry(Duration::ZERO);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -71,7 +77,13 @@ pub(crate) async fn handle_retryable_response_stream_error(
|
||||
)
|
||||
.await;
|
||||
}
|
||||
let retry_delay_started_at = Instant::now();
|
||||
tokio::time::sleep(delay).await;
|
||||
if matches!(request, ResponsesStreamRequest::Sampling) {
|
||||
turn_context
|
||||
.turn_timing_state
|
||||
.record_sampling_retry(retry_delay_started_at.elapsed());
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicU64;
|
||||
use std::time::Instant;
|
||||
use std::time::SystemTime;
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
@@ -2352,7 +2353,12 @@ impl Session {
|
||||
.turn_metadata_state
|
||||
.mark_user_input_requested_during_turn();
|
||||
self.send_event(turn_context, event).await;
|
||||
rx_response.await.ok()
|
||||
let wait_started_at = Instant::now();
|
||||
let response = rx_response.await.ok();
|
||||
turn_context
|
||||
.turn_timing_state
|
||||
.record_request_user_input_wait(wait_started_at.elapsed());
|
||||
response
|
||||
}
|
||||
|
||||
#[expect(
|
||||
|
||||
@@ -1088,7 +1088,6 @@ async fn run_sampling_request(
|
||||
ResponsesStreamRequest::Sampling,
|
||||
)
|
||||
.await?;
|
||||
turn_context.turn_timing_state.record_sampling_retry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ struct TurnProfileState {
|
||||
pending_idle_after_sampling: Duration,
|
||||
sampling_request_count: u32,
|
||||
sampling_retry_count: u32,
|
||||
sampling_retry_delay: Duration,
|
||||
request_user_input_count: u32,
|
||||
request_user_input_wait: Duration,
|
||||
completed_profile: Option<TurnProfile>,
|
||||
}
|
||||
|
||||
@@ -127,8 +130,13 @@ impl TurnTimingState {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn record_sampling_retry(&self) {
|
||||
self.profile_state().record_sampling_retry();
|
||||
pub(crate) fn record_sampling_retry(&self, delay: Duration) {
|
||||
self.profile_state().record_sampling_retry(delay);
|
||||
}
|
||||
|
||||
pub(crate) fn record_request_user_input_wait(&self, duration: Duration) {
|
||||
self.profile_state()
|
||||
.record_request_user_input_wait(duration);
|
||||
}
|
||||
|
||||
pub(crate) fn begin_tool_blocking(self: &Arc<Self>) -> TurnProfileTimingGuard {
|
||||
@@ -217,9 +225,17 @@ impl TurnProfileState {
|
||||
true
|
||||
}
|
||||
|
||||
fn record_sampling_retry(&mut self) {
|
||||
fn record_sampling_retry(&mut self, delay: Duration) {
|
||||
if self.completed_profile.is_none() && self.started_at.is_some() {
|
||||
self.sampling_retry_count = self.sampling_retry_count.saturating_add(1);
|
||||
self.sampling_retry_delay = self.sampling_retry_delay.saturating_add(delay);
|
||||
}
|
||||
}
|
||||
|
||||
fn record_request_user_input_wait(&mut self, duration: Duration) {
|
||||
if self.completed_profile.is_none() && self.started_at.is_some() {
|
||||
self.request_user_input_count = self.request_user_input_count.saturating_add(1);
|
||||
self.request_user_input_wait = self.request_user_input_wait.saturating_add(duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,6 +293,9 @@ impl TurnProfileState {
|
||||
after_last_sampling_ms: duration_to_u64_ms(after_last_sampling),
|
||||
sampling_request_count: self.sampling_request_count,
|
||||
sampling_retry_count: self.sampling_retry_count,
|
||||
sampling_retry_delay_ms: duration_to_u64_ms(self.sampling_retry_delay),
|
||||
request_user_input_count: self.request_user_input_count,
|
||||
request_user_input_wait_ms: duration_to_u64_ms(self.request_user_input_wait),
|
||||
};
|
||||
let total_ms = self
|
||||
.started_at
|
||||
|
||||
@@ -167,7 +167,8 @@ fn turn_profile_breaks_down_sampling_blocking_and_retry_overhead() {
|
||||
started_at + Duration::from_millis(900),
|
||||
TurnProfilePhase::ToolBlocking,
|
||||
);
|
||||
state.record_sampling_retry();
|
||||
state.record_sampling_retry(Duration::from_millis(50));
|
||||
state.record_request_user_input_wait(Duration::from_millis(250));
|
||||
let _ = state.begin_sampling(started_at + Duration::from_millis(1_000));
|
||||
state.end_phase(
|
||||
started_at + Duration::from_millis(1_200),
|
||||
@@ -184,6 +185,9 @@ fn turn_profile_breaks_down_sampling_blocking_and_retry_overhead() {
|
||||
after_last_sampling_ms: 100,
|
||||
sampling_request_count: 2,
|
||||
sampling_retry_count: 1,
|
||||
sampling_retry_delay_ms: 50,
|
||||
request_user_input_count: 1,
|
||||
request_user_input_wait_ms: 250,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user