fix(guardian, app-server): introduce guardian review ids (#17298)

## Description

This PR introduces `review_id` as the stable identifier for guardian
reviews and exposes it in app-server `item/autoApprovalReview/started`
and `item/autoApprovalReview/completed` events.

Internally, guardian rejection state is now keyed by `review_id` instead
of the reviewed tool item ID. `target_item_id` is still included when a
review maps to a concrete thread item, but it is no longer overloaded as
the review lifecycle identifier.

## Motivation

We'd like to give users the ability to preempt a guardian review while
it's running (approve or decline).

However, we can't implement the API that allows the user to override a
running guardian review because we didn't have a unique `review_id` per
guardian review. Using `target_item_id` is not correct since:
- with execve reviews, there can be multiple execve calls (and therefore
guardian reviews) per shell command
- with network policy reviews, there is no target item ID

The PR that actually implements user overrides will use `review_id` as
the stable identifier.
This commit is contained in:
Owen Lin authored and GitHub committed 2026-04-10 16:21:02 -07:00
1 parent 7999b0f60f
commit a3be74143a
36 files changed
+577 -172

No files matched your search

+12 -2
View File
@@ -174,6 +174,7 @@ use codex_protocol::protocol::ExecCommandSource;
#[cfg(test)]
use codex_protocol::protocol::ExitedReviewModeEvent;
use codex_protocol::protocol::GuardianAssessmentAction;
use codex_protocol::protocol::GuardianAssessmentDecisionSource;
use codex_protocol::protocol::GuardianAssessmentEvent;
use codex_protocol::protocol::GuardianAssessmentStatus;
use codex_protocol::protocol::ImageGenerationBeginEvent;
@@ -6682,17 +6683,19 @@ impl ChatWidget {
}
ServerNotification::ItemGuardianApprovalReviewStarted(notification) => {
self.on_guardian_review_notification(
notification.target_item_id,
notification.review_id,
notification.turn_id,
notification.review,
/*decision_source*/ None,
notification.action,
);
}
ServerNotification::ItemGuardianApprovalReviewCompleted(notification) => {
self.on_guardian_review_notification(
notification.target_item_id,
notification.review_id,
notification.turn_id,
notification.review,
Some(notification.decision_source),
notification.action,
);
}
@@ -6975,10 +6978,12 @@ impl ChatWidget {
id: String,
turn_id: String,
review: codex_app_server_protocol::GuardianApprovalReview,
decision_source: Option<codex_app_server_protocol::AutoReviewDecisionSource>,
action: GuardianApprovalReviewAction,
) {
self.on_guardian_assessment(GuardianAssessmentEvent {
id,
target_item_id: None,
turn_id,
status: match review.status {
codex_app_server_protocol::GuardianApprovalReviewStatus::InProgress => {
@@ -7025,6 +7030,11 @@ impl ChatWidget {
}
}),
rationale: review.rationale,
decision_source: decision_source.map(|source| match source {
codex_app_server_protocol::AutoReviewDecisionSource::Agent => {
GuardianAssessmentDecisionSource::Agent
}
}),
action: action.into(),
});
}