From a7c1a8cdd0cd60fb208b0dde66ef5cd6fcaba417 Mon Sep 17 00:00:00 2001 From: Brian Yu Date: Sat, 7 Feb 2026 10:58:02 -0800 Subject: [PATCH] =?UTF-8?q?Reset=20websocket=20turn=20state=20on=20recon?= =?UTF-8?q?=E2=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codex-rs/core/src/client.rs | 11 +++++++++++ codex-rs/core/tests/suite/turn_state.rs | 11 ++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index d9e938befc..e872cf361a 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -522,6 +522,17 @@ impl ModelClient { fn set_shared_v2_connection(&self, connection: Option>) { self.with_shared_v2_state(|state| { + let connection_changed = match (&state.connection, &connection) { + (Some(existing), Some(new_connection)) => !Arc::ptr_eq(existing, new_connection), + (None, Some(_)) | (Some(_), None) => true, + (None, None) => false, + }; + if connection_changed { + // Response chaining state is scoped to a single backend websocket connection. + // When the connection changes, start the next request as a full create. + state.websocket_last_items.clear(); + state.websocket_last_response_id = None; + } state.connection = connection; }); } diff --git a/codex-rs/core/tests/suite/turn_state.rs b/codex-rs/core/tests/suite/turn_state.rs index df939f01cc..05d6730cc1 100644 --- a/codex-rs/core/tests/suite/turn_state.rs +++ b/codex-rs/core/tests/suite/turn_state.rs @@ -221,9 +221,14 @@ async fn websocket_v2_reconnect_after_turn_boundary_does_not_replay_turn_state() .first() .expect("second websocket connection should have a request") .body_json(); - assert_eq!( - second_request["previous_response_id"].as_str(), - Some("resp-1") + assert_eq!(second_request.get("previous_response_id"), None); + let second_input_len = second_request["input"] + .as_array() + .map(Vec::len) + .unwrap_or(0); + assert!( + second_input_len > 1, + "reconnect should send full input items, got {second_input_len}" ); server.shutdown().await;