From 6e863c77c0f0da7a635e4ebd98de616934af1303 Mon Sep 17 00:00:00 2001 From: Katia Bazzi Date: Thu, 11 Jun 2026 20:19:51 -0700 Subject: [PATCH] Gate Guardian manual fallback behind feature flag --- codex-rs/core/config.schema.json | 6 ++ codex-rs/core/src/session/mod.rs | 6 +- codex-rs/core/tests/suite/guardian_review.rs | 97 ++++++++++++++++++++ codex-rs/features/src/lib.rs | 8 ++ codex-rs/features/src/tests.rs | 11 +++ 5 files changed, 126 insertions(+), 2 deletions(-) diff --git a/codex-rs/core/config.schema.json b/codex-rs/core/config.schema.json index 9ed02fdd17..c4ffa54814 100644 --- a/codex-rs/core/config.schema.json +++ b/codex-rs/core/config.schema.json @@ -492,6 +492,9 @@ "guardian_approval": { "type": "boolean" }, + "guardian_manual_approval_fallback": { + "type": "boolean" + }, "hooks": { "type": "boolean" }, @@ -4624,6 +4627,9 @@ "guardian_approval": { "type": "boolean" }, + "guardian_manual_approval_fallback": { + "type": "boolean" + }, "hooks": { "type": "boolean" }, diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs index e249af8e49..6e196c6e63 100644 --- a/codex-rs/core/src/session/mod.rs +++ b/codex-rs/core/src/session/mod.rs @@ -618,8 +618,10 @@ impl Codex { metrics_service_name, app_server_client_name: None, app_server_client_version: None, - manual_approval_fallback_enabled: - crate::guardian::can_fallback_to_manual_after_guardian_timeout( + manual_approval_fallback_enabled: config + .features + .enabled(Feature::GuardianManualApprovalFallback) + && crate::guardian::can_fallback_to_manual_after_guardian_timeout( &client_session_source, ), session_source, diff --git a/codex-rs/core/tests/suite/guardian_review.rs b/codex-rs/core/tests/suite/guardian_review.rs index fb6ff08bec..ffd0af4306 100644 --- a/codex-rs/core/tests/suite/guardian_review.rs +++ b/codex-rs/core/tests/suite/guardian_review.rs @@ -3,6 +3,7 @@ use anyhow::Result; use codex_core::config::Constrained; use codex_core::sandboxing::SandboxPermissions; +use codex_features::Feature; use codex_protocol::config_types::ApprovalsReviewer; use codex_protocol::protocol::AskForApproval; use codex_protocol::protocol::EventMsg; @@ -70,6 +71,9 @@ async fn guardian_timeout_falls_back_to_manual_approval_end_to_end() -> Result<( let mut builder = test_codex() .with_session_source(SessionSource::Cli) .with_config(move |config| { + let _ = config + .features + .enable(Feature::GuardianManualApprovalFallback); config.permissions.approval_policy = Constrained::allow_any(approval_policy); config .set_legacy_sandbox_policy(sandbox_policy_for_config) @@ -171,6 +175,99 @@ async fn guardian_timeout_falls_back_to_manual_approval_end_to_end() -> Result<( Ok(()) } +#[tokio::test(flavor = "current_thread")] +async fn guardian_timeout_does_not_fallback_by_default() -> Result<()> { + skip_if_no_network!(Ok(())); + skip_if_sandbox!(Ok(())); + + let approval_policy = AskForApproval::OnRequest; + let sandbox_policy = SandboxPolicy::WorkspaceWrite { + writable_roots: vec![], + network_access: false, + exclude_tmpdir_env_var: true, + exclude_slash_tmp: true, + }; + let sandbox_policy_for_config = sandbox_policy.clone(); + let mut builder = test_codex() + .with_session_source(SessionSource::Cli) + .with_config(move |config| { + config.permissions.approval_policy = Constrained::allow_any(approval_policy); + config + .set_legacy_sandbox_policy(sandbox_policy_for_config) + .expect("set sandbox policy"); + }); + + let output_dir = TempDir::new()?; + let output_file = output_dir.path().join("guardian-timeout-no-fallback.txt"); + let command = format!("printf guardian-manual > {}", output_file.display()); + let tool_args = json!({ + "cmd": command, + "yield_time_ms": 1_000_u64, + "sandbox_permissions": SandboxPermissions::RequireEscalated, + "justification": "Exercise disabled Guardian timeout fallback.", + }); + let (_guardian_gate_tx, guardian_gate_rx) = oneshot::channel(); + let (server, _completions) = start_streaming_sse_server(vec![ + vec![StreamingSseChunk { + gate: None, + body: parent_tool_response("exec-call", &tool_args), + }], + vec![ + StreamingSseChunk { + gate: None, + body: sse(vec![ev_response_created("resp-guardian-timeout")]), + }, + StreamingSseChunk { + gate: Some(guardian_gate_rx), + body: sse(vec![ev_completed("resp-guardian-timeout")]), + }, + ], + vec![StreamingSseChunk { + gate: None, + body: parent_done_response(), + }], + ]) + .await; + let test = builder.build_with_streaming_server(&server).await?; + + test.codex + .submit(Op::UserInput { + items: vec![UserInput::Text { + text: "run a command that requires Guardian review".into(), + text_elements: Vec::new(), + }], + final_output_json_schema: None, + responsesapi_client_metadata: None, + additional_context: Default::default(), + thread_settings: codex_protocol::protocol::ThreadSettingsOverrides { + environments: Some(local_selections(test.config.cwd.clone())), + approval_policy: Some(approval_policy), + approvals_reviewer: Some(ApprovalsReviewer::AutoReview), + sandbox_policy: Some(sandbox_policy), + ..Default::default() + }, + }) + .await?; + + server.wait_for_request_count(/*count*/ 2).await; + tokio::time::pause(); + tokio::time::advance(Duration::from_secs(91)).await; + tokio::time::resume(); + + loop { + match wait_for_event(&test.codex, |_| true).await { + EventMsg::ExecApprovalRequest(approval) => { + panic!("manual approval should be disabled: {approval:?}") + } + EventMsg::TurnComplete(_) => break, + _ => {} + } + } + assert!(!output_file.exists()); + + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn guardian_review_session_does_not_inherit_legacy_notify() -> Result<()> { skip_if_no_network!(Ok(())); diff --git a/codex-rs/features/src/lib.rs b/codex-rs/features/src/lib.rs index b30c255165..a6ca8e05b6 100644 --- a/codex-rs/features/src/lib.rs +++ b/codex-rs/features/src/lib.rs @@ -193,6 +193,8 @@ pub enum Feature { DefaultModeRequestUserInput, /// Enable automatic review for approval prompts. GuardianApproval, + /// Fall back to manual approval prompts when automatic approval review times out. + GuardianManualApprovalFallback, /// Enable persisted thread goals and automatic goal continuation. Goals, /// Route MCP tool approval prompts through the MCP elicitation request path. @@ -1128,6 +1130,12 @@ pub const FEATURES: &[FeatureSpec] = &[ stage: Stage::Stable, default_enabled: true, }, + FeatureSpec { + id: Feature::GuardianManualApprovalFallback, + key: "guardian_manual_approval_fallback", + stage: Stage::Stable, + default_enabled: false, + }, FeatureSpec { id: Feature::Goals, key: "goals", diff --git a/codex-rs/features/src/tests.rs b/codex-rs/features/src/tests.rs index b7d158ca36..e79b0e3b18 100644 --- a/codex-rs/features/src/tests.rs +++ b/codex-rs/features/src/tests.rs @@ -132,6 +132,17 @@ fn guardian_approval_is_stable_and_enabled_by_default() { assert_eq!(Feature::GuardianApproval.default_enabled(), true); } +#[test] +fn guardian_manual_approval_fallback_is_stable_and_disabled_by_default() { + let spec = Feature::GuardianManualApprovalFallback.info(); + + assert_eq!(spec.stage, Stage::Stable); + assert_eq!( + Feature::GuardianManualApprovalFallback.default_enabled(), + false + ); +} + #[test] fn request_permissions_is_under_development() { assert_eq!(