From 35bbc6851b67d3bfa154f076a72f787daca9fd06 Mon Sep 17 00:00:00 2001 From: Dave Tist <109555139+davetist@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:06:38 +0200 Subject: [PATCH] fix(gateway): honor previewed replies in queued follow-ups --- gateway/run.py | 4 +++- .../gateway/test_duplicate_reply_suppression.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index 8447dd0f..5682d003 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -9396,8 +9396,10 @@ class GatewayRunner: pass except Exception as e: logger.debug("Stream consumer wait before queued message failed: %s", e) + _previewed = bool(result.get("response_previewed")) _already_streamed = bool( - _sc and getattr(_sc, "final_response_sent", False) + (_sc and getattr(_sc, "final_response_sent", False)) + or _previewed ) first_response = result.get("final_response", "") if first_response and not _already_streamed: diff --git a/tests/gateway/test_duplicate_reply_suppression.py b/tests/gateway/test_duplicate_reply_suppression.py index f454d75e..3c2c7b32 100644 --- a/tests/gateway/test_duplicate_reply_suppression.py +++ b/tests/gateway/test_duplicate_reply_suppression.py @@ -324,9 +324,24 @@ class TestQueuedMessageAlreadyStreamed: def test_queued_path_detects_confirmed_final_stream_delivery(self): """Confirmed final streamed delivery should skip the resend.""" _sc = self._make_mock_sc(already_sent=True, final_response_sent=True) + response = {"response_previewed": False} _already_streamed = bool( - _sc and getattr(_sc, "final_response_sent", False) + (_sc and getattr(_sc, "final_response_sent", False)) + or bool(response.get("response_previewed")) + ) + + assert _already_streamed is True + + def test_queued_path_detects_previewed_response_delivery(self): + """A response already previewed via the adapter should not be resent + before processing the queued follow-up.""" + _sc = self._make_mock_sc(already_sent=False, final_response_sent=False) + response = {"response_previewed": True} + + _already_streamed = bool( + (_sc and getattr(_sc, "final_response_sent", False)) + or bool(response.get("response_previewed")) ) assert _already_streamed is True