diff --git a/strix/config/models.py b/strix/config/models.py index b84e2aa2..cb24c2db 100644 --- a/strix/config/models.py +++ b/strix/config/models.py @@ -446,10 +446,12 @@ async def _with_timeouts( first = True while True: limits: list[tuple[float, float, str]] = [] - gap = first_event if first else idle + # Without a first-event bound, the idle bound covers the first event too. + on_first = first and bool(first_event) + gap = first_event if on_first else idle if gap: limits.append( - (gap, gap, "stream_first_event_timeout" if first else "stream_idle_timeout") + (gap, gap, "stream_first_event_timeout" if on_first else "stream_idle_timeout") ) if total: limits.append((max(0.0, deadline - time.monotonic()), total, "stream_total_timeout")) diff --git a/tests/test_stream_idle_timeout.py b/tests/test_stream_idle_timeout.py index 8ee47cba..2f247d08 100644 --- a/tests/test_stream_idle_timeout.py +++ b/tests/test_stream_idle_timeout.py @@ -161,6 +161,8 @@ async def test_first_event_and_whole_stream_are_bounded() -> None: with pytest.raises(TimeoutError, match="stream_first_event_timeout"): [event async for event in _with_timeouts(_slow_start(), idle=5, first_event=0.2)] + with pytest.raises(TimeoutError, match="stream_idle_timeout"): + [event async for event in _with_timeouts(_slow_start(), idle=0.2)] with pytest.raises(TimeoutError, match="stream_total_timeout"): [event async for event in _with_timeouts(_endless(), idle=5, total=0.3)]