fix: cleanup models, better retry strat

This commit is contained in:
Alex committed 2026-07-23 10:22:10 +01:00
1 parent c3d605f07a
commit 32597df153
20 files changed
+849 -671

No files matched your search

+49
View File
@@ -446,6 +446,55 @@ def test_stream_cache_bypasses_when_tools_provided(mock_make_redis):
mock_redis_instance.get.assert_not_called()
@pytest.mark.unit
@patch("application.cache.get_redis_instance")
def test_stream_cache_skips_write_when_no_content_deltas(mock_make_redis):
"""A stream that emits only reasoning ("thought") dicts and a
finish chunk — i.e. reasoning-only-stop, the silent-loss bug's
signature — must NOT be cached. Otherwise the empty stream is
replayed for the TTL on every identical request, poisoning the
cache and denying the reasoning-only recovery any chance to hit
a fresh provider call.
"""
mock_redis_instance = MagicMock()
mock_make_redis.return_value = mock_redis_instance
mock_redis_instance.get.return_value = None
@stream_cache
def mock_function(self, model, messages, stream, tools):
yield {"type": "thought", "thought": "thinking hard"}
yield {"type": "thought", "thought": " and harder"}
yield {"type": "stop"}
messages = [{"role": "user", "content": "test"}]
result = list(mock_function(None, "model", messages, stream=True, tools=None))
assert len(result) == 3
mock_redis_instance.set.assert_not_called()
@pytest.mark.unit
@patch("application.cache.get_redis_instance")
def test_stream_cache_writes_when_any_content_chunk_seen(mock_make_redis):
"""The mirror case: a stream with even one str content delta is
cached normally (the poison guard is minimal — only reasoning-only
streams are dropped)."""
mock_redis_instance = MagicMock()
mock_make_redis.return_value = mock_redis_instance
mock_redis_instance.get.return_value = None
@stream_cache
def mock_function(self, model, messages, stream, tools):
yield {"type": "thought", "thought": "brief thought"}
yield "the answer"
messages = [{"role": "user", "content": "test"}]
result = list(mock_function(None, "model", messages, stream=True, tools=None))
assert result == [{"type": "thought", "thought": "brief thought"}, "the answer"]
mock_redis_instance.set.assert_called_once()
@pytest.mark.unit
@patch("application.cache.get_redis_instance")
def test_stream_cache_no_redis(mock_make_redis):