Preserve executor path URIs in permission profile workspace roots (#45863)

## Why

Executor profile roots can use path conventions that are not native to the current host. Converting them to host paths during configuration or turn reconstruction can reject or drop those roots, while case-insensitive comparison can hide Windows path spelling changes.

## What changed

- Store profile roots as URI-backed `ProfileWorkspaceRoot` values throughout permission snapshots and thread settings, preserving spelling in equality and deduplication.
- Keep effective workspace roots as `PathUri` values for permission materialization and status summaries. Convert Windows sandbox root hints to native paths only at native Windows sandbox boundaries, rejecting incompatible roots.
- Omit the legacy rollout `workspace_roots` field when profile roots cannot be represented as host paths, retaining the compiled permission profile.

## Testing

Add regression coverage for Windows and UNC root spelling changes, settings restoration and turn recording with foreign roots, executor-root status display, and backend-specific Windows root conversion.

GitOrigin-RevId: 903c068fd74959bdd10e7cb1141aa42b953a59a4
This commit is contained in:
Sean Huang authored and copyberry committed 2026-09-16 04:23:46 +00:00
1 parent 04581f9604
commit 83dc7d11e8
27 files changed
+408 -105

No files matched your search

+1 -3
View File
@@ -1023,9 +1023,7 @@ impl App {
runtime_permission_profile_override.map(|profile| {
profile
.clone()
.materialize_project_roots_with_workspace_roots(
&config.effective_workspace_roots(),
)
.materialize_project_roots_with_path_uris(&config.effective_workspace_roots())
});
if runtime_permission_profile_override
.as_ref()
@@ -1203,11 +1203,7 @@ fn permissions_display(config: &Config) -> String {
let summary = summarize_permission_profile(
&permission_profile,
&PathUri::from_abs_path(&config.cwd),
&config
.effective_workspace_roots()
.iter()
.map(PathUri::from_abs_path)
.collect::<Vec<_>>(),
&config.effective_workspace_roots(),
);
if let Some(details) = summary.strip_prefix("read-only")
&& !details.contains("(network access enabled)")
+1 -5
View File
@@ -298,11 +298,7 @@ impl StatusHistoryCell {
) -> Self {
let approval_policy = AskForApproval::from(config.permissions.approval_policy.value());
let permission_profile = config.permissions.effective_permission_profile();
let workspace_roots = config
.effective_workspace_roots()
.iter()
.map(PathUri::from_abs_path)
.collect::<Vec<_>>();
let workspace_roots = config.effective_workspace_roots();
let cwd = PathUri::from_abs_path(&config.cwd);
let model_provider = model_provider_id
.filter(|id| !id.trim().is_empty())
+40 -2
View File
@@ -52,6 +52,7 @@ use codex_protocol::permissions::FileSystemSandboxEntry;
use codex_protocol::permissions::FileSystemSpecialPath;
use codex_protocol::permissions::NetworkSandboxPolicy;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use insta::assert_snapshot;
use pretty_assertions::assert_eq;
use ratatui::prelude::*;
@@ -244,6 +245,10 @@ fn reset_at_from(captured_at: &chrono::DateTime<chrono::Local>, seconds: i64) ->
}
fn permissions_text_for(config: &Config) -> Option<String> {
permissions_text_for_width(config, /*width*/ 80)
}
fn permissions_text_for_width(config: &Config, width: u16) -> Option<String> {
let usage = TokenUsage::default();
let captured_at = chrono::Local
.with_ymd_and_hms(2024, 1, 2, 3, 4, 5)
@@ -265,7 +270,7 @@ fn permissions_text_for(config: &Config) -> Option<String> {
/*collaboration_mode*/ None,
/*reasoning_effort_override*/ None,
);
render_lines(&composite.display_lines(/*width*/ 80))
render_lines(&composite.display_lines(width))
.iter()
.find(|line| line.contains("Permissions:"))
.and_then(|line| {
@@ -626,7 +631,7 @@ async fn status_permissions_workspace_roots_include_profile_defined_directories(
/*exclude_slash_tmp*/ false,
),
ActivePermissionProfile::new(":workspace"),
vec![profile_root.clone()],
vec![profile_root.clone().into()],
),
)
.expect("set permission profile");
@@ -2225,3 +2230,36 @@ async fn status_context_window_uses_last_usage() {
"context line should not use total aggregated tokens, got: {context_line}"
);
}
#[tokio::test]
async fn status_permissions_include_executor_profile_root() {
let temp_home = TempDir::new().expect("temp home");
let mut config = test_config(&temp_home).await;
set_workspace_cwd(&mut config, test_path_buf("/workspace/repo").abs());
config
.permissions
.approval_policy
.set(AskForApproval::OnRequest.to_core())
.expect("set approval policy");
let root = PathUri::parse("file://server/share/foreign").expect("executor URI");
config
.permissions
.set_permission_profile_from_session_snapshot(
PermissionProfileSnapshot::active_with_profile_workspace_roots(
PermissionProfile::workspace_write_with_path_uris(
std::slice::from_ref(&root),
NetworkSandboxPolicy::Restricted,
/*exclude_tmpdir_env_var*/ true,
/*exclude_slash_tmp*/ true,
),
ActivePermissionProfile::new("executor"),
vec![root.into()],
),
)
.expect("set permission snapshot");
assert_snapshot!(
permissions_text_for_width(&config, /*width*/ 160).expect("permissions line"),
@r"Profile executor (workspace [\\server\share\foreign], Ask for approval)"
);
}