From 46020c32c5db403bbbb9ba5c3da262fcf2117402 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 19:43:36 -0700 Subject: [PATCH] refactor(agent/stream_diag): compact retry log call and drop-suffix computation --- agent/stream_diag.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/agent/stream_diag.py b/agent/stream_diag.py index c9f83c89df..5500ee4565 100644 --- a/agent/stream_diag.py +++ b/agent/stream_diag.py @@ -115,19 +115,12 @@ def log_stream_retry( _chain = type(error).__name__ logger.warning( - "Stream %s on attempt %s/%s — retrying. " - "subagent_id=%s depth=%s provider=%s base_url=%s " - "error_type=%s error=%s " - "chain=%s " - "http_status=%s bytes=%d chunks=%d elapsed=%.2fs ttfb=%s " - "upstream=[%s]", + "Stream %s on attempt %s/%s — retrying. subagent_id=%s depth=%s provider=%s base_url=%s " + "error_type=%s error=%s chain=%s http_status=%s bytes=%d chunks=%d elapsed=%.2fs ttfb=%s upstream=[%s]", kind, attempt, max_attempts, - getattr(agent, "_subagent_id", None) or "-", - getattr(agent, "_delegate_depth", 0), - agent.provider or "-", - agent.base_url or "-", - type(error).__name__, _summary, _chain, - *_diag_fields(diag), + getattr(agent, "_subagent_id", None) or "-", getattr(agent, "_delegate_depth", 0), + agent.provider or "-", agent.base_url or "-", + type(error).__name__, _summary, _chain, *_diag_fields(diag), extra={"mid_tool_call": mid_tool_call}, ) except Exception: @@ -146,13 +139,12 @@ def emit_stream_drop( ) provider = agent.provider or "provider" _suffix = "" - if isinstance(diag, dict): - try: - started = diag.get("started_at") - if started is not None: - _suffix = f" after {max(0.0, time.time() - float(started)):.1f}s" - except Exception: - pass + try: + started = diag.get("started_at") if isinstance(diag, dict) else None + if started is not None: + _suffix = f" after {max(0.0, time.time() - float(started)):.1f}s" + except Exception: + pass try: agent._buffer_status( f"⚠️ {provider} stream {kind} ({type(error).__name__}){_suffix} "