mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Add turn profiling analytics (#26484)
## Summary Add flat profiling fields to `codex_turn_event` so analytics can explain where turn wall-clock time is spent without changing tool execution behavior. The profile reports: - time before the first sampling request - sampling time across all attempts and follow-ups - overhead between sampling requests - time blocked in the post-sampling tool drain - time after the final sampling request - sampling request and retry counts ## Implementation - Extend the existing turn timing state with constant-memory phase accounting and one RAII phase guard. - Observe sampling and the existing post-sampling drain only at turn orchestration boundaries. - Keep tool runtime, tool futures, response item handling, and turn lifecycle values unchanged. - Add the profiling fields directly to the existing analytics turn event without changing app-server protocol or rollout persistence. - Use the existing turn `status` to distinguish completed, failed, and interrupted profiles. Exact sampling/tool overlap is intentionally omitted because measuring tool completion accurately would require hooks in the tool execution path. ## Validation - Add app-server end-to-end coverage for a single-sampling turn with no blocking tool work. - Add app-server end-to-end coverage for `request_user_input` blocking followed by a second sampling request. - CI is running on the PR; tests were not executed locally per repository guidance.
This commit is contained in:
committed by
GitHub
Unverified
parent
82b15b65e2
commit
8d72fb6de9
@@ -1088,6 +1088,7 @@ async fn run_sampling_request(
|
||||
ResponsesStreamRequest::Sampling,
|
||||
)
|
||||
.await?;
|
||||
turn_context.turn_timing_state.record_sampling_retry();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1800,6 +1801,7 @@ async fn try_run_sampling_request(
|
||||
turn_context.model_info.slug.as_str(),
|
||||
turn_context.provider.info().name.as_str(),
|
||||
);
|
||||
let sampling_timing_guard = turn_context.turn_timing_state.begin_sampling();
|
||||
let mut stream = client_session
|
||||
.stream(
|
||||
prompt,
|
||||
@@ -2213,6 +2215,7 @@ async fn try_run_sampling_request(
|
||||
}
|
||||
}
|
||||
};
|
||||
drop(sampling_timing_guard);
|
||||
|
||||
flush_assistant_text_segments_all(
|
||||
&sess,
|
||||
@@ -2222,7 +2225,13 @@ async fn try_run_sampling_request(
|
||||
)
|
||||
.await;
|
||||
|
||||
let tool_blocking_timing_guard = if in_flight.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(turn_context.turn_timing_state.begin_tool_blocking())
|
||||
};
|
||||
drain_in_flight(&mut in_flight, sess.clone(), turn_context.clone()).await?;
|
||||
drop(tool_blocking_timing_guard);
|
||||
|
||||
if should_emit_token_count {
|
||||
// A tool call such as request_user_input can intentionally pause the turn. Emit token
|
||||
|
||||
Reference in New Issue
Block a user