diff --git a/gateway/run.py b/gateway/run.py index 8447dd0f51..5682d00346 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 f454d75eb0..3c2c7b32c8 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