From a7bc192fc5afd19b35119bba05fcafeaf3018d79 Mon Sep 17 00:00:00 2001 From: Chris Busillo Date: Sun, 3 May 2026 14:03:26 -0400 Subject: [PATCH] fix(core): scope Responses WebSocket reuse to turns Reset reusable Responses WebSocket state at the start of each turn and clear cached chain state when the socket closes before a terminal response. This keeps prewarm reuse within a turn while avoiding stale cross-turn sockets. --- code-rs/core/src/client.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code-rs/core/src/client.rs b/code-rs/core/src/client.rs index 61a024a0909b..90fd36f3a9c1 100644 --- a/code-rs/core/src/client.rs +++ b/code-rs/core/src/client.rs @@ -687,6 +687,7 @@ impl ModelClient { /// the provider config. Public callers always invoke `stream()` – the /// specialised helpers are private to avoid accidental misuse. pub async fn stream(&self, prompt: &Prompt) -> Result { + self.reset_responses_websocket_session().await; let env_log_tag = std::env::var("CODE_DEBUG_LOG_TAG").ok(); let log_tag = env_log_tag .as_deref() @@ -1262,6 +1263,8 @@ impl ModelClient { loop { let Some(next) = ws_stream.next().await else { session.connection = None; + session.last_request = None; + session.last_response_id = None; break; }; match next {