mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
## Why The `incomplete` status alone gives no indication of which timing dependency was missing or which operation prevented capture. ## What changed Emit deduplicated `critical_path_incomplete_reasons` in turn analytics for incomplete captures. Reasons cover unsupported Code Mode and agent operations, unattributed reviews and user waits, missing turn starts, and forced teardown, with an `unclassified` fallback. External tools that share a built-in name can still invalidate capture without being classified as the built-in operation. During interruption, use the task's join result to distinguish forced teardown from normal completion so a task that already finished can still report a complete path. ## Testing Add coverage for analytics serialization, concurrent reason deduplication, tool name collisions, and interrupted tasks that finish normally or require forced teardown. GitOrigin-RevId: fab9aa1ff881997a34dcf75adc5638133cedc7fe
104 lines
3.9 KiB
Rust
104 lines
3.9 KiB
Rust
//! Turn critical-path facts and their nullable analytics fields.
|
|
//! Missing capture never becomes a zero-duration measurement.
|
|
|
|
use serde::Serialize;
|
|
|
|
/// Reasons a turn's critical path could not be measured.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum IncompleteReason {
|
|
CodeModeUnsupported,
|
|
UnsupportedOperation,
|
|
MissingTurnStart,
|
|
UnattributedReview,
|
|
UnattributedUserWait,
|
|
ForcedTeardown,
|
|
Unclassified,
|
|
}
|
|
|
|
/// Capture coverage for one finalized turn, independent of its completion status.
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
|
|
pub enum TurnCriticalPath {
|
|
#[default]
|
|
Disabled,
|
|
Incomplete(Vec<IncompleteReason>),
|
|
Complete(TurnCriticalPathDurations),
|
|
}
|
|
|
|
impl TurnCriticalPath {
|
|
pub fn status(&self) -> &'static str {
|
|
match self {
|
|
Self::Disabled => "disabled",
|
|
Self::Incomplete(_) => "incomplete",
|
|
Self::Complete(_) => "complete",
|
|
}
|
|
}
|
|
|
|
pub fn durations(&self) -> Option<&TurnCriticalPathDurations> {
|
|
match self {
|
|
Self::Complete(durations) => Some(durations),
|
|
Self::Disabled | Self::Incomplete(_) => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Category totals over the server turn interval, truncated to milliseconds.
|
|
/// Inference is the compatibility total of sampling and compaction, not another leaf.
|
|
/// Independent truncation can leave the seven leaf categories up to six milliseconds
|
|
/// below duration_ms, and sampling_ms + compaction_ms up to one below inference_ms.
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
|
pub struct TurnCriticalPathDurations {
|
|
pub duration_ms: u64,
|
|
pub inference_ms: u64,
|
|
pub sampling_ms: u64,
|
|
pub compaction_ms: u64,
|
|
pub auto_review_ms: u64,
|
|
/// Portion of auto_review_ms outside observed Guardian turn execution; not additive.
|
|
pub auto_review_overhead_ms: Option<u64>,
|
|
pub user_wait_ms: u64,
|
|
pub tools_ms: u64,
|
|
pub overhead_ms: u64,
|
|
pub unknown_ms: u64,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub(crate) struct CriticalPathEventParams {
|
|
critical_path_status: &'static str,
|
|
critical_path_duration_ms: Option<u64>,
|
|
critical_path_inference_ms: Option<u64>,
|
|
critical_path_sampling_ms: Option<u64>,
|
|
critical_path_compaction_ms: Option<u64>,
|
|
critical_path_auto_review_ms: Option<u64>,
|
|
critical_path_auto_review_overhead_ms: Option<u64>,
|
|
critical_path_user_wait_ms: Option<u64>,
|
|
critical_path_tools_ms: Option<u64>,
|
|
critical_path_overhead_ms: Option<u64>,
|
|
critical_path_unknown_ms: Option<u64>,
|
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
|
critical_path_incomplete_reasons: Vec<IncompleteReason>,
|
|
}
|
|
|
|
impl From<TurnCriticalPath> for CriticalPathEventParams {
|
|
fn from(path: TurnCriticalPath) -> Self {
|
|
let durations = path.durations();
|
|
Self {
|
|
critical_path_status: path.status(),
|
|
critical_path_duration_ms: durations.map(|value| value.duration_ms),
|
|
critical_path_inference_ms: durations.map(|value| value.inference_ms),
|
|
critical_path_sampling_ms: durations.map(|value| value.sampling_ms),
|
|
critical_path_compaction_ms: durations.map(|value| value.compaction_ms),
|
|
critical_path_auto_review_ms: durations.map(|value| value.auto_review_ms),
|
|
critical_path_auto_review_overhead_ms: durations
|
|
.and_then(|value| value.auto_review_overhead_ms),
|
|
critical_path_user_wait_ms: durations.map(|value| value.user_wait_ms),
|
|
critical_path_tools_ms: durations.map(|value| value.tools_ms),
|
|
critical_path_overhead_ms: durations.map(|value| value.overhead_ms),
|
|
critical_path_unknown_ms: durations.map(|value| value.unknown_ms),
|
|
critical_path_incomplete_reasons: match path {
|
|
TurnCriticalPath::Incomplete(reasons) => reasons,
|
|
TurnCriticalPath::Disabled | TurnCriticalPath::Complete(_) => Vec::new(),
|
|
},
|
|
}
|
|
}
|
|
}
|