From 9c1c1d8063c8cc06db0eb4d4beb2ba893dce6dc1 Mon Sep 17 00:00:00 2001 From: happy5318 Date: Sat, 1 Aug 2026 00:44:57 +0800 Subject: [PATCH 1/2] fix: stop false Compressing-context card for preflight compression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #6184 narrowed the agent-status-to-SSE bridge to real compression start notices, but the 'preflight compression:' pattern matches the Hermes agent's preflight check message ("Preflight compression: ~X tokens >= Y threshold"). This fires on every new session where the system prompt alone exceeds the threshold, showing a "Compressing context" card before any model output — a false positive. Remove 'preflight compression:' from the pattern. The preflight check is a one-time pre-model-call estimate, not a mid-conversation compression event that the user needs to see. --- api/streaming.py | 3 +-- tests/test_auto_compression_card.py | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/streaming.py b/api/streaming.py index f9dc14eb..5f2645d3 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -587,8 +587,7 @@ def _is_agent_compression_start_status(kind: str, message: str) -> bool: if 'compressed' in m and 'compressing' not in m and 'compression attempt' not in m: return False return ( - 'preflight compression:' in m - or 'pre-api compression:' in m + 'pre-api compression:' in m or 'compacting context' in m or 'context too large' in m or '— compressing (' in m diff --git a/tests/test_auto_compression_card.py b/tests/test_auto_compression_card.py index a6bfa8fd..b8f46d18 100644 --- a/tests/test_auto_compression_card.py +++ b/tests/test_auto_compression_card.py @@ -473,7 +473,10 @@ def test_agent_status_callback_emits_compressing_and_warning_events(): def test_agent_compression_start_status_matches_real_emitters_only(): # Real start notices from hermes-agent emitters - assert _is_agent_compression_start_status( + # Preflight compression is excluded — it fires on every new session + # where the system prompt alone exceeds the threshold, producing a + # false "Compressing context" card before any model output. + assert not _is_agent_compression_start_status( "lifecycle", "📦 Preflight compression: ~101,000 tokens >= 96,000 threshold. This may take a moment.", ) From f52be26610266ef10ad67eaf360920f861bb01b8 Mon Sep 17 00:00:00 2001 From: happy5318 Date: Sat, 1 Aug 2026 01:47:51 +0800 Subject: [PATCH 2/2] docs: update comments to reflect preflight exclusion reasoning Clarify that preflight compression is intentionally excluded because the later authoritative 'Compacting context' marker from conversation_compression is the real signal that compression proceeded. The preflight status can fire even when compression exits before compaction (e.g. durable guard refresh, Codex-Hermes mode with no active thread). --- api/streaming.py | 7 +++++-- tests/test_auto_compression_card.py | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/api/streaming.py b/api/streaming.py index 5f2645d3..f83a6d35 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -566,8 +566,11 @@ def _is_agent_compression_start_status(kind: str, message: str) -> bool: auto-compression. Positive markers below match the agent emitters in hermes-agent - (``turn_context`` preflight, ``conversation_loop`` pre-API / 413 / too-large, - ``conversation_compression`` compaction status). Explicitly reject skip / + (``conversation_loop`` pre-API / 413 / too-large, + ``conversation_compression`` compaction status). Preflight compression + (``turn_context``) is intentionally excluded — the later authoritative + ``Compacting context`` marker is the signal that compression actually + proceeded. Explicitly reject skip / defer notices so "Skipping preflight compression…" never surfaces as a running compress divider. """ diff --git a/tests/test_auto_compression_card.py b/tests/test_auto_compression_card.py index b8f46d18..837ff474 100644 --- a/tests/test_auto_compression_card.py +++ b/tests/test_auto_compression_card.py @@ -473,9 +473,12 @@ def test_agent_status_callback_emits_compressing_and_warning_events(): def test_agent_compression_start_status_matches_real_emitters_only(): # Real start notices from hermes-agent emitters - # Preflight compression is excluded — it fires on every new session - # where the system prompt alone exceeds the threshold, producing a - # false "Compressing context" card before any model output. + # Preflight compression is intentionally excluded — the later + # authoritative ``Compacting context`` marker from + # conversation_compression is the signal that compression + # actually proceeded, and the preflight status can fire even + # when compression exits before compaction (e.g. durable + # guard refresh, Codex-Hermes mode with no active thread). assert not _is_agent_compression_start_status( "lifecycle", "📦 Preflight compression: ~101,000 tokens >= 96,000 threshold. This may take a moment.",