Reset websocket turn state on recon−

This commit is contained in:
Brian Yu
2026-02-07 10:58:02 -08:00
parent a27322b039
commit a7c1a8cdd0
2 changed files with 19 additions and 3 deletions

View File

@@ -522,6 +522,17 @@ impl ModelClient {
fn set_shared_v2_connection(&self, connection: Option<Arc<ApiWebSocketConnection>>) {
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;
});
}

View File

@@ -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;