The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): count streamed reasoning details as progress
anhtahaylove99d037eeb997
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 645c78c2325..57db47a0f46 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -9463,6 +9463,7 @@ class _ChatStreamAccumulator:self._total_ceiling = total_ceilingself.content_parts: List[str] = []self.reasoning_parts: List[str] = []+ self.reasoning_details: List[Any] = []self.tool_calls_acc: Dict[int, Dict[str, Any]] = {}self.finish_reason = Noneself.usage = None@@ -9507,6 +9508,24 @@ class _ChatStreamAccumulator:if reasoning_piece and isinstance(reasoning_piece, str):self.reasoning_parts.append(reasoning_piece)made_progress = True+ # OpenRouter-compatible reasoning models may stream their entire+ # thinking phase through ``reasoning_details`` instead of+ # ``reasoning`` / ``reasoning_content``. Treat only details carrying+ # actual text as forward progress: structural/signed envelopes must+ # not keep an otherwise stalled compression alive indefinitely.+ reasoning_details = getattr(delta, "reasoning_details", None)+ if reasoning_details is None:+ model_extra = getattr(delta, "model_extra", None)+ if isinstance(model_extra, dict):+ reasoning_details = model_extra.get("reasoning_details")+ if isinstance(reasoning_details, list):+ for detail in reasoning_details:+ self.reasoning_details.append(detail)+ if isinstance(detail, dict) and any(+ isinstance(detail.get(field), str) and detail[field]+ for field in ("summary", "thinking", "content", "text")+ ):+ made_progress = Truefor tc in (getattr(delta, "tool_calls", None) or []):idx = getattr(tc, "index", 0) or 0acc = self.tool_calls_acc.setdefault(@@ -9548,6 +9567,7 @@ class _ChatStreamAccumulator:content="".join(self.content_parts),tool_calls=tool_calls,reasoning="".join(self.reasoning_parts) or None,+ reasoning_details=self.reasoning_details or None,)choice = SimpleNamespace(index=0,diff --git a/tests/agent/test_aux_progress_streaming.py b/tests/agent/test_aux_progress_streaming.pyindex 5f43768ffe3..fcc5f7d81da 100644--- a/tests/agent/test_aux_progress_streaming.py+++ b/tests/agent/test_aux_progress_streaming.py@@ -36,12 +36,14 @@ from agent.conversation_compression import CompressionCommitFence# Helpers# ----------------------------------------------------------------------------def _chunk(content=None, reasoning=None, finish_reason=None, usage=None,- tool_calls=None, model="m1", chunk_id="c1"):+def _chunk(content=None, reasoning=None, reasoning_details=None,+ finish_reason=None, usage=None, tool_calls=None, model="m1",+ chunk_id="c1"):delta = SimpleNamespace(content=content,reasoning=reasoning,reasoning_content=None,+ reasoning_details=reasoning_details,tool_calls=tool_calls,)choice = SimpleNamespace(delta=delta, finish_reason=finish_reason)@@ -347,6 +349,34 @@ class TestContentBearingProgress:assert ticks == [1]+ def test_openrouter_reasoning_details_keep_compression_alive(self):+ """Reasoning-only streams must refresh the compression idle fence."""+ ticks = []+ accumulator = _ChatStreamAccumulator()+ detail = {"type": "reasoning.summary", "summary": "working..."}++ with aux_progress_hook(lambda: ticks.append(1)):+ accumulator.feed(_chunk(reasoning_details=[detail]))++ result = accumulator.finish()+ assert ticks == [1]+ assert result.choices[0].message.reasoning_details == [detail]++ def test_structural_reasoning_details_are_not_progress(self):+ ticks = []+ accumulator = _ChatStreamAccumulator()++ with aux_progress_hook(lambda: ticks.append(1)):+ accumulator.feed(+ _chunk(+ reasoning_details=[+ {"type": "reasoning.encrypted", "signature": "sig"}+ ]+ )+ )++ assert ticks == []+def test_codex_adapter_updates_fence_only_for_substantive_events(self):events = [SimpleNamespace(type="response.created"),