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
@@ -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))