From 3cd93c00ac16ffabf98dfcb73799a18878863155 Mon Sep 17 00:00:00 2001 From: jif-oai Date: Thu, 12 Feb 2026 11:40:48 +0000 Subject: [PATCH] Fix flaky pre_sampling_compact switch test (#11573) Summary - address the nondeterministic behavior observed in `pre_sampling_compact_runs_on_switch_to_smaller_context_model` so it no longer fails intermittently during model switches - ensure the surrounding sampling logic consistently handles the smaller-context case that the test exercises Testing - Not run (not requested) --- codex-rs/core/src/tasks/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/codex-rs/core/src/tasks/mod.rs b/codex-rs/core/src/tasks/mod.rs index 3d4528da2..cf2462b83 100644 --- a/codex-rs/core/src/tasks/mod.rs +++ b/codex-rs/core/src/tasks/mod.rs @@ -149,18 +149,16 @@ impl Session { task_cancellation_token.child_token(), ) .await; - session_ctx.clone_session().flush_rollout().await; + let sess = session_ctx.clone_session(); + sess.flush_rollout().await; + // Update previous model before TurnComplete is emitted so + // immediately following turns observe the correct switch state. + sess.set_previous_model(Some(model_slug)).await; if !task_cancellation_token.is_cancelled() { // Emit completion uniformly from spawn site so all tasks share the same lifecycle. - let sess = session_ctx.clone_session(); sess.on_task_finished(Arc::clone(&ctx_for_finish), last_agent_message) .await; } - // Set previous model regardless of completion or interruption for model-switch handling. - session_ctx - .clone_session() - .set_previous_model(Some(model_slug)) - .await; done_clone.notify_waiters(); } .instrument(session_span),