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
This commit is contained in:
goodman-oai
2026-12-01 00:29:20 +00:00
committed by copyberry
parent 404eb8b39a
commit 83545f3514
8 changed files with 397 additions and 49 deletions
+116 -23
View File
@@ -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</permissions instructions>"
);
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::<Vec<_>>()
.join("\n");
let expected = format!("{expected_body}\n</permissions instructions>");
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::<PermissionMessages>(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::<Vec<_>>();
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</permissions instructions>"
)));
} 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",
"</permissions instructions>",
)));
}
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#"<entry access="write">"#).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("<filesystem>").count(), 1);
assert_eq!(
permissions_annotations(request),
vec![
+5
View File
@@ -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,
@@ -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: "<PROMPT_CACHE_KEY 1>"
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:
<permissions instructions>
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: &&, ||
<OMITTED 48 LINES; ~819 TOKENS; hash=25364fc2ae19f565>
- ["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: <BOUNDED_ROOT_LIST>.
</permissions instructions>
03:message/user:
<environment_context>
<cwd><CWD></cwd>
<shell><HOST_SHELL></shell>
<current_date><CURRENT_DATE></current_date>
<timezone><HOST_TIMEZONE></timezone>
<filesystem><LARGE_PERMISSION_PATH_FIXTURE/></filesystem>
</environment_context>
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:
<permissions instructions>
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: &&, ||
<OMITTED 48 LINES; ~819 TOKENS; hash=25364fc2ae19f565>
- ["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: <BOUNDED_ROOT_LIST>.
</permissions instructions>
03:message/user:
<environment_context>
<cwd><CWD></cwd>
<shell><HOST_SHELL></shell>
<current_date><CURRENT_DATE></current_date>
<timezone><HOST_TIMEZONE></timezone>
<filesystem><LARGE_PERMISSION_PATH_FIXTURE/></filesystem>
</environment_context>
04:message/user:
Inspect the writable workspace.
05:message/developer:
<model_instructions>
The current model is catalog-writable-roots-b.
</model_instructions>
06:message/developer:
<permissions instructions>
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: &&, ||
<OMITTED 47 LINES; ~812 TOKENS; hash=035ff6687b0303fa>
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]
</permissions instructions>
07:message/user:
Continue with the selected model.
-- request 3 (request) --
08:message/user:
Continue without changing permissions.