mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
Scope runtime workspace roots to execution environments (#32952)
## Why Multi-environment turns can run against different filesystems, so a single thread-wide workspace-root list cannot accurately describe every selected environment. ## What changed - Add optional `runtimeWorkspaceRoots` to each app-server environment selection. Omitted roots default to that environment's `cwd`, while an empty list selects no roots. - Carry environment-native roots through turn selection, model-visible context, permission materialization, and tool sandboxing. - Keep the top-level `runtimeWorkspaceRoots` field as a compatibility input when constructing default environment selections; explicit selections use their own roots. ## Testing - Cover thread and turn API defaults, overrides, empty roots, and schema round-tripping. - Verify foreign roots remain model-visible and remote execution applies the target environment's roots before sandbox selection. GitOrigin-RevId: c6e7a62883c45c676c153055f46a55ee15a323a4
This commit is contained in:
@@ -4,7 +4,7 @@ use codex_protocol::permissions::FileSystemAccessMode;
|
||||
use codex_protocol::permissions::FileSystemPath;
|
||||
use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -33,14 +33,18 @@ enum ManagedFileSystemContext {
|
||||
impl FileSystemContext {
|
||||
pub(super) fn from_permission_profile(
|
||||
permission_profile: &PermissionProfile,
|
||||
workspace_roots: &[AbsolutePathBuf],
|
||||
workspace_roots: &[PathUri],
|
||||
) -> Self {
|
||||
let materialized_workspace_roots = workspace_roots
|
||||
.iter()
|
||||
.filter_map(|workspace_root| workspace_root.to_abs_path().ok())
|
||||
.collect::<Vec<_>>();
|
||||
let permission_profile = permission_profile
|
||||
.clone()
|
||||
.materialize_project_roots_with_workspace_roots(workspace_roots);
|
||||
.materialize_project_roots_with_workspace_roots(&materialized_workspace_roots);
|
||||
let workspace_roots = workspace_roots
|
||||
.iter()
|
||||
.map(|root| root.to_string_lossy().into_owned())
|
||||
.map(PathUri::inferred_native_path_string)
|
||||
.collect();
|
||||
let permission_profile = match permission_profile {
|
||||
PermissionProfile::Managed { file_system, .. } => {
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::context::environment_context::NetworkContext;
|
||||
use crate::context::environment_context::push_xml_escaped_text;
|
||||
use crate::environment_selection::TurnEnvironmentSnapshot;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
use crate::session::turn_context::TurnEnvironment;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -27,14 +28,18 @@ impl EnvironmentsState {
|
||||
turn_context: &TurnContext,
|
||||
environments: &TurnEnvironmentSnapshot,
|
||||
) -> Self {
|
||||
let workspace_roots = environments
|
||||
.primary()
|
||||
.map(TurnEnvironment::workspace_roots)
|
||||
.unwrap_or_default();
|
||||
Self {
|
||||
environments: environment_states(environments),
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
network: network_from_turn_context(turn_context),
|
||||
filesystem: Some(FileSystemContext::from_permission_profile(
|
||||
&turn_context.permission_profile,
|
||||
&turn_context.config.effective_workspace_roots(),
|
||||
turn_context.config.permissions.permission_profile(),
|
||||
workspace_roots,
|
||||
)),
|
||||
subagents: None,
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ fn serialize_workspace_write_environment_context() {
|
||||
|
||||
#[test]
|
||||
fn serialize_environment_context_with_foreign_windows_cwd() {
|
||||
let context = environment_state(
|
||||
let mut context = environment_state(
|
||||
[environment(
|
||||
"remote",
|
||||
PathUri::parse("file:///C:/windows").expect("Windows cwd URI"),
|
||||
@@ -97,12 +97,17 @@ fn serialize_environment_context_with_foreign_windows_cwd() {
|
||||
/*network*/ None,
|
||||
/*subagents*/ None,
|
||||
);
|
||||
context.filesystem = Some(FileSystemContext::from_permission_profile(
|
||||
&PermissionProfile::Disabled,
|
||||
&[PathUri::parse("file:///D:/workspace").expect("Windows workspace root URI")],
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
context.render(),
|
||||
r#"<environment_context>
|
||||
<cwd>C:\windows</cwd>
|
||||
<shell>powershell</shell>
|
||||
<filesystem><workspace_roots><root>D:\workspace</root></workspace_roots><permission_profile type="disabled"><file_system type="unrestricted" /></permission_profile></filesystem>
|
||||
</environment_context>"#
|
||||
);
|
||||
}
|
||||
@@ -189,7 +194,10 @@ fn serialize_environment_context_with_full_filesystem_profile() {
|
||||
);
|
||||
context.filesystem = Some(FileSystemContext::from_permission_profile(
|
||||
&workspace_write_permission_profile_with_private_denials(),
|
||||
&[repo.clone(), other_repo.clone()],
|
||||
&[
|
||||
PathUri::from_abs_path(&repo),
|
||||
PathUri::from_abs_path(&other_repo),
|
||||
],
|
||||
));
|
||||
|
||||
let expected = format!(
|
||||
|
||||
Reference in New Issue
Block a user