Report why turn critical path capture is incomplete (#62357)

## 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
This commit is contained in:
akak-oai
2026-11-18 20:29:59 +00:00
committed by copyberry
parent 513577302a
commit ed9becd2fc
17 changed files with 279 additions and 96 deletions
+1
View File
@@ -83,6 +83,7 @@ pub use guardian_v2::GuardianV2EventKind;
pub use product_attribution::ThreadProductUpdate;
pub use thread_hint::ThreadHintStatus;
pub use thread_hint::ThreadHintStatusEvent;
pub use turn_critical_path::IncompleteReason;
pub use turn_critical_path::TurnCriticalPath;
pub use turn_critical_path::TurnCriticalPathDurations;
@@ -1023,6 +1023,7 @@ async fn turn_completed_without_started_notification_emits_null_started_at() {
#[tokio::test]
async fn critical_path_payload_preserves_capture_status_and_emits_once() {
use crate::IncompleteReason;
use crate::TurnCriticalPath;
use crate::TurnCriticalPathDurations;
use crate::TurnProfileFact;
@@ -1032,15 +1033,19 @@ async fn critical_path_payload_preserves_capture_status_and_emits_once() {
AppServerTurnStatus::Completed,
AppServerTurnStatus::Interrupted,
] {
for (critical_path, expected) in [
for (critical_path, expected, expected_reasons) in [
(
TurnCriticalPath::Disabled,
json!([
"disabled", null, null, null, null, null, null, null, null, null
]),
None,
),
(
TurnCriticalPath::Incomplete,
TurnCriticalPath::Incomplete(vec![
IncompleteReason::CodeModeUnsupported,
IncompleteReason::UnattributedUserWait,
]),
json!([
"incomplete",
null,
@@ -1053,6 +1058,7 @@ async fn critical_path_payload_preserves_capture_status_and_emits_once() {
null,
null
]),
Some(json!(["code_mode_unsupported", "unattributed_user_wait"])),
),
(
TurnCriticalPath::Complete(TurnCriticalPathDurations {
@@ -1068,6 +1074,7 @@ async fn critical_path_payload_preserves_capture_status_and_emits_once() {
unknown_ms: 4,
}),
json!(["complete", 1234, 700, 500, 200, 200, 100, 150, 80, 4]),
None,
),
(
TurnCriticalPath::Complete(TurnCriticalPathDurations {
@@ -1083,6 +1090,7 @@ async fn critical_path_payload_preserves_capture_status_and_emits_once() {
unknown_ms: 0,
}),
json!(["complete", 1234, 1234, 1234, 0, 0, 0, 0, 0, 0]),
None,
),
] {
let mut reducer = AnalyticsReducer::default();
@@ -1144,6 +1152,10 @@ async fn critical_path_payload_preserves_capture_status_and_emits_once() {
]),
expected
);
assert_eq!(
params.get("critical_path_incomplete_reasons"),
expected_reasons.as_ref()
);
assert_eq!(
params.get("critical_path_auto_review_overhead_ms"),
Some(&json!(expected_review_overhead))
+22 -3
View File
@@ -3,12 +3,25 @@
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,
Incomplete(Vec<IncompleteReason>),
Complete(TurnCriticalPathDurations),
}
@@ -16,7 +29,7 @@ impl TurnCriticalPath {
pub fn status(&self) -> &'static str {
match self {
Self::Disabled => "disabled",
Self::Incomplete => "incomplete",
Self::Incomplete(_) => "incomplete",
Self::Complete(_) => "complete",
}
}
@@ -24,7 +37,7 @@ impl TurnCriticalPath {
pub fn durations(&self) -> Option<&TurnCriticalPathDurations> {
match self {
Self::Complete(durations) => Some(durations),
Self::Disabled | Self::Incomplete => None,
Self::Disabled | Self::Incomplete(_) => None,
}
}
}
@@ -61,6 +74,8 @@ pub(crate) struct CriticalPathEventParams {
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 {
@@ -79,6 +94,10 @@ impl From<TurnCriticalPath> for CriticalPathEventParams {
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(),
},
}
}
}