Keep active-turn environments stable across settings updates (#33658)

## Why

With deferred execution enabled, rebuilding a step context from the latest
thread environment snapshot could apply a settings update to a turn that was
already in progress.

## What changed

- Preserve each turn's captured environment selections when creating later
  step contexts.
- Refresh only the readiness of environments that were already starting, while
  retaining their original selection order.
- Apply updated environment selections to the next turn.

## Testing

Add coverage for changing the selected workspace while a turn is paused,
verifying that the active turn keeps its original working directory and the
next turn uses the new one.

GitOrigin-RevId: c6f4388c843384ef045b7abdbc303dcfca11d230
This commit is contained in:
sayan-oai authored and copyberry committed 2026-07-16 18:23:43 +00:00
1 parent b7983c2a07
commit c4ce0493dc
22 files changed
+463 -182

No files matched your search

+5 -2
View File
@@ -1,6 +1,7 @@
use super::head_tail_buffer::HeadTailBuffer;
use super::*;
use crate::codex_thread::BackgroundTerminalInfo;
use crate::environment_selection::TurnEnvironmentState;
use crate::exec::ExecCapturePolicy;
use crate::exec::ExecExpiration;
use crate::sandboxing::ExecRequest;
@@ -891,8 +892,10 @@ async fn remote_exec_server_rejects_inherited_fd_launches() -> anyhow::Result<()
let remote_test_env = remote_test_env().await?;
let (_, mut turn) = make_session_and_context().await;
turn.environments.turn_environments[0].environment =
Arc::new(remote_test_env.environment().clone());
let TurnEnvironmentState::Ready(environment) = &mut turn.environments.environments[0] else {
panic!("expected ready primary environment");
};
environment.environment = Arc::new(remote_test_env.environment().clone());
#[allow(deprecated)]
let cwd = turn.cwd.clone();