The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): dispatch alone must not reset the summary idle fence (#114938)
Diamond Hands Digc2560f4dcc41
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 505f822cf9b..244e60830fa 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -6860,7 +6860,10 @@ def _create_with_progress_once(error is surfaced to the normal recovery chains instead."""_notify_aux_dispatch()- _notify_aux_progress() # Preserve the watchdog's historical dispatch tick.+ # Dispatch alone is not forward progress: a 401/retry/fallback dispatch must not+ # reset the compression inactivity fence, or a zero-output attempt runs to the+ # total ceiling instead of idling out (#114938). Progress ticks only for+ # substantive stream payloads or a completed usable response.if (not _aux_progress_active() and not force_stream) or _client_streams_internally(client):response = client.chat.completions.create(**kwargs)if not _client_streams_internally(client):@@ -7085,7 +7088,7 @@ async def _acreate_with_progress("""Async :func:`_create_with_progress`: stream + re-aggregate (ticking the hook per substantivechunk) when a progress hook is active or the provider is stream-only; plain create otherwise."""_notify_aux_dispatch()- _notify_aux_progress()+ # Same contract as the sync twin (#114938): dispatch alone is not progress.if (not _aux_progress_active() and not force_stream) or _async_client_streams_internally(client):response = await client.chat.completions.create(**kwargs)if not _async_client_streams_internally(client):diff --git a/tests/agent/test_aux_progress_streaming.py b/tests/agent/test_aux_progress_streaming.pyindex 93c58ef22ec..57667303018 100644--- a/tests/agent/test_aux_progress_streaming.py+++ b/tests/agent/test_aux_progress_streaming.py@@ -18,12 +18,16 @@ from agent.auxiliary_client import (_AnthropicCompletionsAdapter,_ChatStreamAccumulator,_CodexCompletionsAdapter,+ _acreate_with_progress,_acreate_with_stream,_aggregate_chat_stream,_aggregate_chat_stream_async,_anthropic_event_has_content,+ _aux_dispatch,_aux_stream_total_ceiling,+ _aux_thread_local_hook,_create_with_progress,+ _create_with_progress_once,_notify_aux_progress,_provider_requires_stream,aux_progress_hook,@@ -145,9 +149,9 @@ class TestCreateWithProgress:assert result.choices[0].message.reasoning == "thinking..."assert result.choices[0].finish_reason == "stop"assert result.usage.total_tokens == 7- # 1 dispatch tick (preserved for the watchdog's historical liveness- # signal — see _create_with_progress) + 1 per substantive chunk.- assert ticks == [1, 1, 1, 1]+ # 1 tick per substantive chunk (reasoning, "Hello ", "world"); the+ # dispatch itself is not progress (#114938).+ assert ticks == [1, 1, 1]def test_reasoning_only_in_model_extra_is_captured_and_counts_as_progress(self):# Non-SDK delta objects (proxies, relays) may carry reasoning only in ``model_extra``;@@ -178,11 +182,9 @@ class TestCreateWithProgress:assert calls[0]["stream"] is Trueassert result is _COMPLETE- # A completed response object carries the full summary payload, and- # the dispatch tick is the watchdog's historical liveness signal:- # both are one-shot terminal ticks, not per-frame keepalives, so- # neither can defeat an inactivity timeout.- assert ticks == [1, 1]+ # A completed response object carries the full summary payload: one+ # terminal tick, and no dispatch tick (#114938).+ assert ticks == [1]def test_streaming_rejected_falls_back_to_plain_call(self):client = _FakeClient(@@ -199,6 +201,28 @@ class TestCreateWithProgress:assert client.calls[0].get("stream") is Trueassert "stream" not in client.calls[1]+ def test_dispatch_only_auth_failure_does_not_tick_progress(self):+ """Bug pin (#114938): a dispatch that dies before any payload (401) must+ not reset the compression inactivity fence. Dispatch telemetry still+ fires, but progress_observed stays False."""+ fence = CompressionCommitFence()+ dispatches = []++ class _AuthError(Exception):+ status_code = 401++ client = _FakeClient(stream_error=_AuthError("unauthorized"))+ with (+ aux_progress_hook(fence.touch_progress),+ _aux_thread_local_hook(_aux_dispatch, lambda: dispatches.append(1)),+ pytest.raises(_AuthError),+ ):+ _create_with_progress_once(+ client, {"model": "m1", "messages": [], "timeout": 30},+ )+ assert dispatches == [1] # dispatch telemetry preserved+ assert fence.progress_observed is False+@@ -689,3 +713,31 @@ class TestAsyncStreamAggregation:)assert calls[0]["stream"] is Trueassert result.choices[0].message.content == "ok"+ @pytest.mark.asyncio+ async def test_async_dispatch_only_auth_failure_does_not_tick_progress(self):+ """Async twin of the #114938 pin: a 401 dispatch must not reset the+ compression inactivity fence."""+ fence = CompressionCommitFence()+ dispatches = []++ class _AuthError(Exception):+ status_code = 401++ class _AsyncClient:+ def __init__(self):+ completions = SimpleNamespace(create=self._create)+ self.chat = SimpleNamespace(completions=completions)++ async def _create(self, **kwargs):+ raise _AuthError("unauthorized")++ with (+ aux_progress_hook(fence.touch_progress),+ _aux_thread_local_hook(_aux_dispatch, lambda: dispatches.append(1)),+ pytest.raises(_AuthError),+ ):+ await _acreate_with_progress(+ _AsyncClient(), {"model": "m1", "messages": [], "timeout": 30},+ )+ assert dispatches == [1]+ assert fence.progress_observed is Falsediff --git a/tests/agent/test_aux_relay_progress_seam.py b/tests/agent/test_aux_relay_progress_seam.pyindex 90a7fe268b3..ae42a3dcb8e 100644--- a/tests/agent/test_aux_relay_progress_seam.py+++ b/tests/agent/test_aux_relay_progress_seam.py@@ -48,7 +48,7 @@ def test_relay_default_callback_streams_and_ticks_hook_sync_and_async():assert sync_client.wire == [True]assert resp.choices[0].message.content == "hello world"sync_ticks = len(ticks)- assert sync_ticks >= 2 # one per substantive chunk, on top of the dispatch tick+ assert sync_ticks >= 2 # one per substantive chunk; dispatch alone is not progress (#114938)async_client = _AsyncClient()resp = asyncio.run(aux._relay_async_completion(async_client, {"model": "m", "messages": []}))