From 83545f351497540aa2ca4dffecdbc204fc8c0eb6 Mon Sep 17 00:00:00 2001 From: goodman-oai Date: Mon, 30 Nov 2026 23:10:17 +0000 Subject: [PATCH] Allow model catalogs to omit writable-root sentences (#64837) ## Why The environment context already lists writable paths. An empty catalog template previously fell back to the bundled writable-root sentence, so a model catalog had no way to omit that repeated list. ## What changed Treat an empty `writable_root` or `writable_roots` template as a request to omit the corresponding sentence. Missing, null, invalid nonempty, and oversized templates still use the bundled wording. Suppressed roots leave the full path budget available for denied-read paths and globs and never trigger an omitted-path warning on their own. ## Testing Cover empty singular and plural templates and verify that suppressed roots leave room for denied-read entries. A model-switch scenario checks that Codex appends the updated permissions message once and preserves the earlier conversation, filesystem permissions, and approval settings. GitOrigin-RevId: 105819fb07ff829be8f111b3676656373aeb7892 --- .../core/tests/suite/permissions_messages.rs | 139 +++++++++++++++--- codex-rs/core/tests/suite/scenarios.rs | 5 + ..._writable_roots_follow_selected_model.snap | 134 +++++++++++++++++ .../prompts/src/permissions_instructions.rs | 72 ++++++--- .../writable_roots.rs | 6 +- .../writable_roots_tests.rs | 34 ++++- .../src/permissions_instructions_tests.rs | 50 +++++++ codex-rs/protocol/src/openai_models.rs | 6 +- 8 files changed, 397 insertions(+), 49 deletions(-) create mode 100644 codex-rs/core/tests/suite/snapshots/all__suite__scenarios__catalog_empty_writable_roots_follow_selected_model.snap diff --git a/codex-rs/core/tests/suite/permissions_messages.rs b/codex-rs/core/tests/suite/permissions_messages.rs index 05e111df87..11ac1e7051 100644 --- a/codex-rs/core/tests/suite/permissions_messages.rs +++ b/codex-rs/core/tests/suite/permissions_messages.rs @@ -975,6 +975,28 @@ const WORKSPACE_PERMISSIONS_PREFIX: &str = concat!( "## Catalog denied reads\n{facts}\nCatalog footer."; "override plural" )] +#[test_case( + 1, + PermissionMessages { + writable_root: Some("".into()), + writable_roots: Some("Catalog plural: {{ roots }}!".into()), + ..Default::default() + }, + "", + "## Denied filesystem reads\n{facts}"; + "empty singular" +)] +#[test_case( + 2, + PermissionMessages { + writable_root: Some("Catalog single: {{ roots }}!".into()), + writable_roots: Some("".into()), + ..Default::default() + }, + "", + "## Denied filesystem reads\n{facts}"; + "empty plural" +)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn permissions_message_includes_writable_roots( root_count: usize, @@ -1073,9 +1095,16 @@ async fn permissions_message_includes_writable_roots( .join(", "); let root_sentence = expected_root_sentence.replace("{roots}", &roots); let request = req.single_request(); - let expected = format!( - "{WORKSPACE_PERMISSIONS_PREFIX}{root_sentence}{denied_reads}\n" - ); + let expected_body = [ + WORKSPACE_PERMISSIONS_PREFIX.trim_end_matches('\n'), + root_sentence.as_str(), + denied_reads.trim_start_matches('\n'), + ] + .into_iter() + .filter(|section| !section.is_empty()) + .collect::>() + .join("\n"); + let expected = format!("{expected_body}\n"); assert_eq!(permissions_texts(&request), vec![expected]); assert_eq!( permissions_annotations(&request), @@ -1092,6 +1121,7 @@ async fn permissions_message_includes_writable_roots( pub(super) enum PermissionPathScenario { OmittedPaths, DeniedReads, + EmptyWritableRoots, } pub(super) async fn catalog_permission_paths_model_change_requests( @@ -1108,16 +1138,19 @@ pub(super) async fn catalog_permission_paths_model_change_requests( let models = [(first_slug, "Model A"), (second_slug, "Model B")] .into_iter() .map(|(slug, label)| { - let mut model = model_with_permission_messages( - slug, - serde_json::from_value(json!({ - "writable_root": format!("Wrong {label} single: {{{{ roots }}}}."), - "writable_roots": format!("{label} roots: {{{{ roots }}}}."), - "omitted_paths": format!("{label} omitted paths:"), - "denied_reads": format!("{label} denied reads:\n{{{{ denied_reads }}}}"), - })) - .expect("valid catalog permission messages"), - ); + let mut permissions = serde_json::from_value::(json!({ + "writable_root": format!("Wrong {label} single: {{{{ roots }}}}."), + "writable_roots": format!("{label} roots: {{{{ roots }}}}."), + "omitted_paths": format!("{label} omitted paths:"), + "denied_reads": format!("{label} denied reads:\n{{{{ denied_reads }}}}"), + })) + .expect("valid catalog permission messages"); + if matches!(scenario, PermissionPathScenario::EmptyWritableRoots) && slug == second_slug + { + permissions.writable_root = Some("".into()); + permissions.writable_roots = Some("".into()); + } + let mut model = model_with_permission_messages(slug, permissions); model.use_responses_lite = true; model }) @@ -1155,24 +1188,42 @@ pub(super) async fn catalog_permission_paths_model_change_requests( .try_into() .expect("canonical workspace path should be absolute"); } - config.permissions.approval_policy = Constrained::allow_any(AskForApproval::Never); + config.permissions.approval_policy = Constrained::allow_any(match scenario { + PermissionPathScenario::EmptyWritableRoots => AskForApproval::OnRequest, + PermissionPathScenario::DeniedReads | PermissionPathScenario::OmittedPaths => { + AskForApproval::Never + } + }); + if matches!(scenario, PermissionPathScenario::EmptyWritableRoots) { + config.approvals_reviewer = ApprovalsReviewer::AutoReview; + } // Keep oversized presentation facts out of the denied-read case: filesystem // helpers enforce those policies, and Seatbelt expands every denied ancestor. let suffix = match scenario { - PermissionPathScenario::DeniedReads => "writable".to_string(), + PermissionPathScenario::DeniedReads + | PermissionPathScenario::EmptyWritableRoots => "writable".to_string(), PermissionPathScenario::OmittedPaths => vec!["x".repeat(175); 105].join("/"), }; let cwd = executor_path_uri(&config.cwd).expect("executor cwd URI"); - let roots = (0..2) + // Nine additional roots plus cwd reproduce a ten-root workspace profile. + let extra_root_count = match scenario { + PermissionPathScenario::EmptyWritableRoots => 9, + PermissionPathScenario::DeniedReads | PermissionPathScenario::OmittedPaths => 2, + }; + let roots = (0..extra_root_count) .map(|index| { cwd.join(&format!("catalog-root-{index:03}/{suffix}")) .expect("executor writable root URI") }) .collect::>(); + let network = match scenario { + PermissionPathScenario::EmptyWritableRoots => NetworkSandboxPolicy::Enabled, + PermissionPathScenario::DeniedReads | PermissionPathScenario::OmittedPaths => { + NetworkSandboxPolicy::Restricted + } + }; let mut file_system = PermissionProfile::workspace_write_with_path_uris( - &roots, - NetworkSandboxPolicy::Restricted, - /*exclude_tmpdir_env_var*/ true, + &roots, network, /*exclude_tmpdir_env_var*/ true, /*exclude_slash_tmp*/ true, ) .file_system_sandbox_policy(); @@ -1199,7 +1250,7 @@ pub(super) async fn catalog_permission_paths_model_change_requests( .permissions .set_permission_profile(PermissionProfile::from_runtime_permissions( &file_system, - NetworkSandboxPolicy::Restricted, + network, )) .expect("workspace-write profile should be allowed"); config.workspace_roots = vec![config.cwd.clone()]; @@ -1211,6 +1262,7 @@ pub(super) async fn catalog_permission_paths_model_change_requests( }); let test = builder.build_with_auto_env(&server).await?; submit_text_turn(&test, "Inspect the writable workspace.").await?; + let initial_settings = test.codex.config_snapshot().await; core_test_support::submit_thread_settings( &test.codex, ThreadSettingsOverrides { @@ -1225,12 +1277,27 @@ pub(super) async fn catalog_permission_paths_model_change_requests( ) .await; submit_text_turn(&test, "Continue with the selected model.").await?; + let switched_settings = test.codex.config_snapshot().await; let req3 = mount_sse_once( &server, sse(vec![ev_response_created("resp-3"), ev_completed("resp-3")]), ) .await; submit_text_turn(&test, "Continue without changing permissions.").await?; + let final_settings = test.codex.config_snapshot().await; + for settings in [switched_settings, final_settings] { + assert_eq!(settings.model, second_slug); + assert_eq!( + settings.permission_profile, + initial_settings.permission_profile + ); + assert_eq!(settings.workspace_roots, initial_settings.workspace_roots); + assert_eq!(settings.approval_policy, initial_settings.approval_policy); + assert_eq!( + settings.approvals_reviewer, + initial_settings.approvals_reviewer + ); + } let requests = vec![ req1.single_request(), req2.single_request(), @@ -1241,7 +1308,10 @@ pub(super) async fn catalog_permission_paths_model_change_requests( let first = first[0].clone(); assert!(first.contains("\nModel A roots: ")); assert!(first.contains("catalog-root-000")); - assert_eq!(first.contains("catalog-root-001"), include_denied_reads); + assert_eq!( + first.contains("catalog-root-001"), + !matches!(scenario, PermissionPathScenario::OmittedPaths) + ); if include_denied_reads { let cwd = executor_path_uri(&test.config.cwd)?; let denied_path = cwd.join("catalog-denied")?.inferred_native_path_string(); @@ -1251,20 +1321,43 @@ pub(super) async fn catalog_permission_paths_model_change_requests( assert!(first.ends_with(&format!( "\nModel A denied reads:\nThe active permission profile denies reading these paths/globs. Do not request escalation or additional permissions to read them; these denials are policy restrictions.\n- path `{denied_path}`\n- glob `{denied_glob}`\n" ))); - } else { + } else if matches!(scenario, PermissionPathScenario::OmittedPaths) { assert!(first.ends_with(concat!( "Model A omitted paths:\n", "Additional permission paths/globs are omitted. All restrictions still apply; do not use escalation or additional permissions to bypass omitted read denials.\n", "", ))); } - let second = first.replace("Model A", "Model B"); + let second = if matches!(scenario, PermissionPathScenario::EmptyWritableRoots) { + assert_eq!(initial_settings.approval_policy, AskForApproval::OnRequest); + assert_eq!( + initial_settings.approvals_reviewer, + ApprovalsReviewer::AutoReview + ); + assert_eq!( + initial_settings.permission_profile.network_sandbox_policy(), + NetworkSandboxPolicy::Enabled + ); + assert!(first.contains(AUTO_REVIEW_BODY)); + let root_line = first + .lines() + .find(|line| line.starts_with("Model A roots: ")) + .expect("root sentence"); + assert_eq!(root_line.matches('`').count(), 20); + let environment = requests[0].message_input_texts("user").join("\n"); + assert_eq!(environment.matches(r#""#).count(), 10); + first.replace(&format!("{root_line}\n"), "") + } else { + first.replace("Model A", "Model B") + }; assert_eq!(permissions_texts(&requests[1]), vec![first, second]); assert_eq!( permissions_texts(&requests[2]), permissions_texts(&requests[1]) ); for (request, count) in requests.iter().zip([1, 2, 2]) { + let user_text = request.message_input_texts("user").join("\n"); + assert_eq!(user_text.matches("").count(), 1); assert_eq!( permissions_annotations(request), vec![ diff --git a/codex-rs/core/tests/suite/scenarios.rs b/codex-rs/core/tests/suite/scenarios.rs index 801be6ad20..40d3d13539 100644 --- a/codex-rs/core/tests/suite/scenarios.rs +++ b/codex-rs/core/tests/suite/scenarios.rs @@ -3922,6 +3922,7 @@ async fn compact_filesystem_context(per_environment: bool, snapshot_name: &str) #[test_case::test_case(PermissionPathScenario::OmittedPaths; "omitted_paths")] #[test_case::test_case(PermissionPathScenario::DeniedReads; "denied_reads")] +#[test_case::test_case(PermissionPathScenario::EmptyWritableRoots; "empty_writable_roots")] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn catalog_permission_paths_follow_selected_model( scenario: PermissionPathScenario, @@ -3970,6 +3971,10 @@ async fn catalog_permission_paths_follow_selected_model( "catalog_denied_reads_follow_selected_model", "Catalog denied-read wording follows the selected model, appending changed permissions once while preserving prior input, denial facts, and mandatory policy warnings.", ), + PermissionPathScenario::EmptyWritableRoots => ( + "catalog_empty_writable_roots_follow_selected_model", + "Switching to empty root overrides appends permissions without the root sentence once, preserving automatic review, the ten-root filesystem profile, and earlier history.", + ), }; insta::assert_snapshot!( snapshot_name, diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__catalog_empty_writable_roots_follow_selected_model.snap b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__catalog_empty_writable_roots_follow_selected_model.snap new file mode 100644 index 0000000000..ff2b62f918 --- /dev/null +++ b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__catalog_empty_writable_roots_follow_selected_model.snap @@ -0,0 +1,134 @@ +--- +source: core/tests/suite/scenarios.rs +expression: "context_snapshot::format_context_snapshot(description, &entries,\n&ContextSnapshotOptions::default().include_request_settings(),)" +--- +Scenario: Switching to empty root overrides appends permissions without the root sentence once, preserving automatic review, the ten-root filesystem profile, and earlier history. + +## Window 1 +Settings: + include: ["reasoning.encrypted_content"] + model: "catalog-writable-roots-a" + parallel_tool_calls: false + prompt_cache_key: "" + reasoning: {"context":"all_turns","summary":"auto"} + store: false + stream: true + stream_options: {"reasoning_summary_delivery":"sequential_cutoff"} + tool_choice: "auto" +-- request 1 (request) -- +00:additional_tools/developer (2; hash=ba09b4f2f05f1575): + - namespace/functions; hash=3fd5e7004553e7b9 + - function/exec_command + - function/write_stdin + - function/request_user_input + - function/view_image + - namespace/multi_agent_v1: Tools for spawning and managing sub-agents.; hash=c826e5b07fd2820f + - function/close_agent + - function/resume_agent + - function/send_input + - function/spawn_agent + - function/wait_agent +01:message/developer: + Help with the workspace. +02:message/developer: + + Filesystem sandboxing defines which files can be read or written. `sandbox_mode` is `workspace-write`: T...ctories requires approval. Network access is enabled. [hash=4bea877c3f99797a] + # Escalation Requests + + Commands are run outside the sandbox if they are approved by the user, or match an existing rule that al...hell control operators, including but not limited to: [hash=d24ebf5fa4e4b9bb] + + - Pipes: | + - Logical operators: &&, || + + - ["npm", "run", "dev"] + - ["gh", "pr", "check"] + - ["cargo", "test"] + + + `approvals_reviewer` is `auto_review`: Sandbox escalations with require_escalated will be reviewed for c...he risk and send a final message to ask for approval. [hash=c592d119d24cd2d6] + Model A roots: . + +03:message/user: + + + + + + + +04:message/user: + Inspect the writable workspace. + +## Window 2 (after request 1) +Settings: relative to window 1 + model: "catalog-writable-roots-b" +-- request 2 (request) -- +00:additional_tools/developer (2; hash=ba09b4f2f05f1575): + - namespace/functions; hash=3fd5e7004553e7b9 + - function/exec_command + - function/write_stdin + - function/request_user_input + - function/view_image + - namespace/multi_agent_v1: Tools for spawning and managing sub-agents.; hash=c826e5b07fd2820f + - function/close_agent + - function/resume_agent + - function/send_input + - function/spawn_agent + - function/wait_agent +01:message/developer: + Help with the workspace. +02:message/developer: + + Filesystem sandboxing defines which files can be read or written. `sandbox_mode` is `workspace-write`: T...ctories requires approval. Network access is enabled. [hash=4bea877c3f99797a] + # Escalation Requests + + Commands are run outside the sandbox if they are approved by the user, or match an existing rule that al...hell control operators, including but not limited to: [hash=d24ebf5fa4e4b9bb] + + - Pipes: | + - Logical operators: &&, || + + - ["npm", "run", "dev"] + - ["gh", "pr", "check"] + - ["cargo", "test"] + + + `approvals_reviewer` is `auto_review`: Sandbox escalations with require_escalated will be reviewed for c...he risk and send a final message to ask for approval. [hash=c592d119d24cd2d6] + Model A roots: . + +03:message/user: + + + + + + + +04:message/user: + Inspect the writable workspace. +05:message/developer: + + The current model is catalog-writable-roots-b. + +06:message/developer: + + Filesystem sandboxing defines which files can be read or written. `sandbox_mode` is `workspace-write`: T...ctories requires approval. Network access is enabled. [hash=4bea877c3f99797a] + # Escalation Requests + + Commands are run outside the sandbox if they are approved by the user, or match an existing rule that al...hell control operators, including but not limited to: [hash=d24ebf5fa4e4b9bb] + + - Pipes: | + - Logical operators: &&, || + + Good examples of prefixes: + - ["npm", "run", "dev"] + - ["gh", "pr", "check"] + - ["cargo", "test"] + + + `approvals_reviewer` is `auto_review`: Sandbox escalations with require_escalated will be reviewed for c...he risk and send a final message to ask for approval. [hash=c592d119d24cd2d6] + +07:message/user: + Continue with the selected model. +-- request 3 (request) -- +08:message/user: + Continue without changing permissions. diff --git a/codex-rs/prompts/src/permissions_instructions.rs b/codex-rs/prompts/src/permissions_instructions.rs index 0a06987780..edf6af94cd 100644 --- a/codex-rs/prompts/src/permissions_instructions.rs +++ b/codex-rs/prompts/src/permissions_instructions.rs @@ -126,25 +126,56 @@ impl PermissionsInstructions { let mut remaining_path_bytes = MAX_PERMISSION_PATH_BYTES - OMITTED_PERMISSION_PATHS.len() - 1; let mut paths_omitted = false; - let mut bounded_paths = |paths: &[String]| { - paths - .iter() - .filter(|path| { - // Reserve up to ten bytes for each entry's label, quoting, and separator. - if let Some(remaining) = remaining_path_bytes.checked_sub(path.len() + 10) { - remaining_path_bytes = remaining; - true - } else { - paths_omitted = true; - false - } - }) - .cloned() - .collect::>() + let bounded_paths = + |paths: &[String], remaining_path_bytes: &mut usize, paths_omitted: &mut bool| { + paths + .iter() + .filter(|path| { + // Reserve up to ten bytes for each entry's label, quoting, and separator. + if let Some(remaining) = remaining_path_bytes.checked_sub(path.len() + 10) { + *remaining_path_bytes = remaining; + true + } else { + *paths_omitted = true; + false + } + }) + .cloned() + .collect::>() + }; + let initial_path_bytes = remaining_path_bytes; + let writable_roots = bounded_paths( + context.writable_roots, + &mut remaining_path_bytes, + &mut paths_omitted, + ); + let writable_roots_text = + writable_roots_text(&writable_roots, approval_context.permission_messages); + let path_messages = approval_context.permission_messages; + let roots_suppressed = match writable_roots.len() { + 0 => match context.writable_roots.len() { + 1 => path_messages.writable_root.catalog_override() == Some(""), + 2.. => path_messages.writable_roots.catalog_override() == Some(""), + _ => false, + }, + _ => writable_roots_text.is_none(), }; - let writable_roots = bounded_paths(context.writable_roots); - let denied_read_paths = bounded_paths(context.denied_read_paths); - let denied_read_globs = bounded_paths(context.denied_read_globs); + if roots_suppressed { + // An empty catalog override suppresses the selected sentence, so its paths + // do not consume the budget shared with the visible denied-read entries. + remaining_path_bytes = initial_path_bytes; + paths_omitted = false; + } + let denied_read_paths = bounded_paths( + context.denied_read_paths, + &mut remaining_path_bytes, + &mut paths_omitted, + ); + let denied_read_globs = bounded_paths( + context.denied_read_globs, + &mut remaining_path_bytes, + &mut paths_omitted, + ); let mut text = String::new(); let sandbox = sandbox_text( context.sandbox_mode, @@ -164,12 +195,9 @@ impl PermissionsInstructions { context.request_permissions_tool_enabled, ), ); - if let Some(writable_roots) = - writable_roots_text(&writable_roots, approval_context.permission_messages) - { + if let Some(writable_roots) = writable_roots_text { append_section(&mut text, &writable_roots); } - let path_messages = approval_context.permission_messages; if let Some(denied_reads) = denied_reads_text(&denied_read_paths, &denied_read_globs, path_messages) { diff --git a/codex-rs/prompts/src/permissions_instructions/writable_roots.rs b/codex-rs/prompts/src/permissions_instructions/writable_roots.rs index 0da8e47e30..3aabc61025 100644 --- a/codex-rs/prompts/src/permissions_instructions/writable_roots.rs +++ b/codex-rs/prompts/src/permissions_instructions/writable_roots.rs @@ -1,5 +1,6 @@ //! Renders bounded catalog wording around an already bounded list of writable roots. -//! Validate template text before inserting paths once; unusable overrides retain legacy bytes. +//! Empty overrides omit the sentence; unusable nonempty overrides retain legacy bytes. +//! Validate template text before inserting paths once. use super::MAX_PERMISSION_PATH_BYTES; use super::PermissionsInstructions; @@ -24,6 +25,9 @@ pub(super) fn writable_roots_text( 1 => (messages.writable_root, WRITABLE_ROOT_TEMPLATE), _ => (messages.writable_roots, WRITABLE_ROOTS_TEMPLATE), }; + if selected.catalog_override() == Some("") { + return None; + } let roots_list = roots .iter() .map(|root| format!("`{root}`")) diff --git a/codex-rs/prompts/src/permissions_instructions/writable_roots_tests.rs b/codex-rs/prompts/src/permissions_instructions/writable_roots_tests.rs index de949a7e23..9dd478b177 100644 --- a/codex-rs/prompts/src/permissions_instructions/writable_roots_tests.rs +++ b/codex-rs/prompts/src/permissions_instructions/writable_roots_tests.rs @@ -1,3 +1,5 @@ +#![cfg(test)] + //! Checks bounded catalog wording without interpreting or truncating runtime paths. use super::*; @@ -8,7 +10,6 @@ use pretty_assertions::assert_eq; fn unusable_templates_fall_back_without_losing_roots() { let roots = vec!["/a".to_string(), "/b".to_string()]; for template in [ - "", " ", "No placeholder", "{{roots}}", @@ -43,6 +44,37 @@ fn unusable_templates_fall_back_without_losing_roots() { } } +#[test] +fn empty_catalog_templates_suppress_root_sentences() { + let roots = vec!["/a".to_string(), "/b".to_string()]; + let messages = PermissionMessages { + writable_root: Some("".into()), + writable_roots: Some("".into()), + ..PermissionMessages::default() + }; + let resolved = ResolvedPermissionMessages::new(Some(&messages)); + + assert_eq!(writable_roots_text(&roots[..1], resolved), None); + assert_eq!(writable_roots_text(&roots, resolved), None); +} + +#[test] +fn missing_catalog_templates_preserve_bundled_root_sentences() { + let roots = vec!["/a".to_string(), "/b".to_string()]; + let messages = PermissionMessages::default(); + for catalog in [None, Some(&messages)] { + let resolved = ResolvedPermissionMessages::new(catalog); + assert_eq!( + writable_roots_text(&roots[..1], resolved), + Some(" The writable root is `/a`.".into()), + ); + assert_eq!( + writable_roots_text(&roots, resolved), + Some(" The writable roots are `/a`, `/b`.".into()), + ); + } +} + #[test] fn substitution_preserves_whitespace_and_path_contents() { assert_eq!( diff --git a/codex-rs/prompts/src/permissions_instructions_tests.rs b/codex-rs/prompts/src/permissions_instructions_tests.rs index 6d6aa18c1e..e1d78cdd66 100644 --- a/codex-rs/prompts/src/permissions_instructions_tests.rs +++ b/codex-rs/prompts/src/permissions_instructions_tests.rs @@ -991,6 +991,56 @@ fn catalog_writable_roots_select_displayed_count_after_truncation() { ); } +#[test] +fn suppressed_writable_roots_leave_the_path_budget_for_denied_reads() { + let messages = PermissionMessages { + writable_roots: Some("".into()), + ..PermissionMessages::default() + }; + let roots = ["r".repeat(16_000), "s".repeat(16_000)]; + let denied = [format!("/private/{}", "d".repeat(1_000))]; + let globs = ["/secret/**".to_string()]; + let instructions = PermissionsInstructions::from_resolved( + PermissionsRenderContext { + writable_roots: &roots, + denied_read_paths: &denied, + denied_read_globs: &globs, + ..WORKSPACE_CONTEXT + }, + ApprovalPromptContext { + permission_messages: ResolvedPermissionMessages::new(Some(&messages)), + ..user_approval_context() + }, + ); + assert!(instructions.text.contains(&denied[0])); + assert!(instructions.text.contains(&globs[0])); + assert!(!instructions.text.contains("writable root")); + assert!(!instructions.text.contains(OMITTED_PERMISSION_PATHS)); +} + +#[test] +fn suppressed_oversized_root_does_not_report_omitted_paths() { + let messages = PermissionMessages { + writable_root: Some("".into()), + ..Default::default() + }; + let roots = ["x".repeat(33_000)]; + let denied = ["/private".to_string()]; + let instructions = PermissionsInstructions::from_resolved( + PermissionsRenderContext { + writable_roots: &roots, + denied_read_paths: &denied, + ..WORKSPACE_CONTEXT + }, + ApprovalPromptContext { + permission_messages: ResolvedPermissionMessages::new(Some(&messages)), + ..user_approval_context() + }, + ); + assert!(instructions.text.contains(&denied[0])); + assert!(!instructions.text.contains(OMITTED_PERMISSION_PATHS)); +} + #[test] fn catalog_path_warnings_preserve_facts_selection_and_default_bytes() { let messages = PermissionMessages { diff --git a/codex-rs/protocol/src/openai_models.rs b/codex-rs/protocol/src/openai_models.rs index 5a4a98f4c9..d61d293509 100644 --- a/codex-rs/protocol/src/openai_models.rs +++ b/codex-rs/protocol/src/openai_models.rs @@ -909,11 +909,13 @@ pub struct PermissionMessages { #[serde(default, skip_serializing_if = "Option::is_none")] pub approved_command_prefix_saved: Option, /// Single writable-root sentence with exactly one `{{ roots }}` placeholder. - /// Missing, null, empty, invalid, or oversized templates use the bundled sentence. + /// An empty string suppresses the sentence. Missing, null, invalid, or oversized + /// templates use the bundled sentence. #[serde(default, skip_serializing_if = "Option::is_none")] pub writable_root: Option, /// Multiple writable-roots sentence with exactly one `{{ roots }}` placeholder. - /// Missing, null, empty, invalid, or oversized templates use the bundled sentence. + /// An empty string suppresses the sentence. Missing, null, invalid, or oversized + /// templates use the bundled sentence. #[serde(default, skip_serializing_if = "Option::is_none")] pub writable_roots: Option, /// Optional presentation before the harness-owned omission and no-bypass warning.