From 7beebc0c5787480fb09e6e3862785da1979a5f15 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 722da8334c..021a26bed0 100644 --- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json +++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json @@ -1354,6 +1354,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" @@ -1395,6 +1396,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 987f134c13..2af9d0c90c 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 @@ -8201,6 +8201,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" @@ -8244,6 +8245,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 0bf0e147f2..67f1186e6b 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 @@ -4949,6 +4949,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" @@ -4992,6 +4993,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 2400d1771f..8e15590bf1 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2.rs @@ -4843,6 +4843,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, @@ -4866,6 +4869,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 253eace303..f64e2177e7 100644 --- a/codex-rs/app-server/README.md +++ b/codex-rs/app-server/README.md @@ -879,7 +879,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 579ea5547c..817ac31ca1 100644 --- a/codex-rs/core/src/guardian/approval_request.rs +++ b/codex-rs/core/src/guardian/approval_request.rs @@ -406,12 +406,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 06e52136fe..df1f29c66b 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; @@ -370,6 +371,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 a614d1361d..92c9c97e6d 100644 --- a/codex-rs/tui/src/chatwidget/tests.rs +++ b/codex-rs/tui/src/chatwidget/tests.rs @@ -9557,6 +9557,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, @@ -9575,6 +9576,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), @@ -9618,6 +9620,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), @@ -9765,6 +9768,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, @@ -9794,6 +9798,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, @@ -9809,6 +9814,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, @@ -9824,6 +9830,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 108fb49e7e..e1c08acfa0 100644 --- a/codex-rs/tui_app_server/src/chatwidget/tests.rs +++ b/codex-rs/tui_app_server/src/chatwidget/tests.rs @@ -10105,7 +10105,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, @@ -10124,7 +10124,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), @@ -10168,7 +10168,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), @@ -10221,7 +10221,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, @@ -10261,7 +10261,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, @@ -10281,7 +10281,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), @@ -10480,7 +10480,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, @@ -10510,7 +10510,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, @@ -10526,7 +10526,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, @@ -10542,7 +10542,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),