Skip to content

The agent that grows with you

fix(agent): do not let hygiene idle timeouts block in-agent compression

Christopher2cb8381963ae
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index cf95c6a6894..c28ff546a2a 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -69,6 +69,20 @@ _SUMMARY_MISSING_CREDENTIAL_MARKERS: tuple[str, ...] = (
"no api key found",
)
+_HYGIENE_IDLE_TIMEOUT_MARKERS: tuple[str, ...] = (
+ "session hygiene compression timed out",
+)
+
+
+def _is_hygiene_idle_timeout_error(error: object) -> bool:
+ """Return True when the durable cooldown came from a hygiene watchdog timeout.
+
+ That persist is intentional for the pre-agent hygiene pass (#74136) but
+ must not block the in-conversation compressor (#86972).
+ """
+ text = str(error or "").strip().casefold()
+ return any(marker in text for marker in _HYGIENE_IDLE_TIMEOUT_MARKERS)
+
def _is_summary_access_or_quota_error(exc: Exception) -> bool:
"""Return True for non-retryable summary auth, permission, or quota errors."""
@@ -2465,6 +2479,13 @@ class ContextCompressor(ContextEngine):
self._last_summary_error = None
return None
+ # Hygiene idle-watchdog timeouts persist the same column so the
+ # pre-agent pass can skip (#74136), but they are not evidence of a
+ # 429/aux-model fault. The in-conversation compressor has its own
+ # budget and must still be allowed to run (#86972).
+ if _is_hygiene_idle_timeout_error(state.get("error")):
+ return None
+
self._summary_failure_cooldown_until = now_mono + remaining_seconds
self._last_summary_error = state.get("error")
self._cooldown_persist_failed = False
diff --git a/tests/agent/test_hygiene_timeout_cooldown_isolation.py b/tests/agent/test_hygiene_timeout_cooldown_isolation.py
new file mode 100644
index 00000000000..b53baf179e0
--- /dev/null
+++ b/tests/agent/test_hygiene_timeout_cooldown_isolation.py
@@ -0,0 +1,67 @@
+"""Hygiene idle-timeout cooldowns must not block the in-agent compressor."""
+
+from __future__ import annotations
+
+import time
+from pathlib import Path
+from unittest.mock import patch
+
+from agent.context_compressor import ContextCompressor
+from hermes_state import SessionDB
+
+_HYGIENE_TIMEOUT_ERROR = (
+ "session hygiene compression timed out with no output from the summary model"
+)
+
+
+def _bound_compressor(db: SessionDB, session_id: str) -> ContextCompressor:
+ with patch(
+ "agent.context_compressor.get_model_context_length",
+ return_value=100_000,
+ ):
+ compressor = ContextCompressor(
+ model="test/model",
+ threshold_percent=0.85,
+ protect_first_n=2,
+ protect_last_n=2,
+ quiet_mode=True,
+ )
+ compressor.bind_session_state(db, session_id)
+ return compressor
+
+
+def test_hygiene_idle_timeout_does_not_block_in_agent_compressor(tmp_path: Path):
+ db = SessionDB(db_path=tmp_path / "state.db")
+ session_id = "hyg-timeout-sid"
+ db.create_session(session_id, source="telegram")
+ db.record_compression_failure_cooldown(
+ session_id,
+ time.time() + 300,
+ _HYGIENE_TIMEOUT_ERROR,
+ )
+
+ compressor = _bound_compressor(db, session_id)
+
+ # Hygiene still sees the durable row so the pre-agent pass can skip.
+ assert db.get_compression_failure_cooldown(session_id) is not None
+ # The in-conversation compressor must not inherit that watchdog timeout.
+ assert compressor.get_active_compression_failure_cooldown() is None
+ db.close()
+
+
+def test_aux_model_fault_cooldown_still_blocks_in_agent_compressor(tmp_path: Path):
+ db = SessionDB(db_path=tmp_path / "state.db")
+ session_id = "aux-fault-sid"
+ db.create_session(session_id, source="telegram")
+ db.record_compression_failure_cooldown(
+ session_id,
+ time.time() + 300,
+ "rate limited",
+ )
+
+ compressor = _bound_compressor(db, session_id)
+
+ state = compressor.get_active_compression_failure_cooldown()
+ assert state is not None
+ assert state["error"] == "rate limited"
+ db.close()