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

+22 -6
View File
@@ -894,13 +894,21 @@ async fn resume_and_fork_do_not_restore_thread_environments_from_rollout() {
.new_turn_with_sub_id("resume-turn".to_string(), SessionSettingsUpdate::default())
.await
.expect("build resumed turn context");
assert_eq!(resumed_turn.environments.turn_environments.len(), 1);
assert_eq!(resumed_turn.environments.turn_environments().count(), 1);
assert_eq!(
resumed_turn.environments.turn_environments[0].cwd(),
resumed_turn
.environments
.primary()
.expect("primary environment")
.cwd(),
&PathUri::from_abs_path(&default_cwd)
);
assert_ne!(
resumed_turn.environments.turn_environments[0].cwd(),
resumed_turn
.environments
.primary()
.expect("primary environment")
.cwd(),
&PathUri::from_abs_path(&selected_cwd)
);
@@ -920,13 +928,21 @@ async fn resume_and_fork_do_not_restore_thread_environments_from_rollout() {
.new_turn_with_sub_id("fork-turn".to_string(), SessionSettingsUpdate::default())
.await
.expect("build forked turn context");
assert_eq!(forked_turn.environments.turn_environments.len(), 1);
assert_eq!(forked_turn.environments.turn_environments().count(), 1);
assert_eq!(
forked_turn.environments.turn_environments[0].cwd(),
forked_turn
.environments
.primary()
.expect("primary environment")
.cwd(),
&PathUri::from_abs_path(&default_cwd)
);
assert_ne!(
forked_turn.environments.turn_environments[0].cwd(),
forked_turn
.environments
.primary()
.expect("primary environment")
.cwd(),
&PathUri::from_abs_path(&selected_cwd)
);
}