mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] preserve explicit environment cwd (#27995)
## Why `TurnEnvironmentSelections::new` rewrote the primary environment's explicit `cwd` to the legacy fallback cwd. For a remote-first selection, this could replace the remote working directory with a local fallback path and made the legacy cwd overlay authoritative over environment-owned state. ## What changed - Preserve every explicit environment cwd when constructing turn environment selections. - Keep `cwd`-only app-server updates compatible by rebuilding the default environment selections at the requested cwd. - Cover both explicit primary cwd preservation and cwd-only updates reaching the model-visible execution environment. ## Testing - `just test -p codex-core session_update_settings_does_not_rewrite_sticky_environment_cwds` - `just test -p codex-core environment_settings_preserve_explicit_primary_cwd` - `just test -p codex-app-server thread_settings_update_cwd_retargets_default_environment`
This commit is contained in:
@@ -106,7 +106,6 @@ pub const COLLABORATION_MODE_CLOSE_TAG: &str = "</collaboration_mode>";
|
||||
pub const REALTIME_CONVERSATION_OPEN_TAG: &str = "<realtime_conversation>";
|
||||
pub const REALTIME_CONVERSATION_CLOSE_TAG: &str = "</realtime_conversation>";
|
||||
pub const USER_MESSAGE_BEGIN: &str = "## My request for Codex:";
|
||||
const LOCAL_ENVIRONMENT_ID: &str = "local";
|
||||
|
||||
// TODO(anp): Replace `TurnEnvironmentSelection` with `PathUri` once path URIs carry environment
|
||||
// identifiers.
|
||||
@@ -127,22 +126,9 @@ impl TurnEnvironmentSelections {
|
||||
legacy_fallback_cwd: AbsolutePathBuf,
|
||||
environments: Vec<TurnEnvironmentSelection>,
|
||||
) -> Self {
|
||||
let mut settings = Self {
|
||||
Self {
|
||||
legacy_fallback_cwd,
|
||||
environments,
|
||||
};
|
||||
settings.sync_primary_environment_cwd();
|
||||
settings
|
||||
}
|
||||
|
||||
fn sync_primary_environment_cwd(&mut self) {
|
||||
let legacy_fallback_cwd = PathUri::from_abs_path(&self.legacy_fallback_cwd);
|
||||
// Keep remote environments' native cwd instead of replacing it with the local fallback.
|
||||
if let Some(turn_environment) = self.environments.first_mut()
|
||||
&& turn_environment.environment_id == LOCAL_ENVIRONMENT_ID
|
||||
&& turn_environment.cwd != legacy_fallback_cwd
|
||||
{
|
||||
turn_environment.cwd = legacy_fallback_cwd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user