Add request-scoped Guardian approval decisions (#42807)

## What changed

- Extend `ApprovalReviewContributor` with a `decide` hook that can allow an
  action, return a synchronous review result, or hand the request to the user.
- Pass contributors the request's approval state and a callback bound to the
  existing synchronous reviewer. Review results satisfy the review gate while
  the host continues to enforce permissions.
- Add structured reasons for requesting a fresh Guardian review and select the
  first contributor decision in registration order.

GitOrigin-RevId: ec84474b3fcbcf1027c8502aa1c2947c10149f9d
This commit is contained in:
jif authored and copyberry committed 2026-09-04 17:38:39 +00:00
1 parent 89a4eec6da
commit 0ae02915bd
8 files changed
+145 -1

No files matched your search

@@ -1,3 +1,5 @@
//! Request-scoped approval decisions. A review only satisfies the review gate; the host enforces permissions.
use std::fmt;
use std::sync::Arc;
@@ -31,7 +33,7 @@ pub struct ApprovalAssessment {
pub enum ApprovalReviewError {
/// The reviewer could not produce a valid assessment.
Failed(String),
/// The request exceeded its host-owned review deadline.
/// The request exceeded its synchronous review deadline.
TimedOut,
/// The request was cancelled by its parent approval.
Cancelled,
@@ -66,3 +68,38 @@ pub struct ApprovalReviewInput<'a> {
/// Reason an earlier request is being retried, when applicable.
pub retry_reason: Option<&'a str>,
}
/// Guardian's choice for one approval. Synchronous results pass through unchanged.
#[derive(Clone, Debug, PartialEq)]
pub enum ApprovalDecision {
/// Existing async evidence allows this action without synchronous review.
Allow,
Reviewed(codex_protocol::protocol::ReviewDecision),
AskUser,
}
/// Runs the existing synchronous review for the bound action and cancellation token.
/// Implementations must not resolve policy or reuse an async score.
pub trait SynchronousApprovalReviewer: Send + Sync {
fn review(
&self,
reason: codex_protocol::approvals::GuardianReviewReason,
) -> crate::ExtensionFuture<'_, codex_protocol::protocol::ReviewDecision>;
}
/// Inputs to Guardian's policy choice. Conversation and scores stay thread-owned.
pub struct ApprovalDecisionInput<'a> {
pub approval_id: &'a str,
pub action: &'a serde_json::Value,
pub thread_id: ThreadId,
pub thread_store: &'a ExtensionData,
pub category: codex_protocol::openai_models::GuardianScope,
pub approval_policy: codex_protocol::protocol::AskForApproval,
pub approvals_reviewer: codex_protocol::config_types::ApprovalsReviewer,
pub require_guardian: bool,
/// Existing retry and sensitive-action rules require a synchronous review.
pub require_fresh_review: bool,
pub full_access: bool,
pub metrics: Option<Arc<dyn crate::ExtensionMetrics>>,
pub synchronous_reviewer: &'a dyn SynchronousApprovalReviewer,
}