fix(llm): bound the first stream event by the idle limit when no first-event limit is set

This commit is contained in:
Ian 2026-10-07 11:31:15 -04:00
parent 59e645eba5
commit 58d25f447d
2 changed files with 6 additions and 2 deletions

View file

@ -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"))

View file

@ -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)]