From e2494aeaa1663b44b8b0a52c6a8024c980270344 Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Sun, 22 Mar 2026 18:02:27 -0700 Subject: [PATCH] core: populate guardian parent ids for direct reviews Populate parent tool item ids for direct guardian-reviewed tool actions while preserving distinct network approval review ids. Co-authored-by: Codex --- .../schema/json/ServerNotification.json | 2 ++ .../codex_app_server_protocol.schemas.json | 2 ++ .../codex_app_server_protocol.v2.schemas.json | 2 ++ ...anApprovalReviewCompletedNotification.json | 1 + ...dianApprovalReviewStartedNotification.json | 1 + ...dianApprovalReviewCompletedNotification.ts | 8 +++++++- ...ardianApprovalReviewStartedNotification.ts | 8 +++++++- .../app-server-protocol/src/protocol/v2.rs | 6 ++++++ codex-rs/app-server/README.md | 2 +- .../app-server/src/bespoke_event_handling.rs | 8 ++++---- codex-rs/core/src/codex_delegate_tests.rs | 2 +- .../core/src/guardian/approval_request.rs | 10 +++++----- codex-rs/core/src/guardian/tests.rs | 9 +++++++++ codex-rs/tui/src/chatwidget/tests.rs | 7 +++++++ .../tui_app_server/src/chatwidget/tests.rs | 20 +++++++++---------- 15 files changed, 65 insertions(+), 23 deletions(-) diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.json index 3d0150546c..cdfa97dde3 100644 --- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json +++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json @@ -1377,6 +1377,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" @@ -1418,6 +1419,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json index 9077cdb356..193259d007 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json @@ -8224,6 +8224,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" @@ -8267,6 +8268,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json index 23dcaedc50..31a70321e7 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json @@ -4972,6 +4972,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" @@ -5015,6 +5016,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewCompletedNotification.json index a41e28df54..b76741b213 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewCompletedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewCompletedNotification.json @@ -62,6 +62,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewStartedNotification.json index fa4a0bfbe0..043cd1efdc 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewStartedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ItemGuardianApprovalReviewStartedNotification.json @@ -62,6 +62,7 @@ "action": true, "parentToolItemId": { "default": null, + "description": "Reviewed parent tool item identifier. For direct tool reviews this matches `review_id`; attributed `network_access` reviews may differ, and unattributed `network_access` reviews may omit it.", "type": [ "string", "null" diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewCompletedNotification.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewCompletedNotification.ts index 53b0f4abbb..dc2261818c 100644 --- a/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewCompletedNotification.ts +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewCompletedNotification.ts @@ -20,4 +20,10 @@ targetItemId: string, /** * Stable guardian review identifier for matching started/completed events. */ -reviewId: string | null, parentToolItemId: string | null, review: GuardianApprovalReview, action: JsonValue | null, }; +reviewId: string | null, +/** + * Reviewed parent tool item identifier. For direct tool reviews this + * matches `review_id`; attributed `network_access` reviews may differ, + * and unattributed `network_access` reviews may omit it. + */ +parentToolItemId: string | null, review: GuardianApprovalReview, action: JsonValue | null, }; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewStartedNotification.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewStartedNotification.ts index 6fda7a1a86..76b8f34f69 100644 --- a/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewStartedNotification.ts +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ItemGuardianApprovalReviewStartedNotification.ts @@ -20,4 +20,10 @@ targetItemId: string, /** * Stable guardian review identifier for matching started/completed events. */ -reviewId: string | null, parentToolItemId: string | null, review: GuardianApprovalReview, action: JsonValue | null, }; +reviewId: string | null, +/** + * Reviewed parent tool item identifier. For direct tool reviews this + * matches `review_id`; attributed `network_access` reviews may differ, + * and unattributed `network_access` reviews may omit it. + */ +parentToolItemId: string | null, review: GuardianApprovalReview, action: JsonValue | null, }; diff --git a/codex-rs/app-server-protocol/src/protocol/v2.rs b/codex-rs/app-server-protocol/src/protocol/v2.rs index 356b2444b7..961f26e661 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2.rs @@ -4879,6 +4879,9 @@ pub struct ItemGuardianApprovalReviewStartedNotification { /// Stable guardian review identifier for matching started/completed events. #[serde(default)] pub review_id: Option, + /// Reviewed parent tool item identifier. For direct tool reviews this + /// matches `review_id`; attributed `network_access` reviews may differ, + /// and unattributed `network_access` reviews may omit it. #[serde(default)] pub parent_tool_item_id: Option, pub review: GuardianApprovalReview, @@ -4902,6 +4905,9 @@ pub struct ItemGuardianApprovalReviewCompletedNotification { /// Stable guardian review identifier for matching started/completed events. #[serde(default)] pub review_id: Option, + /// Reviewed parent tool item identifier. For direct tool reviews this + /// matches `review_id`; attributed `network_access` reviews may differ, + /// and unattributed `network_access` reviews may omit it. #[serde(default)] pub parent_tool_item_id: Option, pub review: GuardianApprovalReview, diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.md index 2b785376c2..0a99b6a0b4 100644 --- a/codex-rs/app-server/README.md +++ b/codex-rs/app-server/README.md @@ -881,7 +881,7 @@ All items emit shared lifecycle events: - `item/autoApprovalReview/started` — [UNSTABLE] temporary guardian notification carrying `{threadId, turnId, targetItemId, reviewId, parentToolItemId, review, action?}` when guardian approval review begins. - `item/autoApprovalReview/completed` — [UNSTABLE] temporary guardian notification carrying `{threadId, turnId, targetItemId, reviewId, parentToolItemId, review, action?}` when guardian approval review resolves. -`review` is [UNSTABLE] and currently has `{status, riskScore?, riskLevel?, rationale?}`, where `status` is one of `inProgress`, `approved`, `denied`, or `aborted`. `action` is the guardian action summary payload from core when available and is intended to support temporary standalone pending-review UI. `reviewId` is the stable guardian review id for matching started/completed notifications. `targetItemId` is a deprecated alias for `reviewId` retained for backwards compatibility. `parentToolItemId` points at the reviewed parent tool item when app-server can attribute the review to one, including attributed `network_access` reviews. These notifications are separate from the target item's own `item/completed` lifecycle and are intentionally temporary while the guardian app protocol is still being designed. +`review` is [UNSTABLE] and currently has `{status, riskScore?, riskLevel?, rationale?}`, where `status` is one of `inProgress`, `approved`, `denied`, or `aborted`. `action` is the guardian action summary payload from core when available and is intended to support temporary standalone pending-review UI. `reviewId` is the stable guardian review id for matching started/completed notifications. `targetItemId` is a deprecated alias for `reviewId` retained for backwards compatibility. `parentToolItemId` points at the reviewed parent tool item; for direct tool reviews it matches `reviewId`, while attributed `network_access` reviews may point at a different parent item and can remain absent when attribution is unavailable. These notifications are separate from the target item's own `item/completed` lifecycle and are intentionally temporary while the guardian app protocol is still being designed. There are additional item-specific events: diff --git a/codex-rs/app-server/src/bespoke_event_handling.rs b/codex-rs/app-server/src/bespoke_event_handling.rs index 158598ea83..c2d5e1e2b1 100644 --- a/codex-rs/app-server/src/bespoke_event_handling.rs +++ b/codex-rs/app-server/src/bespoke_event_handling.rs @@ -2925,7 +2925,7 @@ mod tests { "turn-from-event", &GuardianAssessmentEvent { id: "item-1".to_string(), - parent_tool_item_id: None, + parent_tool_item_id: Some("item-1".to_string()), turn_id: String::new(), status: codex_protocol::protocol::GuardianAssessmentStatus::InProgress, risk_score: None, @@ -2941,7 +2941,7 @@ mod tests { assert_eq!(payload.turn_id, "turn-from-event"); assert_eq!(payload.target_item_id, "item-1"); assert_eq!(payload.review_id.as_deref(), Some("item-1")); - assert_eq!(payload.parent_tool_item_id, None); + assert_eq!(payload.parent_tool_item_id.as_deref(), Some("item-1")); assert_eq!( payload.review.status, GuardianApprovalReviewStatus::InProgress @@ -2967,7 +2967,7 @@ mod tests { "turn-from-event", &GuardianAssessmentEvent { id: "item-2".to_string(), - parent_tool_item_id: None, + parent_tool_item_id: Some("item-2".to_string()), turn_id: "turn-from-assessment".to_string(), status: codex_protocol::protocol::GuardianAssessmentStatus::Denied, risk_score: Some(91), @@ -2983,7 +2983,7 @@ mod tests { assert_eq!(payload.turn_id, "turn-from-assessment"); assert_eq!(payload.target_item_id, "item-2"); assert_eq!(payload.review_id.as_deref(), Some("item-2")); - assert_eq!(payload.parent_tool_item_id, None); + assert_eq!(payload.parent_tool_item_id.as_deref(), Some("item-2")); assert_eq!(payload.review.status, GuardianApprovalReviewStatus::Denied); assert_eq!(payload.review.risk_score, Some(91)); assert_eq!( diff --git a/codex-rs/core/src/codex_delegate_tests.rs b/codex-rs/core/src/codex_delegate_tests.rs index abf52ade43..73e44cdedd 100644 --- a/codex-rs/core/src/codex_delegate_tests.rs +++ b/codex-rs/core/src/codex_delegate_tests.rs @@ -313,7 +313,7 @@ async fn handle_exec_approval_uses_call_id_for_guardian_review_and_approval_id_f assessment_event, GuardianAssessmentEvent { id: "command-item-1".to_string(), - parent_tool_item_id: None, + parent_tool_item_id: Some("command-item-1".to_string()), turn_id: parent_ctx.sub_id.clone(), status: GuardianAssessmentStatus::InProgress, risk_score: None, diff --git a/codex-rs/core/src/guardian/approval_request.rs b/codex-rs/core/src/guardian/approval_request.rs index e5d23e9bd0..e237c508cf 100644 --- a/codex-rs/core/src/guardian/approval_request.rs +++ b/codex-rs/core/src/guardian/approval_request.rs @@ -380,12 +380,12 @@ pub(crate) fn guardian_request_parent_tool_item_id( parent_tool_item_id, .. } => parent_tool_item_id.as_deref(), - GuardianApprovalRequest::Shell { .. } - | GuardianApprovalRequest::ExecCommand { .. } - | GuardianApprovalRequest::ApplyPatch { .. } - | GuardianApprovalRequest::McpToolCall { .. } => None, + GuardianApprovalRequest::Shell { id, .. } + | GuardianApprovalRequest::ExecCommand { id, .. } + | GuardianApprovalRequest::ApplyPatch { id, .. } + | GuardianApprovalRequest::McpToolCall { id, .. } => Some(id), #[cfg(unix)] - GuardianApprovalRequest::Execve { .. } => None, + GuardianApprovalRequest::Execve { id, .. } => Some(id), } } diff --git a/codex-rs/core/src/guardian/tests.rs b/codex-rs/core/src/guardian/tests.rs index 5a7b191da5..12eb426e07 100644 --- a/codex-rs/core/src/guardian/tests.rs +++ b/codex-rs/core/src/guardian/tests.rs @@ -1,3 +1,4 @@ +use super::approval_request::guardian_request_parent_tool_item_id; use super::*; use crate::codex::Session; use crate::codex::TurnContext; @@ -371,6 +372,14 @@ fn guardian_request_turn_id_prefers_network_access_owner_turn() { guardian_request_turn_id(&apply_patch, "fallback-turn"), "fallback-turn" ); + assert_eq!( + guardian_request_parent_tool_item_id(&network_access), + Some("command-1") + ); + assert_eq!( + guardian_request_parent_tool_item_id(&apply_patch), + Some("patch-1") + ); } #[test] diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs index 2300421966..022ac72a11 100644 --- a/codex-rs/tui/src/chatwidget/tests.rs +++ b/codex-rs/tui/src/chatwidget/tests.rs @@ -10399,6 +10399,7 @@ async fn guardian_denied_exec_renders_warning_and_denied_request() { id: "guardian-in-progress".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".into(), + parent_tool_item_id: Some("guardian-1".into()), turn_id: "turn-1".into(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -10417,6 +10418,7 @@ async fn guardian_denied_exec_renders_warning_and_denied_request() { id: "guardian-assessment".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".into(), + parent_tool_item_id: Some("guardian-1".into()), turn_id: "turn-1".into(), status: GuardianAssessmentStatus::Denied, risk_score: Some(96), @@ -10460,6 +10462,7 @@ async fn guardian_approved_exec_renders_approved_request() { id: "guardian-assessment".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "thread:child-thread:guardian-1".into(), + parent_tool_item_id: Some("thread:child-thread:guardian-1".into()), turn_id: "turn-1".into(), status: GuardianAssessmentStatus::Approved, risk_score: Some(14), @@ -10607,6 +10610,7 @@ async fn guardian_parallel_reviews_render_aggregate_status_snapshot() { id: format!("event-{id}"), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: id.to_string(), + parent_tool_item_id: Some(id.to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -10636,6 +10640,7 @@ async fn guardian_parallel_reviews_keep_remaining_review_visible_after_denial() id: "event-guardian-1".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".to_string(), + parent_tool_item_id: Some("guardian-1".to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -10651,6 +10656,7 @@ async fn guardian_parallel_reviews_keep_remaining_review_visible_after_denial() id: "event-guardian-2".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-2".to_string(), + parent_tool_item_id: Some("guardian-2".to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -10666,6 +10672,7 @@ async fn guardian_parallel_reviews_keep_remaining_review_visible_after_denial() id: "event-guardian-1-denied".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".to_string(), + parent_tool_item_id: Some("guardian-1".to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::Denied, risk_score: Some(92), diff --git a/codex-rs/tui_app_server/src/chatwidget/tests.rs b/codex-rs/tui_app_server/src/chatwidget/tests.rs index 5448edd0dd..213c8737f8 100644 --- a/codex-rs/tui_app_server/src/chatwidget/tests.rs +++ b/codex-rs/tui_app_server/src/chatwidget/tests.rs @@ -10956,7 +10956,7 @@ async fn guardian_denied_exec_renders_warning_and_denied_request() { id: "guardian-in-progress".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".into(), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-1".into()), turn_id: "turn-1".into(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -10975,7 +10975,7 @@ async fn guardian_denied_exec_renders_warning_and_denied_request() { id: "guardian-assessment".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".into(), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-1".into()), turn_id: "turn-1".into(), status: GuardianAssessmentStatus::Denied, risk_score: Some(96), @@ -11019,7 +11019,7 @@ async fn guardian_approved_exec_renders_approved_request() { id: "guardian-assessment".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "thread:child-thread:guardian-1".into(), - parent_tool_item_id: None, + parent_tool_item_id: Some("thread:child-thread:guardian-1".into()), turn_id: "turn-1".into(), status: GuardianAssessmentStatus::Approved, risk_score: Some(14), @@ -11072,7 +11072,7 @@ async fn app_server_guardian_review_started_sets_review_status() { turn_id: "turn-1".to_string(), target_item_id: "guardian-1".to_string(), review_id: Some("guardian-1".to_string()), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-1".to_string()), review: GuardianApprovalReview { status: GuardianApprovalReviewStatus::InProgress, risk_score: None, @@ -11112,7 +11112,7 @@ async fn app_server_guardian_review_denied_renders_denied_request_snapshot() { turn_id: "turn-1".to_string(), target_item_id: "guardian-1".to_string(), review_id: Some("guardian-1".to_string()), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-1".to_string()), review: GuardianApprovalReview { status: GuardianApprovalReviewStatus::InProgress, risk_score: None, @@ -11132,7 +11132,7 @@ async fn app_server_guardian_review_denied_renders_denied_request_snapshot() { turn_id: "turn-1".to_string(), target_item_id: "guardian-1".to_string(), review_id: Some("guardian-1".to_string()), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-1".to_string()), review: GuardianApprovalReview { status: GuardianApprovalReviewStatus::Denied, risk_score: Some(96), @@ -11331,7 +11331,7 @@ async fn guardian_parallel_reviews_render_aggregate_status_snapshot() { id: format!("event-{id}"), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: id.to_string(), - parent_tool_item_id: None, + parent_tool_item_id: Some(id.to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -11361,7 +11361,7 @@ async fn guardian_parallel_reviews_keep_remaining_review_visible_after_denial() id: "event-guardian-1".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".to_string(), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-1".to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -11377,7 +11377,7 @@ async fn guardian_parallel_reviews_keep_remaining_review_visible_after_denial() id: "event-guardian-2".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-2".to_string(), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-2".to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::InProgress, risk_score: None, @@ -11393,7 +11393,7 @@ async fn guardian_parallel_reviews_keep_remaining_review_visible_after_denial() id: "event-guardian-1-denied".into(), msg: EventMsg::GuardianAssessment(GuardianAssessmentEvent { id: "guardian-1".to_string(), - parent_tool_item_id: None, + parent_tool_item_id: Some("guardian-1".to_string()), turn_id: "turn-1".to_string(), status: GuardianAssessmentStatus::Denied, risk_score: Some(92),