mirror of
https://github.com/openai/codex.git
synced 2026-10-22 03:47:49 +00:00
Rename environment config for turn scope (#37862)
## What changed - Rename `EnvironmentConfig` to `TurnEnvironmentConfig` to make its scope explicit. - Rename the corresponding `SessionConfiguration` accessor and update all call sites. GitOrigin-RevId: f47d745566199e699bd8e7c671c313eaf3bba79e
This commit is contained in:
@@ -4,8 +4,8 @@ use crate::config::PermissionProfileSnapshot;
|
||||
use crate::context::ContextualUserFragment;
|
||||
use crate::environment_selection::TurnEnvironmentSnapshot;
|
||||
use crate::environment_selection::TurnEnvironmentState;
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::TurnEnvironment;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use codex_config::ConfigLayerEntry;
|
||||
use codex_config::ConfigLayerStack;
|
||||
use codex_config::ConfigRequirements;
|
||||
@@ -340,7 +340,7 @@ fn resolved_local_environments<const N: usize>(
|
||||
PathUri::from_abs_path(&cwd),
|
||||
Vec::new(),
|
||||
/*shell*/ None,
|
||||
EnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::legacy(
|
||||
PermissionProfile::read_only(),
|
||||
|
||||
@@ -22,9 +22,9 @@ use futures::future::BoxFuture;
|
||||
use futures::future::Shared;
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::ShellSnapshotTask;
|
||||
use crate::session::turn_context::TurnEnvironment;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use crate::shell::Shell;
|
||||
use crate::shell_snapshot::ShellSnapshot;
|
||||
|
||||
@@ -60,7 +60,7 @@ struct ResolvedEnvironment {
|
||||
struct SelectedTurnEnvironment {
|
||||
selection: TurnEnvironmentSelection,
|
||||
// Temporary: copied from thread settings until environments supply their own config.
|
||||
config: EnvironmentConfig,
|
||||
config: TurnEnvironmentConfig,
|
||||
environment: Arc<Environment>,
|
||||
// Selection clones share one listener; the final handle drop aborts it.
|
||||
connection_events_task: Option<Arc<AbortOnDropHandle<()>>>,
|
||||
@@ -70,7 +70,7 @@ struct SelectedTurnEnvironment {
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct StartingTurnEnvironment {
|
||||
pub(crate) selection: TurnEnvironmentSelection,
|
||||
config: EnvironmentConfig,
|
||||
config: TurnEnvironmentConfig,
|
||||
resolution: TurnEnvironmentResolution,
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ impl ThreadEnvironments {
|
||||
pub(crate) fn new(
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
local_shell: Shell,
|
||||
thread_environment_config: EnvironmentConfig,
|
||||
thread_environment_config: TurnEnvironmentConfig,
|
||||
shell_snapshot: ShellSnapshot,
|
||||
current: TurnEnvironmentSnapshot,
|
||||
non_blocking_snapshots: bool,
|
||||
@@ -149,7 +149,7 @@ impl ThreadEnvironments {
|
||||
pub(crate) fn update_selections(
|
||||
&self,
|
||||
environments: &[TurnEnvironmentSelection],
|
||||
thread_environment_config: &EnvironmentConfig,
|
||||
thread_environment_config: &TurnEnvironmentConfig,
|
||||
) {
|
||||
let previous = self.environments.load();
|
||||
let mut seen_environment_ids = HashSet::with_capacity(environments.len());
|
||||
@@ -227,7 +227,7 @@ impl ThreadEnvironments {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn update_environment_configs(&self, config: &EnvironmentConfig) {
|
||||
pub(crate) fn update_environment_configs(&self, config: &TurnEnvironmentConfig) {
|
||||
let environments = self
|
||||
.environments
|
||||
.load()
|
||||
@@ -554,8 +554,8 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
fn test_environment_config() -> EnvironmentConfig {
|
||||
EnvironmentConfig {
|
||||
fn test_environment_config() -> TurnEnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::read_only()),
|
||||
}
|
||||
@@ -718,7 +718,7 @@ url = "ws://127.0.0.1:8765"
|
||||
shell_type: crate::shell::ShellType::Zsh,
|
||||
shell_path: std::path::PathBuf::from("/configured/zsh"),
|
||||
};
|
||||
let expected_config = EnvironmentConfig {
|
||||
let expected_config = TurnEnvironmentConfig {
|
||||
allow_login_shell: false,
|
||||
permission_profile: PermissionProfileSnapshot::active_with_profile_workspace_roots(
|
||||
PermissionProfile::read_only(),
|
||||
@@ -910,7 +910,7 @@ url = "ws://127.0.0.1:8765"
|
||||
.await,
|
||||
);
|
||||
let cwd = AbsolutePathBuf::current_dir().expect("cwd");
|
||||
let expected_config = EnvironmentConfig {
|
||||
let expected_config = TurnEnvironmentConfig {
|
||||
allow_login_shell: false,
|
||||
permission_profile: PermissionProfileSnapshot::active_with_profile_workspace_roots(
|
||||
PermissionProfile::read_only(),
|
||||
@@ -1054,7 +1054,7 @@ url = "ws://127.0.0.1:8765"
|
||||
/*connect_timeout*/ None,
|
||||
)
|
||||
.expect("replacement environment");
|
||||
let next_config = EnvironmentConfig {
|
||||
let next_config = TurnEnvironmentConfig {
|
||||
allow_login_shell: false,
|
||||
..test_environment_config()
|
||||
};
|
||||
@@ -1204,7 +1204,7 @@ url = "ws://127.0.0.1:8765"
|
||||
/*connect_timeout*/ None,
|
||||
)
|
||||
.expect("replacement environment");
|
||||
let child_config = EnvironmentConfig {
|
||||
let child_config = TurnEnvironmentConfig {
|
||||
allow_login_shell: false,
|
||||
permission_profile: PermissionProfileSnapshot::active_with_profile_workspace_roots(
|
||||
PermissionProfile::read_only(),
|
||||
|
||||
@@ -6,8 +6,8 @@ use crate::session::step_context::StepContext;
|
||||
use crate::session::tests::make_session_and_context;
|
||||
use crate::session::tests::make_session_and_context_with_rx;
|
||||
use crate::session::tests::mcp_config_for_test;
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::TurnEnvironment;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use crate::state::ActiveTurn;
|
||||
use crate::test_support::models_manager_with_provider;
|
||||
use crate::tools::hook_names::HookToolName;
|
||||
@@ -1100,7 +1100,7 @@ async fn mcp_sandbox_cwd_uses_matching_server_environment_uri() -> anyhow::Resul
|
||||
secondary_cwd.clone(),
|
||||
Vec::new(),
|
||||
/*shell*/ None,
|
||||
EnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: turn_context
|
||||
.config
|
||||
|
||||
@@ -1596,12 +1596,12 @@ impl Session {
|
||||
let permission_profile_changed =
|
||||
previous_permission_profile != updated_permission_profile;
|
||||
let mcp_inputs_changed = state.session_configuration.mcp_inputs_differ(&updated);
|
||||
let environment_config = updated.environment_config();
|
||||
let environment_config = updated.turn_environment_config();
|
||||
if updates.environments.is_some() {
|
||||
self.services
|
||||
.turn_environments
|
||||
.update_selections(updated.environment_selections(), &environment_config);
|
||||
} else if state.session_configuration.environment_config() != environment_config {
|
||||
} else if state.session_configuration.turn_environment_config() != environment_config {
|
||||
self.services
|
||||
.turn_environments
|
||||
.update_environment_configs(&environment_config);
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::agents_md_manager::AgentsMdManager;
|
||||
use crate::config::ConstraintError;
|
||||
use crate::environment_selection::ThreadEnvironments;
|
||||
use crate::environment_selection::TurnEnvironmentSnapshot;
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use crate::shell_snapshot::ShellSnapshot;
|
||||
use crate::skills::SkillError;
|
||||
use crate::state::ActiveTurn;
|
||||
@@ -160,8 +160,8 @@ impl SessionConfiguration {
|
||||
&self.permission_profile_state
|
||||
}
|
||||
|
||||
pub(super) fn environment_config(&self) -> EnvironmentConfig {
|
||||
EnvironmentConfig {
|
||||
pub(super) fn turn_environment_config(&self) -> TurnEnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: self
|
||||
.original_config_do_not_use
|
||||
.permissions
|
||||
@@ -1060,14 +1060,14 @@ impl Session {
|
||||
environment_manager,
|
||||
default_shell.clone(),
|
||||
// Temporary: preserve thread-level behavior until environments supply config.
|
||||
session_configuration.environment_config(),
|
||||
session_configuration.turn_environment_config(),
|
||||
shell_snapshot,
|
||||
inherited_environments.unwrap_or_default(),
|
||||
config.features.enabled(Feature::DeferredExecutor),
|
||||
));
|
||||
turn_environments.update_selections(
|
||||
session_configuration.environment_selections(),
|
||||
&session_configuration.environment_config(),
|
||||
&session_configuration.turn_environment_config(),
|
||||
);
|
||||
let resolved_environments = turn_environments.snapshot().await;
|
||||
let agents_md_manager = Arc::new(AgentsMdManager::new(user_instructions));
|
||||
|
||||
@@ -4870,14 +4870,14 @@ async fn resolved_environments_for_configuration(
|
||||
let turn_environments = ThreadEnvironments::new(
|
||||
Arc::clone(&environment_manager),
|
||||
default_user_shell(),
|
||||
session_configuration.environment_config(),
|
||||
session_configuration.turn_environment_config(),
|
||||
ShellSnapshot::disabled(),
|
||||
TurnEnvironmentSnapshot::default(),
|
||||
/*non_blocking_snapshots*/ false,
|
||||
);
|
||||
turn_environments.update_selections(
|
||||
session_configuration.environment_selections(),
|
||||
&session_configuration.environment_config(),
|
||||
&session_configuration.turn_environment_config(),
|
||||
);
|
||||
(environment_manager, turn_environments.snapshot().await)
|
||||
}
|
||||
@@ -5737,7 +5737,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
let turn_environments = Arc::new(ThreadEnvironments::new(
|
||||
environment_manager,
|
||||
default_user_shell(),
|
||||
session_configuration.environment_config(),
|
||||
session_configuration.turn_environment_config(),
|
||||
ShellSnapshot::disabled(),
|
||||
resolved_environments,
|
||||
/*non_blocking_snapshots*/ false,
|
||||
@@ -7996,7 +7996,7 @@ where
|
||||
let turn_environments = Arc::new(ThreadEnvironments::new(
|
||||
environment_manager,
|
||||
default_user_shell(),
|
||||
session_configuration.environment_config(),
|
||||
session_configuration.turn_environment_config(),
|
||||
ShellSnapshot::disabled(),
|
||||
resolved_turn_environments.clone(),
|
||||
/*non_blocking_snapshots*/ false,
|
||||
|
||||
@@ -29,7 +29,7 @@ pub(crate) type ShellSnapshotTask = Shared<BoxFuture<'static, Option<Arc<ShellSn
|
||||
|
||||
/// Effective per-environment config; fields move here as executor config is migrated.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct EnvironmentConfig {
|
||||
pub(crate) struct TurnEnvironmentConfig {
|
||||
pub(crate) allow_login_shell: bool,
|
||||
pub(crate) permission_profile: PermissionProfileSnapshot,
|
||||
}
|
||||
@@ -41,7 +41,7 @@ pub(crate) struct TurnEnvironment {
|
||||
cwd: PathUri,
|
||||
workspace_roots: Vec<PathUri>,
|
||||
pub(crate) shell: Option<shell::Shell>,
|
||||
pub(crate) config: EnvironmentConfig,
|
||||
pub(crate) config: TurnEnvironmentConfig,
|
||||
pub(crate) shell_snapshot: ShellSnapshotTask,
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ impl TurnEnvironment {
|
||||
cwd: PathUri,
|
||||
workspace_roots: Vec<PathUri>,
|
||||
shell: Option<shell::Shell>,
|
||||
config: EnvironmentConfig,
|
||||
config: TurnEnvironmentConfig,
|
||||
) -> Self {
|
||||
Self {
|
||||
environment_id,
|
||||
@@ -650,12 +650,13 @@ impl Session {
|
||||
});
|
||||
let new_config = notify_config_contributors
|
||||
.then(|| Self::build_effective_session_config(&next));
|
||||
let environment_config = next.environment_config();
|
||||
let environment_config = next.turn_environment_config();
|
||||
if updates.environments.is_some() {
|
||||
self.services
|
||||
.turn_environments
|
||||
.update_selections(next.environment_selections(), &environment_config);
|
||||
} else if state.session_configuration.environment_config() != environment_config
|
||||
} else if state.session_configuration.turn_environment_config()
|
||||
!= environment_config
|
||||
{
|
||||
self.services
|
||||
.turn_environments
|
||||
|
||||
@@ -13,8 +13,8 @@ use crate::exec_env::inject_session_id_env;
|
||||
use crate::sandboxing::SandboxPermissions;
|
||||
use crate::session::step_context::StepContext;
|
||||
use crate::session::tests::make_session_and_context;
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::TurnEnvironment;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use crate::shell::Shell;
|
||||
use crate::shell::ShellType;
|
||||
use crate::tools::context::FunctionToolOutput;
|
||||
@@ -114,7 +114,7 @@ async fn shell_command_handler_to_exec_params_uses_selected_environment() {
|
||||
PathUri::from_abs_path(&selected_cwd),
|
||||
Vec::new(),
|
||||
Some(selected_shell),
|
||||
EnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::active(
|
||||
permission_profile,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use crate::config::PermissionProfileSnapshot;
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use crate::tools::sandboxing::SandboxAttempt;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::models::AdditionalPermissionProfile;
|
||||
@@ -23,7 +23,7 @@ fn test_turn_environment(environment_id: &str) -> crate::session::turn_context::
|
||||
PathUri::from_abs_path(&std::env::temp_dir().abs()),
|
||||
Vec::new(),
|
||||
/*shell*/ None,
|
||||
EnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::read_only()),
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use crate::config::PermissionProfileSnapshot;
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use crate::tools::approvals::ApprovalCacheKey;
|
||||
use codex_exec_server::Environment;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
@@ -20,7 +20,7 @@ async fn approval_key_uses_path_uri_and_includes_environment_id() {
|
||||
PathUri::from_abs_path(&cwd),
|
||||
Vec::new(),
|
||||
/*shell*/ None,
|
||||
EnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::legacy(
|
||||
PermissionProfile::read_only(),
|
||||
|
||||
@@ -483,7 +483,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::config::PermissionProfileSnapshot;
|
||||
use crate::exec::DEFAULT_EXEC_COMMAND_TIMEOUT_MS;
|
||||
use crate::session::turn_context::EnvironmentConfig;
|
||||
use crate::session::turn_context::TurnEnvironmentConfig;
|
||||
use crate::tools::sandboxing::ToolRuntime;
|
||||
use codex_exec_server::Environment;
|
||||
use codex_exec_server::LOCAL_ENVIRONMENT_ID;
|
||||
@@ -502,7 +502,7 @@ mod tests {
|
||||
cwd,
|
||||
Vec::new(),
|
||||
/*shell*/ None,
|
||||
EnvironmentConfig {
|
||||
TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::legacy(
|
||||
PermissionProfile::read_only(),
|
||||
|
||||
@@ -912,7 +912,7 @@ async fn zsh_fork_unified_exec_keeps_shell_parameter_when_remote_environment_ava
|
||||
remote_cwd,
|
||||
Vec::new(),
|
||||
/*shell*/ None,
|
||||
crate::session::turn_context::EnvironmentConfig {
|
||||
crate::session::turn_context::TurnEnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: turn
|
||||
.config
|
||||
|
||||
Reference in New Issue
Block a user