mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Refactor guardian timeout approval flow
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
co-authored by
Codex
parent
fc60875e65
commit
9df3dd6f22
@@ -1854,7 +1854,6 @@ impl Session {
|
||||
session_telemetry,
|
||||
models_manager: Arc::clone(&models_manager),
|
||||
tool_approvals: Mutex::new(ApprovalStore::default()),
|
||||
guardian_review_timeouts: Mutex::new(HashMap::new()),
|
||||
execve_session_approvals: RwLock::new(HashMap::new()),
|
||||
skills_manager,
|
||||
plugins_manager: Arc::clone(&plugins_manager),
|
||||
|
||||
@@ -739,7 +739,7 @@ fn spawn_guardian_review(
|
||||
retry_reason,
|
||||
cancel_token,
|
||||
));
|
||||
let _ = tx.send(decision);
|
||||
let _ = tx.send(decision.into_review_decision());
|
||||
});
|
||||
rx
|
||||
}
|
||||
|
||||
@@ -2653,7 +2653,6 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
session_telemetry: session_telemetry.clone(),
|
||||
models_manager: Arc::clone(&models_manager),
|
||||
tool_approvals: Mutex::new(ApprovalStore::default()),
|
||||
guardian_review_timeouts: Mutex::new(HashMap::new()),
|
||||
execve_session_approvals: RwLock::new(HashMap::new()),
|
||||
skills_manager,
|
||||
plugins_manager,
|
||||
@@ -3489,7 +3488,6 @@ pub(crate) async fn make_session_and_context_with_dynamic_tools_and_rx(
|
||||
session_telemetry: session_telemetry.clone(),
|
||||
models_manager: Arc::clone(&models_manager),
|
||||
tool_approvals: Mutex::new(ApprovalStore::default()),
|
||||
guardian_review_timeouts: Mutex::new(HashMap::new()),
|
||||
execve_session_approvals: RwLock::new(HashMap::new()),
|
||||
skills_manager,
|
||||
plugins_manager,
|
||||
|
||||
@@ -25,11 +25,12 @@ pub(crate) use approval_request::GuardianApprovalRequest;
|
||||
pub(crate) use approval_request::GuardianMcpAnnotations;
|
||||
pub(crate) use approval_request::guardian_approval_request_to_json;
|
||||
pub(crate) use review::GUARDIAN_REJECTION_MESSAGE;
|
||||
pub(crate) use review::GUARDIAN_TIMEOUT_MESSAGE;
|
||||
pub(crate) use review::GuardianApprovalDecision;
|
||||
pub(crate) use review::is_guardian_reviewer_source;
|
||||
pub(crate) use review::review_approval_request;
|
||||
pub(crate) use review::review_approval_request_with_cancel;
|
||||
pub(crate) use review::routes_approval_to_guardian;
|
||||
pub(crate) use review::take_guardian_timeout_message;
|
||||
pub(crate) use review_session::GuardianReviewSessionManager;
|
||||
|
||||
const GUARDIAN_PREFERRED_MODEL: &str = "gpt-5.4";
|
||||
|
||||
@@ -6,7 +6,6 @@ use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::GuardianAssessmentEvent;
|
||||
use codex_protocol::protocol::GuardianAssessmentStatus;
|
||||
use codex_protocol::protocol::GuardianRiskLevel;
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use codex_protocol::protocol::WarningEvent;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
@@ -42,6 +41,24 @@ pub(crate) const GUARDIAN_TIMEOUT_MESSAGE: &str = concat!(
|
||||
"The action was not intentionally rejected, and a retry may succeed.",
|
||||
);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) enum GuardianApprovalDecision {
|
||||
Approved,
|
||||
Denied,
|
||||
TimedOut,
|
||||
Aborted,
|
||||
}
|
||||
|
||||
impl GuardianApprovalDecision {
|
||||
pub(crate) fn into_review_decision(self) -> codex_protocol::protocol::ReviewDecision {
|
||||
match self {
|
||||
Self::Approved => codex_protocol::protocol::ReviewDecision::Approved,
|
||||
Self::Denied | Self::TimedOut => codex_protocol::protocol::ReviewDecision::Denied,
|
||||
Self::Aborted => codex_protocol::protocol::ReviewDecision::Abort,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(super) enum GuardianReviewOutcome {
|
||||
Completed(anyhow::Result<GuardianAssessment>),
|
||||
@@ -49,18 +66,6 @@ pub(super) enum GuardianReviewOutcome {
|
||||
Aborted,
|
||||
}
|
||||
|
||||
pub(crate) async fn take_guardian_timeout_message(
|
||||
session: &Session,
|
||||
request_id: &str,
|
||||
) -> Option<String> {
|
||||
session
|
||||
.services
|
||||
.guardian_review_timeouts
|
||||
.lock()
|
||||
.await
|
||||
.remove(request_id)
|
||||
}
|
||||
|
||||
fn guardian_risk_level_str(level: GuardianRiskLevel) -> &'static str {
|
||||
match level {
|
||||
GuardianRiskLevel::Low => "low",
|
||||
@@ -95,16 +100,10 @@ async fn run_guardian_review(
|
||||
request: GuardianApprovalRequest,
|
||||
retry_reason: Option<String>,
|
||||
external_cancel: Option<CancellationToken>,
|
||||
) -> ReviewDecision {
|
||||
) -> GuardianApprovalDecision {
|
||||
let assessment_id = guardian_request_id(&request).to_string();
|
||||
let assessment_turn_id = guardian_request_turn_id(&request, &turn.sub_id).to_string();
|
||||
let action_summary = guardian_assessment_action_value(&request);
|
||||
session
|
||||
.services
|
||||
.guardian_review_timeouts
|
||||
.lock()
|
||||
.await
|
||||
.remove(&assessment_id);
|
||||
session
|
||||
.send_event(
|
||||
turn.as_ref(),
|
||||
@@ -138,7 +137,7 @@ async fn run_guardian_review(
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
return ReviewDecision::Abort;
|
||||
return GuardianApprovalDecision::Aborted;
|
||||
}
|
||||
|
||||
let schema = guardian_output_schema();
|
||||
@@ -175,23 +174,15 @@ async fn run_guardian_review(
|
||||
},
|
||||
GuardianAssessmentStatus::Denied,
|
||||
),
|
||||
GuardianReviewOutcome::TimedOut => {
|
||||
session
|
||||
.services
|
||||
.guardian_review_timeouts
|
||||
.lock()
|
||||
.await
|
||||
.insert(assessment_id.clone(), GUARDIAN_TIMEOUT_MESSAGE.to_string());
|
||||
(
|
||||
GuardianAssessment {
|
||||
risk_level: GuardianRiskLevel::High,
|
||||
risk_score: 100,
|
||||
rationale: GUARDIAN_TIMEOUT_MESSAGE.to_string(),
|
||||
evidence: vec![],
|
||||
},
|
||||
GuardianAssessmentStatus::TimedOut,
|
||||
)
|
||||
}
|
||||
GuardianReviewOutcome::TimedOut => (
|
||||
GuardianAssessment {
|
||||
risk_level: GuardianRiskLevel::High,
|
||||
risk_score: 100,
|
||||
rationale: GUARDIAN_TIMEOUT_MESSAGE.to_string(),
|
||||
evidence: vec![],
|
||||
},
|
||||
GuardianAssessmentStatus::TimedOut,
|
||||
),
|
||||
GuardianReviewOutcome::Aborted => {
|
||||
session
|
||||
.send_event(
|
||||
@@ -207,7 +198,7 @@ async fn run_guardian_review(
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
return ReviewDecision::Abort;
|
||||
return GuardianApprovalDecision::Aborted;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -255,10 +246,13 @@ async fn run_guardian_review(
|
||||
)
|
||||
.await;
|
||||
|
||||
if status == GuardianAssessmentStatus::Approved {
|
||||
ReviewDecision::Approved
|
||||
} else {
|
||||
ReviewDecision::Denied
|
||||
match status {
|
||||
GuardianAssessmentStatus::Approved => GuardianApprovalDecision::Approved,
|
||||
GuardianAssessmentStatus::Denied => GuardianApprovalDecision::Denied,
|
||||
GuardianAssessmentStatus::TimedOut => GuardianApprovalDecision::TimedOut,
|
||||
GuardianAssessmentStatus::InProgress | GuardianAssessmentStatus::Aborted => {
|
||||
unreachable!("guardian terminal decision should not use non-terminal statuses")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +262,7 @@ pub(crate) async fn review_approval_request(
|
||||
turn: &Arc<TurnContext>,
|
||||
request: GuardianApprovalRequest,
|
||||
retry_reason: Option<String>,
|
||||
) -> ReviewDecision {
|
||||
) -> GuardianApprovalDecision {
|
||||
run_guardian_review(
|
||||
Arc::clone(session),
|
||||
Arc::clone(turn),
|
||||
@@ -285,7 +279,7 @@ pub(crate) async fn review_approval_request_with_cancel(
|
||||
request: GuardianApprovalRequest,
|
||||
retry_reason: Option<String>,
|
||||
cancel_token: CancellationToken,
|
||||
) -> ReviewDecision {
|
||||
) -> GuardianApprovalDecision {
|
||||
run_guardian_review(
|
||||
Arc::clone(session),
|
||||
Arc::clone(turn),
|
||||
|
||||
@@ -394,7 +394,7 @@ async fn cancelled_guardian_review_emits_terminal_abort_without_warning() {
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(decision, ReviewDecision::Abort);
|
||||
assert_eq!(decision, GuardianApprovalDecision::Aborted);
|
||||
|
||||
let mut guardian_statuses = Vec::new();
|
||||
let mut warnings = Vec::new();
|
||||
@@ -416,26 +416,11 @@ async fn cancelled_guardian_review_emits_terminal_abort_without_warning() {
|
||||
assert!(warnings.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn guardian_timeout_message_is_taken_once() {
|
||||
let (session, _turn) = crate::codex::make_session_and_context().await;
|
||||
session
|
||||
.services
|
||||
.guardian_review_timeouts
|
||||
.lock()
|
||||
.await
|
||||
.insert("approval-1".to_string(), "review timed out".to_string());
|
||||
|
||||
#[test]
|
||||
fn guardian_timed_out_decision_maps_to_denied_review_decision() {
|
||||
assert_eq!(
|
||||
take_guardian_timeout_message(&session, "approval-1")
|
||||
.await
|
||||
.as_deref(),
|
||||
Some("review timed out")
|
||||
);
|
||||
assert!(
|
||||
take_guardian_timeout_message(&session, "approval-1")
|
||||
.await
|
||||
.is_none()
|
||||
GuardianApprovalDecision::TimedOut.into_review_decision(),
|
||||
ReviewDecision::Denied
|
||||
);
|
||||
}
|
||||
|
||||
@@ -796,7 +781,7 @@ async fn guardian_review_surfaces_responses_api_errors_in_rejection_reason() ->
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(decision, ReviewDecision::Denied);
|
||||
assert_eq!(decision, GuardianApprovalDecision::Denied);
|
||||
|
||||
let mut warnings = Vec::new();
|
||||
let mut denial_rationales = Vec::new();
|
||||
@@ -905,7 +890,7 @@ async fn guardian_parallel_reviews_fork_from_last_committed_trunk_history() -> a
|
||||
};
|
||||
assert_eq!(
|
||||
review_approval_request(&session, &turn, initial_request, None).await,
|
||||
ReviewDecision::Approved
|
||||
GuardianApprovalDecision::Approved
|
||||
);
|
||||
|
||||
let second_request = GuardianApprovalRequest::Shell {
|
||||
@@ -958,7 +943,7 @@ async fn guardian_parallel_reviews_fork_from_last_committed_trunk_history() -> a
|
||||
Some("parallel follow-up".to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(third_decision, ReviewDecision::Approved);
|
||||
assert_eq!(third_decision, GuardianApprovalDecision::Approved);
|
||||
let requests = server.requests().await;
|
||||
assert_eq!(requests.len(), 3);
|
||||
let third_request_body = serde_json::from_slice::<serde_json::Value>(&requests[2])?;
|
||||
@@ -981,7 +966,7 @@ async fn guardian_parallel_reviews_fork_from_last_committed_trunk_history() -> a
|
||||
gate_tx
|
||||
.send(())
|
||||
.expect("second guardian review gate should still be open");
|
||||
assert_eq!(second_review.await?, ReviewDecision::Approved);
|
||||
assert_eq!(second_review.await?, GuardianApprovalDecision::Approved);
|
||||
server.shutdown().await;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -19,12 +19,13 @@ use crate::config::edit::ConfigEdit;
|
||||
use crate::config::edit::ConfigEditsBuilder;
|
||||
use crate::config::types::AppToolApproval;
|
||||
use crate::connectors;
|
||||
use crate::guardian::GUARDIAN_TIMEOUT_MESSAGE;
|
||||
use crate::guardian::GuardianApprovalDecision;
|
||||
use crate::guardian::GuardianApprovalRequest;
|
||||
use crate::guardian::GuardianMcpAnnotations;
|
||||
use crate::guardian::guardian_approval_request_to_json;
|
||||
use crate::guardian::review_approval_request;
|
||||
use crate::guardian::routes_approval_to_guardian;
|
||||
use crate::guardian::take_guardian_timeout_message;
|
||||
use crate::mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use crate::mcp_tool_approval_templates::RenderedMcpToolApprovalParam;
|
||||
use crate::mcp_tool_approval_templates::render_mcp_tool_approval_template;
|
||||
@@ -564,13 +565,7 @@ async fn maybe_request_mcp_tool_approval(
|
||||
monitor_reason.clone(),
|
||||
)
|
||||
.await;
|
||||
let decision = if (decision == ReviewDecision::Denied || decision == ReviewDecision::Abort)
|
||||
&& let Some(message) = take_guardian_timeout_message(sess.as_ref(), call_id).await
|
||||
{
|
||||
McpToolApprovalDecision::TimedOut(message)
|
||||
} else {
|
||||
mcp_tool_approval_decision_from_guardian(decision)
|
||||
};
|
||||
let decision = mcp_tool_approval_decision_from_guardian(decision);
|
||||
apply_mcp_tool_approval_decision(
|
||||
sess,
|
||||
turn_context,
|
||||
@@ -763,13 +758,17 @@ pub(crate) fn build_guardian_mcp_tool_review_request(
|
||||
}
|
||||
}
|
||||
|
||||
fn mcp_tool_approval_decision_from_guardian(decision: ReviewDecision) -> McpToolApprovalDecision {
|
||||
fn mcp_tool_approval_decision_from_guardian(
|
||||
decision: GuardianApprovalDecision,
|
||||
) -> McpToolApprovalDecision {
|
||||
match decision {
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. }
|
||||
| ReviewDecision::NetworkPolicyAmendment { .. } => McpToolApprovalDecision::Accept,
|
||||
ReviewDecision::ApprovedForSession => McpToolApprovalDecision::AcceptForSession,
|
||||
ReviewDecision::Denied | ReviewDecision::Abort => McpToolApprovalDecision::Decline,
|
||||
GuardianApprovalDecision::Approved => McpToolApprovalDecision::Accept,
|
||||
GuardianApprovalDecision::Denied | GuardianApprovalDecision::Aborted => {
|
||||
McpToolApprovalDecision::Decline
|
||||
}
|
||||
GuardianApprovalDecision::TimedOut => {
|
||||
McpToolApprovalDecision::TimedOut(GUARDIAN_TIMEOUT_MESSAGE.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use crate::config::types::AppConfig;
|
||||
use crate::config::types::AppToolConfig;
|
||||
use crate::config::types::AppToolsConfig;
|
||||
use crate::config::types::AppsConfigToml;
|
||||
use crate::guardian::GUARDIAN_TIMEOUT_MESSAGE;
|
||||
use crate::guardian::GuardianApprovalDecision;
|
||||
use codex_config::CONFIG_TOML_FILE;
|
||||
use core_test_support::responses::ev_assistant_message;
|
||||
use core_test_support::responses::ev_completed;
|
||||
@@ -693,17 +695,21 @@ fn prepare_arc_request_action_serializes_mcp_tool_call_shape() {
|
||||
#[test]
|
||||
fn guardian_review_decision_maps_to_mcp_tool_decision() {
|
||||
assert_eq!(
|
||||
mcp_tool_approval_decision_from_guardian(ReviewDecision::Approved),
|
||||
mcp_tool_approval_decision_from_guardian(GuardianApprovalDecision::Approved),
|
||||
McpToolApprovalDecision::Accept
|
||||
);
|
||||
assert_eq!(
|
||||
mcp_tool_approval_decision_from_guardian(ReviewDecision::Denied),
|
||||
mcp_tool_approval_decision_from_guardian(GuardianApprovalDecision::Denied),
|
||||
McpToolApprovalDecision::Decline
|
||||
);
|
||||
assert_eq!(
|
||||
mcp_tool_approval_decision_from_guardian(ReviewDecision::Abort),
|
||||
mcp_tool_approval_decision_from_guardian(GuardianApprovalDecision::Aborted),
|
||||
McpToolApprovalDecision::Decline
|
||||
);
|
||||
assert_eq!(
|
||||
mcp_tool_approval_decision_from_guardian(GuardianApprovalDecision::TimedOut),
|
||||
McpToolApprovalDecision::TimedOut(GUARDIAN_TIMEOUT_MESSAGE.to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -49,7 +49,6 @@ pub(crate) struct SessionServices {
|
||||
pub(crate) models_manager: Arc<ModelsManager>,
|
||||
pub(crate) session_telemetry: SessionTelemetry,
|
||||
pub(crate) tool_approvals: Mutex<ApprovalStore>,
|
||||
pub(crate) guardian_review_timeouts: Mutex<HashMap<String, String>>,
|
||||
#[cfg_attr(not(unix), allow(dead_code))]
|
||||
pub(crate) execve_session_approvals: RwLock<HashMap<AbsolutePathBuf, ExecveSessionApproval>>,
|
||||
pub(crate) skills_manager: Arc<SkillsManager>,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::codex::Session;
|
||||
use crate::guardian::GUARDIAN_REJECTION_MESSAGE;
|
||||
use crate::guardian::GUARDIAN_TIMEOUT_MESSAGE;
|
||||
use crate::guardian::GuardianApprovalDecision;
|
||||
use crate::guardian::GuardianApprovalRequest;
|
||||
use crate::guardian::review_approval_request;
|
||||
use crate::guardian::routes_approval_to_guardian;
|
||||
use crate::guardian::take_guardian_timeout_message;
|
||||
use crate::network_policy_decision::denied_network_policy_message;
|
||||
use crate::tools::sandboxing::ToolError;
|
||||
use codex_network_proxy::BlockedRequest;
|
||||
@@ -352,10 +353,11 @@ impl NetworkApprovalService {
|
||||
protocol,
|
||||
};
|
||||
let owner_call = self.resolve_single_active_call().await;
|
||||
let approval_decision = if routes_approval_to_guardian(&turn_context) {
|
||||
let mut cache_session_deny = false;
|
||||
let resolved = if routes_approval_to_guardian(&turn_context) {
|
||||
// TODO(ccunningham): Attach guardian network reviews to the reviewed tool item
|
||||
// lifecycle instead of this temporary standalone network approval id.
|
||||
review_approval_request(
|
||||
match review_approval_request(
|
||||
&session,
|
||||
&turn_context,
|
||||
GuardianApprovalRequest::NetworkAccess {
|
||||
@@ -371,11 +373,38 @@ impl NetworkApprovalService {
|
||||
Some(policy_denial_message.clone()),
|
||||
)
|
||||
.await
|
||||
{
|
||||
GuardianApprovalDecision::Approved => PendingApprovalDecision::AllowOnce,
|
||||
GuardianApprovalDecision::Denied | GuardianApprovalDecision::Aborted => {
|
||||
if let Some(owner_call) = owner_call.as_ref() {
|
||||
self.record_call_outcome(
|
||||
&owner_call.registration_id,
|
||||
NetworkApprovalOutcome::DeniedByPolicy(
|
||||
GUARDIAN_REJECTION_MESSAGE.to_string(),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
PendingApprovalDecision::Deny
|
||||
}
|
||||
GuardianApprovalDecision::TimedOut => {
|
||||
if let Some(owner_call) = owner_call.as_ref() {
|
||||
self.record_call_outcome(
|
||||
&owner_call.registration_id,
|
||||
NetworkApprovalOutcome::TimedOutByReviewer(
|
||||
GUARDIAN_TIMEOUT_MESSAGE.to_string(),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
PendingApprovalDecision::Deny
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let approval_id = Self::approval_id_for_key(&key);
|
||||
let prompt_command = vec!["network-access".to_string(), target.clone()];
|
||||
let available_decisions = None;
|
||||
session
|
||||
match session
|
||||
.request_command_approval(
|
||||
turn_context.as_ref(),
|
||||
approval_id,
|
||||
@@ -390,75 +419,84 @@ impl NetworkApprovalService {
|
||||
available_decisions,
|
||||
)
|
||||
.await
|
||||
};
|
||||
|
||||
let mut cache_session_deny = false;
|
||||
let resolved = match approval_decision {
|
||||
ReviewDecision::Approved | ReviewDecision::ApprovedExecpolicyAmendment { .. } => {
|
||||
PendingApprovalDecision::AllowOnce
|
||||
}
|
||||
ReviewDecision::ApprovedForSession => PendingApprovalDecision::AllowForSession,
|
||||
ReviewDecision::NetworkPolicyAmendment {
|
||||
network_policy_amendment,
|
||||
} => match network_policy_amendment.action {
|
||||
NetworkPolicyRuleAction::Allow => {
|
||||
match session
|
||||
.persist_network_policy_amendment(
|
||||
&network_policy_amendment,
|
||||
&network_approval_context,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {
|
||||
session
|
||||
.record_network_policy_amendment_message(
|
||||
&turn_context.sub_id,
|
||||
&network_policy_amendment,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
Err(err) => {
|
||||
let message =
|
||||
format!("Failed to apply network policy amendment: {err}");
|
||||
warn!("{message}");
|
||||
session
|
||||
.send_event_raw(Event {
|
||||
id: turn_context.sub_id.clone(),
|
||||
msg: EventMsg::Warning(WarningEvent { message }),
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
PendingApprovalDecision::AllowForSession
|
||||
{
|
||||
ReviewDecision::Approved | ReviewDecision::ApprovedExecpolicyAmendment { .. } => {
|
||||
PendingApprovalDecision::AllowOnce
|
||||
}
|
||||
NetworkPolicyRuleAction::Deny => {
|
||||
match session
|
||||
.persist_network_policy_amendment(
|
||||
&network_policy_amendment,
|
||||
&network_approval_context,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {
|
||||
session
|
||||
.record_network_policy_amendment_message(
|
||||
&turn_context.sub_id,
|
||||
&network_policy_amendment,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
Err(err) => {
|
||||
let message =
|
||||
format!("Failed to apply network policy amendment: {err}");
|
||||
warn!("{message}");
|
||||
session
|
||||
.send_event_raw(Event {
|
||||
id: turn_context.sub_id.clone(),
|
||||
msg: EventMsg::Warning(WarningEvent { message }),
|
||||
})
|
||||
.await;
|
||||
ReviewDecision::ApprovedForSession => PendingApprovalDecision::AllowForSession,
|
||||
ReviewDecision::NetworkPolicyAmendment {
|
||||
network_policy_amendment,
|
||||
} => match network_policy_amendment.action {
|
||||
NetworkPolicyRuleAction::Allow => {
|
||||
match session
|
||||
.persist_network_policy_amendment(
|
||||
&network_policy_amendment,
|
||||
&network_approval_context,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {
|
||||
session
|
||||
.record_network_policy_amendment_message(
|
||||
&turn_context.sub_id,
|
||||
&network_policy_amendment,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
Err(err) => {
|
||||
let message =
|
||||
format!("Failed to apply network policy amendment: {err}");
|
||||
warn!("{message}");
|
||||
session
|
||||
.send_event_raw(Event {
|
||||
id: turn_context.sub_id.clone(),
|
||||
msg: EventMsg::Warning(WarningEvent { message }),
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
PendingApprovalDecision::AllowForSession
|
||||
}
|
||||
NetworkPolicyRuleAction::Deny => {
|
||||
match session
|
||||
.persist_network_policy_amendment(
|
||||
&network_policy_amendment,
|
||||
&network_approval_context,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {
|
||||
session
|
||||
.record_network_policy_amendment_message(
|
||||
&turn_context.sub_id,
|
||||
&network_policy_amendment,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
Err(err) => {
|
||||
let message =
|
||||
format!("Failed to apply network policy amendment: {err}");
|
||||
warn!("{message}");
|
||||
session
|
||||
.send_event_raw(Event {
|
||||
id: turn_context.sub_id.clone(),
|
||||
msg: EventMsg::Warning(WarningEvent { message }),
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
if let Some(owner_call) = owner_call.as_ref() {
|
||||
self.record_call_outcome(
|
||||
&owner_call.registration_id,
|
||||
NetworkApprovalOutcome::DeniedByUser,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
cache_session_deny = true;
|
||||
PendingApprovalDecision::Deny
|
||||
}
|
||||
},
|
||||
ReviewDecision::Denied | ReviewDecision::Abort => {
|
||||
if let Some(owner_call) = owner_call.as_ref() {
|
||||
self.record_call_outcome(
|
||||
&owner_call.registration_id,
|
||||
@@ -466,36 +504,8 @@ impl NetworkApprovalService {
|
||||
)
|
||||
.await;
|
||||
}
|
||||
cache_session_deny = true;
|
||||
PendingApprovalDecision::Deny
|
||||
}
|
||||
},
|
||||
ReviewDecision::Denied | ReviewDecision::Abort => {
|
||||
if routes_approval_to_guardian(&turn_context) {
|
||||
let timeout_message = take_guardian_timeout_message(
|
||||
session.as_ref(),
|
||||
&Self::approval_id_for_key(&key),
|
||||
)
|
||||
.await;
|
||||
if let Some(owner_call) = owner_call.as_ref() {
|
||||
let outcome = if let Some(message) = timeout_message {
|
||||
NetworkApprovalOutcome::TimedOutByReviewer(message)
|
||||
} else {
|
||||
NetworkApprovalOutcome::DeniedByPolicy(
|
||||
GUARDIAN_REJECTION_MESSAGE.to_string(),
|
||||
)
|
||||
};
|
||||
self.record_call_outcome(&owner_call.registration_id, outcome)
|
||||
.await;
|
||||
}
|
||||
} else if let Some(owner_call) = owner_call.as_ref() {
|
||||
self.record_call_outcome(
|
||||
&owner_call.registration_id,
|
||||
NetworkApprovalOutcome::DeniedByUser,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
PendingApprovalDecision::Deny
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ use crate::error::CodexErr;
|
||||
use crate::error::SandboxErr;
|
||||
use crate::exec::ExecToolCallOutput;
|
||||
use crate::guardian::GUARDIAN_REJECTION_MESSAGE;
|
||||
use crate::guardian::GUARDIAN_TIMEOUT_MESSAGE;
|
||||
use crate::guardian::routes_approval_to_guardian;
|
||||
use crate::guardian::take_guardian_timeout_message;
|
||||
use crate::network_policy_decision::network_approval_context_from_payload;
|
||||
use crate::tools::network_approval::DeferredNetworkApproval;
|
||||
use crate::tools::network_approval::NetworkApprovalMode;
|
||||
@@ -19,6 +19,7 @@ use crate::tools::network_approval::begin_network_approval;
|
||||
use crate::tools::network_approval::finish_deferred_network_approval;
|
||||
use crate::tools::network_approval::finish_immediate_network_approval;
|
||||
use crate::tools::sandboxing::ApprovalCtx;
|
||||
use crate::tools::sandboxing::ApprovalOutcome;
|
||||
use crate::tools::sandboxing::ExecApprovalRequirement;
|
||||
use crate::tools::sandboxing::SandboxAttempt;
|
||||
use crate::tools::sandboxing::SandboxOverride;
|
||||
@@ -42,23 +43,13 @@ pub(crate) struct OrchestratorRunResult<Out> {
|
||||
pub deferred_network_approval: Option<DeferredNetworkApproval>,
|
||||
}
|
||||
|
||||
async fn approval_denial_tool_error(
|
||||
tool_ctx: &ToolCtx,
|
||||
turn_ctx: &crate::codex::TurnContext,
|
||||
) -> ToolError {
|
||||
if routes_approval_to_guardian(turn_ctx)
|
||||
&& let Some(message) =
|
||||
take_guardian_timeout_message(tool_ctx.session.as_ref(), &tool_ctx.call_id).await
|
||||
{
|
||||
ToolError::Message(message)
|
||||
fn approval_denial_tool_error(turn_ctx: &crate::codex::TurnContext) -> ToolError {
|
||||
let reason = if routes_approval_to_guardian(turn_ctx) {
|
||||
GUARDIAN_REJECTION_MESSAGE.to_string()
|
||||
} else {
|
||||
let reason = if routes_approval_to_guardian(turn_ctx) {
|
||||
GUARDIAN_REJECTION_MESSAGE.to_string()
|
||||
} else {
|
||||
"rejected by user".to_string()
|
||||
};
|
||||
ToolError::Rejected(reason)
|
||||
}
|
||||
"rejected by user".to_string()
|
||||
};
|
||||
ToolError::Rejected(reason)
|
||||
}
|
||||
|
||||
impl ToolOrchestrator {
|
||||
@@ -157,25 +148,32 @@ impl ToolOrchestrator {
|
||||
retry_reason: reason,
|
||||
network_approval_context: None,
|
||||
};
|
||||
let decision = tool.start_approval_async(req, approval_ctx).await;
|
||||
let approval_outcome = tool.start_approval_async(req, approval_ctx).await;
|
||||
let otel_source = if routes_approval_to_guardian(turn_ctx) {
|
||||
otel_automated_reviewer.clone()
|
||||
} else {
|
||||
otel_user.clone()
|
||||
};
|
||||
let decision = approval_outcome.decision_for_telemetry();
|
||||
|
||||
otel.tool_decision(otel_tn, otel_ci, &decision, otel_source);
|
||||
|
||||
match decision {
|
||||
ReviewDecision::Denied | ReviewDecision::Abort => {
|
||||
return Err(approval_denial_tool_error(tool_ctx, turn_ctx).await);
|
||||
match approval_outcome {
|
||||
ApprovalOutcome::TimedOut => {
|
||||
return Err(ToolError::Message(GUARDIAN_TIMEOUT_MESSAGE.to_string()));
|
||||
}
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. }
|
||||
| ReviewDecision::ApprovedForSession => {}
|
||||
ReviewDecision::NetworkPolicyAmendment {
|
||||
ApprovalOutcome::Decision(ReviewDecision::Denied)
|
||||
| ApprovalOutcome::Decision(ReviewDecision::Abort) => {
|
||||
return Err(approval_denial_tool_error(turn_ctx));
|
||||
}
|
||||
ApprovalOutcome::Decision(
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. }
|
||||
| ReviewDecision::ApprovedForSession,
|
||||
) => {}
|
||||
ApprovalOutcome::Decision(ReviewDecision::NetworkPolicyAmendment {
|
||||
network_policy_amendment,
|
||||
} => match network_policy_amendment.action {
|
||||
}) => match network_policy_amendment.action {
|
||||
NetworkPolicyRuleAction::Allow => {}
|
||||
NetworkPolicyRuleAction::Deny => {
|
||||
return Err(ToolError::Rejected("rejected by user".to_string()));
|
||||
@@ -306,24 +304,31 @@ impl ToolOrchestrator {
|
||||
network_approval_context: network_approval_context.clone(),
|
||||
};
|
||||
|
||||
let decision = tool.start_approval_async(req, approval_ctx).await;
|
||||
let approval_outcome = tool.start_approval_async(req, approval_ctx).await;
|
||||
let otel_source = if routes_approval_to_guardian(turn_ctx) {
|
||||
otel_automated_reviewer
|
||||
} else {
|
||||
otel_user
|
||||
};
|
||||
let decision = approval_outcome.decision_for_telemetry();
|
||||
otel.tool_decision(otel_tn, otel_ci, &decision, otel_source);
|
||||
|
||||
match decision {
|
||||
ReviewDecision::Denied | ReviewDecision::Abort => {
|
||||
return Err(approval_denial_tool_error(tool_ctx, turn_ctx).await);
|
||||
match approval_outcome {
|
||||
ApprovalOutcome::TimedOut => {
|
||||
return Err(ToolError::Message(GUARDIAN_TIMEOUT_MESSAGE.to_string()));
|
||||
}
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. }
|
||||
| ReviewDecision::ApprovedForSession => {}
|
||||
ReviewDecision::NetworkPolicyAmendment {
|
||||
ApprovalOutcome::Decision(ReviewDecision::Denied)
|
||||
| ApprovalOutcome::Decision(ReviewDecision::Abort) => {
|
||||
return Err(approval_denial_tool_error(turn_ctx));
|
||||
}
|
||||
ApprovalOutcome::Decision(
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. }
|
||||
| ReviewDecision::ApprovedForSession,
|
||||
) => {}
|
||||
ApprovalOutcome::Decision(ReviewDecision::NetworkPolicyAmendment {
|
||||
network_policy_amendment,
|
||||
} => match network_policy_amendment.action {
|
||||
}) => match network_policy_amendment.action {
|
||||
NetworkPolicyRuleAction::Allow => {}
|
||||
NetworkPolicyRuleAction::Deny => {
|
||||
return Err(ToolError::Rejected("rejected by user".to_string()));
|
||||
|
||||
@@ -14,6 +14,7 @@ use crate::sandboxing::SandboxPermissions;
|
||||
use crate::sandboxing::execute_env;
|
||||
use crate::tools::sandboxing::Approvable;
|
||||
use crate::tools::sandboxing::ApprovalCtx;
|
||||
use crate::tools::sandboxing::ApprovalOutcome;
|
||||
use crate::tools::sandboxing::ExecApprovalRequirement;
|
||||
use crate::tools::sandboxing::SandboxAttempt;
|
||||
use crate::tools::sandboxing::Sandboxable;
|
||||
@@ -128,7 +129,7 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
|
||||
&'a mut self,
|
||||
req: &'a ApplyPatchRequest,
|
||||
ctx: ApprovalCtx<'a>,
|
||||
) -> BoxFuture<'a, ReviewDecision> {
|
||||
) -> BoxFuture<'a, ApprovalOutcome> {
|
||||
let session = ctx.session;
|
||||
let turn = ctx.turn;
|
||||
let call_id = ctx.call_id.to_string();
|
||||
@@ -138,10 +139,12 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
|
||||
Box::pin(async move {
|
||||
if routes_approval_to_guardian(turn) {
|
||||
let action = ApplyPatchRuntime::build_guardian_review_request(req, ctx.call_id);
|
||||
return review_approval_request(session, turn, action, retry_reason).await;
|
||||
return review_approval_request(session, turn, action, retry_reason)
|
||||
.await
|
||||
.into();
|
||||
}
|
||||
if req.permissions_preapproved && retry_reason.is_none() {
|
||||
return ReviewDecision::Approved;
|
||||
return ApprovalOutcome::Decision(ReviewDecision::Approved);
|
||||
}
|
||||
if let Some(reason) = retry_reason {
|
||||
let rx_approve = session
|
||||
@@ -153,7 +156,7 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
|
||||
/*grant_root*/ None,
|
||||
)
|
||||
.await;
|
||||
return rx_approve.await.unwrap_or_default();
|
||||
return ApprovalOutcome::Decision(rx_approve.await.unwrap_or_default());
|
||||
}
|
||||
|
||||
with_cached_approval(
|
||||
@@ -170,6 +173,7 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
|
||||
},
|
||||
)
|
||||
.await
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use crate::tools::runtimes::build_sandbox_command;
|
||||
use crate::tools::runtimes::maybe_wrap_shell_lc_with_snapshot;
|
||||
use crate::tools::sandboxing::Approvable;
|
||||
use crate::tools::sandboxing::ApprovalCtx;
|
||||
use crate::tools::sandboxing::ApprovalOutcome;
|
||||
use crate::tools::sandboxing::ExecApprovalRequirement;
|
||||
use crate::tools::sandboxing::SandboxAttempt;
|
||||
use crate::tools::sandboxing::SandboxOverride;
|
||||
@@ -36,7 +37,6 @@ use crate::tools::sandboxing::sandbox_override_for_first_attempt;
|
||||
use crate::tools::sandboxing::with_cached_approval;
|
||||
use codex_network_proxy::NetworkProxy;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_sandboxing::SandboxablePreference;
|
||||
use futures::future::BoxFuture;
|
||||
use std::collections::HashMap;
|
||||
@@ -143,7 +143,7 @@ impl Approvable<ShellRequest> for ShellRuntime {
|
||||
&'a mut self,
|
||||
req: &'a ShellRequest,
|
||||
ctx: ApprovalCtx<'a>,
|
||||
) -> BoxFuture<'a, ReviewDecision> {
|
||||
) -> BoxFuture<'a, ApprovalOutcome> {
|
||||
let keys = self.approval_keys(req);
|
||||
let command = req.command.clone();
|
||||
let cwd = req.cwd.clone();
|
||||
@@ -167,7 +167,8 @@ impl Approvable<ShellRequest> for ShellRuntime {
|
||||
},
|
||||
retry_reason,
|
||||
)
|
||||
.await;
|
||||
.await
|
||||
.into();
|
||||
}
|
||||
with_cached_approval(&session.services, "shell", keys, move || async move {
|
||||
let available_decisions = None;
|
||||
@@ -190,6 +191,7 @@ impl Approvable<ShellRequest> for ShellRuntime {
|
||||
.await
|
||||
})
|
||||
.await
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ use crate::exec::ExecCapturePolicy;
|
||||
use crate::exec::ExecExpiration;
|
||||
use crate::exec::ExecToolCallOutput;
|
||||
use crate::exec::is_likely_sandbox_denied;
|
||||
use crate::guardian::GUARDIAN_TIMEOUT_MESSAGE;
|
||||
use crate::guardian::GuardianApprovalRequest;
|
||||
use crate::guardian::review_approval_request;
|
||||
use crate::guardian::routes_approval_to_guardian;
|
||||
use crate::guardian::take_guardian_timeout_message;
|
||||
use crate::sandboxing::ExecOptions;
|
||||
use crate::sandboxing::ExecRequest;
|
||||
use crate::sandboxing::SandboxPermissions;
|
||||
@@ -16,6 +16,7 @@ use crate::shell::ShellType;
|
||||
use crate::skills::SkillMetadata;
|
||||
use crate::tools::runtimes::ExecveSessionApproval;
|
||||
use crate::tools::runtimes::build_sandbox_command;
|
||||
use crate::tools::sandboxing::ApprovalOutcome;
|
||||
use crate::tools::sandboxing::SandboxAttempt;
|
||||
use crate::tools::sandboxing::ToolCtx;
|
||||
use crate::tools::sandboxing::ToolError;
|
||||
@@ -423,7 +424,7 @@ impl CoreShellActionProvider {
|
||||
stopwatch: &Stopwatch,
|
||||
additional_permissions: Option<PermissionProfile>,
|
||||
decision_source: &DecisionSource,
|
||||
) -> anyhow::Result<ReviewDecision> {
|
||||
) -> anyhow::Result<ApprovalOutcome> {
|
||||
let command = join_program_and_argv(program, argv);
|
||||
let workdir = workdir.to_path_buf();
|
||||
let session = self.session.clone();
|
||||
@@ -447,7 +448,8 @@ impl CoreShellActionProvider {
|
||||
},
|
||||
/*retry_reason*/ None,
|
||||
)
|
||||
.await;
|
||||
.await
|
||||
.into();
|
||||
}
|
||||
let available_decisions = vec![
|
||||
Some(ReviewDecision::Approved),
|
||||
@@ -486,6 +488,7 @@ impl CoreShellActionProvider {
|
||||
Some(available_decisions),
|
||||
)
|
||||
.await
|
||||
.into()
|
||||
})
|
||||
.await)
|
||||
}
|
||||
@@ -549,15 +552,20 @@ impl CoreShellActionProvider {
|
||||
)
|
||||
.await?
|
||||
{
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. } => {
|
||||
ApprovalOutcome::TimedOut => {
|
||||
EscalationDecision::deny(Some(GUARDIAN_TIMEOUT_MESSAGE.to_string()))
|
||||
}
|
||||
ApprovalOutcome::Decision(
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. },
|
||||
) => {
|
||||
if needs_escalation {
|
||||
EscalationDecision::escalate(escalation_execution.clone())
|
||||
} else {
|
||||
EscalationDecision::run()
|
||||
}
|
||||
}
|
||||
ReviewDecision::ApprovedForSession => {
|
||||
ApprovalOutcome::Decision(ReviewDecision::ApprovedForSession) => {
|
||||
// Currently, we only add session approvals for
|
||||
// skill scripts because we are storing only the
|
||||
// `program` whereas prefix rules may be restricted by a longer prefix.
|
||||
@@ -584,9 +592,9 @@ impl CoreShellActionProvider {
|
||||
EscalationDecision::run()
|
||||
}
|
||||
}
|
||||
ReviewDecision::NetworkPolicyAmendment {
|
||||
ApprovalOutcome::Decision(ReviewDecision::NetworkPolicyAmendment {
|
||||
network_policy_amendment,
|
||||
} => match network_policy_amendment.action {
|
||||
}) => match network_policy_amendment.action {
|
||||
NetworkPolicyRuleAction::Allow => {
|
||||
if needs_escalation {
|
||||
EscalationDecision::escalate(escalation_execution.clone())
|
||||
@@ -598,27 +606,11 @@ impl CoreShellActionProvider {
|
||||
EscalationDecision::deny(Some("User denied execution".to_string()))
|
||||
}
|
||||
},
|
||||
ReviewDecision::Denied => {
|
||||
if let Some(message) =
|
||||
take_guardian_timeout_message(self.session.as_ref(), &self.call_id)
|
||||
.await
|
||||
{
|
||||
EscalationDecision::deny(Some(message))
|
||||
} else {
|
||||
EscalationDecision::deny(Some("User denied execution".to_string()))
|
||||
}
|
||||
ApprovalOutcome::Decision(ReviewDecision::Denied) => {
|
||||
EscalationDecision::deny(Some("User denied execution".to_string()))
|
||||
}
|
||||
ReviewDecision::Abort => {
|
||||
if let Some(message) =
|
||||
take_guardian_timeout_message(self.session.as_ref(), &self.call_id)
|
||||
.await
|
||||
{
|
||||
EscalationDecision::deny(Some(message))
|
||||
} else {
|
||||
EscalationDecision::deny(Some(
|
||||
"User cancelled execution".to_string(),
|
||||
))
|
||||
}
|
||||
ApprovalOutcome::Decision(ReviewDecision::Abort) => {
|
||||
EscalationDecision::deny(Some("User cancelled execution".to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ use crate::tools::runtimes::maybe_wrap_shell_lc_with_snapshot;
|
||||
use crate::tools::runtimes::shell::zsh_fork_backend;
|
||||
use crate::tools::sandboxing::Approvable;
|
||||
use crate::tools::sandboxing::ApprovalCtx;
|
||||
use crate::tools::sandboxing::ApprovalOutcome;
|
||||
use crate::tools::sandboxing::ExecApprovalRequirement;
|
||||
use crate::tools::sandboxing::SandboxAttempt;
|
||||
use crate::tools::sandboxing::SandboxOverride;
|
||||
@@ -39,7 +40,6 @@ use crate::unified_exec::UnifiedExecProcess;
|
||||
use crate::unified_exec::UnifiedExecProcessManager;
|
||||
use codex_network_proxy::NetworkProxy;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_sandboxing::SandboxablePreference;
|
||||
use futures::future::BoxFuture;
|
||||
use std::collections::HashMap;
|
||||
@@ -111,7 +111,7 @@ impl Approvable<UnifiedExecRequest> for UnifiedExecRuntime<'_> {
|
||||
&'b mut self,
|
||||
req: &'b UnifiedExecRequest,
|
||||
ctx: ApprovalCtx<'b>,
|
||||
) -> BoxFuture<'b, ReviewDecision> {
|
||||
) -> BoxFuture<'b, ApprovalOutcome> {
|
||||
let keys = self.approval_keys(req);
|
||||
let session = ctx.session;
|
||||
let turn = ctx.turn;
|
||||
@@ -136,7 +136,8 @@ impl Approvable<UnifiedExecRequest> for UnifiedExecRuntime<'_> {
|
||||
},
|
||||
retry_reason,
|
||||
)
|
||||
.await;
|
||||
.await
|
||||
.into();
|
||||
}
|
||||
with_cached_approval(&session.services, "unified_exec", keys, || async move {
|
||||
let available_decisions = None;
|
||||
@@ -159,6 +160,7 @@ impl Approvable<UnifiedExecRequest> for UnifiedExecRuntime<'_> {
|
||||
.await
|
||||
})
|
||||
.await
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
use crate::codex::Session;
|
||||
use crate::codex::TurnContext;
|
||||
use crate::error::CodexErr;
|
||||
use crate::guardian::GuardianApprovalDecision;
|
||||
#[cfg(test)]
|
||||
use crate::protocol::SandboxPolicy;
|
||||
use crate::sandboxing::ExecOptions;
|
||||
@@ -115,6 +116,36 @@ where
|
||||
decision
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum ApprovalOutcome {
|
||||
Decision(ReviewDecision),
|
||||
TimedOut,
|
||||
}
|
||||
|
||||
impl ApprovalOutcome {
|
||||
pub(crate) fn decision_for_telemetry(&self) -> ReviewDecision {
|
||||
match self {
|
||||
Self::Decision(decision) => decision.clone(),
|
||||
Self::TimedOut => ReviewDecision::Denied,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ReviewDecision> for ApprovalOutcome {
|
||||
fn from(value: ReviewDecision) -> Self {
|
||||
Self::Decision(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GuardianApprovalDecision> for ApprovalOutcome {
|
||||
fn from(value: GuardianApprovalDecision) -> Self {
|
||||
match value {
|
||||
GuardianApprovalDecision::TimedOut => Self::TimedOut,
|
||||
decision => Self::Decision(decision.into_review_decision()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct ApprovalCtx<'a> {
|
||||
pub session: &'a Arc<Session>,
|
||||
@@ -281,7 +312,7 @@ pub(crate) trait Approvable<Req> {
|
||||
&'a mut self,
|
||||
req: &'a Req,
|
||||
ctx: ApprovalCtx<'a>,
|
||||
) -> BoxFuture<'a, ReviewDecision>;
|
||||
) -> BoxFuture<'a, ApprovalOutcome>;
|
||||
}
|
||||
|
||||
pub(crate) trait Sandboxable {
|
||||
|
||||
Reference in New Issue
Block a user