From 3914089d52fa32936b00e63d881a0a25ad462258 Mon Sep 17 00:00:00 2001 From: Radical Edward Date: Mon, 25 May 2026 01:49:41 +0200 Subject: [PATCH] fix(compression): 3-line fix for infinite compression loop (#29335) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three compounding root causes: A) run_conversation() result dict missing session_id — gateway's dead-code guard at gateway/run.py:8700 never triggers B) preflight compression bypasses should_compress() anti-thrashing — re-triggers every turn when tool schemas dominate token budget C) gateway updates session_entry.session_id in memory but doesn't persist via session_store._save() Fixes: #29335 --- agent/conversation_loop.py | 4 +++- gateway/run.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py index e34631377e4..1361d6ed6e6 100644 --- a/agent/conversation_loop.py +++ b/agent/conversation_loop.py @@ -484,7 +484,8 @@ def run_conversation( tools=agent.tools or None, ) - if _preflight_tokens >= agent.context_compressor.threshold_tokens: + if _preflight_tokens >= agent.context_compressor.threshold_tokens \ + and agent.context_compressor.should_compress(_preflight_tokens): logger.info( "Preflight compression: ~%s tokens >= %s threshold (model %s, ctx %s)", f"{_preflight_tokens:,}", @@ -4180,6 +4181,7 @@ def run_conversation( "estimated_cost_usd": agent.session_estimated_cost_usd, "cost_status": agent.session_cost_status, "cost_source": agent.session_cost_source, + "session_id": agent.session_id, } if agent._tool_guardrail_halt_decision is not None: result["guardrail"] = agent._tool_guardrail_halt_decision.to_metadata() diff --git a/gateway/run.py b/gateway/run.py index cb8b60e556d..675774022e3 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -8692,6 +8692,7 @@ class GatewayRunner: # session_entry so transcript writes below go to the right session. if agent_result.get("session_id") and agent_result["session_id"] != session_entry.session_id: session_entry.session_id = agent_result["session_id"] + self.session_store._save() # Prepend reasoning/thinking if display is enabled (per-platform) try: