Skip to content

The agent that grows with you

fix(compression): stall cooldown covers one idle window; drifted-prompt INFO once per session

joaomarcosf59d973af678
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index e95d54a26f0..73e729952eb 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -2193,7 +2193,15 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngin
def record_timeout_failure(self, error: str, failure_kind: str = "timeout") -> None:
"""Consecutive timeout/stall via the ladder; error persisted as ``backoff:<kind>:strategy=<tail_mode>`` for restarts."""
stamped = f"backoff:{failure_kind or 'timeout'}:strategy={getattr(self, 'tail_mode', None) or 'unknown'}: {error}"
- self._record_compression_failure_cooldown(float(_next_timeout_cooldown(self)), stamped)
+ seconds = float(_next_timeout_cooldown(self))
+ # The first rung (60s) is shorter than the default idle stall window (120s): the next oversized turn
+ # re-entered the same silent route ~1 min after burning the full window (#112420). A stall cooldown
+ # can never be shorter than the window that just failed to show progress.
+ with contextlib.suppress(Exception):
+ from agent.conversation_compression import resolve_context_compression_timeouts
+ idle, _ceiling = resolve_context_compression_timeouts()
+ seconds = max(seconds, float(idle))
+ self._record_compression_failure_cooldown(seconds, stamped)
def _clear_compression_failure_cooldown(self) -> None:
# Fence check BEFORE cooldown-clear: a late cancelled worker must not undo the host's timeout cooldown.
diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py
index 069ac3a48a5..b29df1c9440 100644
--- a/agent/conversation_compression.py
+++ b/agent/conversation_compression.py
@@ -2863,11 +2863,15 @@ def _rebuild_system_prompt_at_boundary(agent: Any, system_message: str) -> str:
else:
new_system_prompt = agent._cached_system_prompt = rebuilt_system_prompt
if cached_system_prompt is not None:
- logger.info(
+ # The rebuild itself stays mandatory; only the first drift per session is INFO — a long session
+ # compacting many times logged this on every compact (19x/day in #112420).
+ log = logger.debug if getattr(agent, "_compaction_prompt_drift_logged", False) is True else logger.info
+ log(
"Compaction rebuilt a drifted system prompt (session=%s, %d -> %d chars): builder output changed "
"since the stored snapshot (update, config change, or memory/skills growth)",
agent.session_id or "none", len(cached_system_prompt), len(new_system_prompt),
)
+ agent._compaction_prompt_drift_logged = True
return new_system_prompt
diff --git a/tests/agent/test_compression_attempt_lifecycle.py b/tests/agent/test_compression_attempt_lifecycle.py
index 0d0f454415d..c5915ffd787 100644
--- a/tests/agent/test_compression_attempt_lifecycle.py
+++ b/tests/agent/test_compression_attempt_lifecycle.py
@@ -229,6 +229,27 @@ class TestDurableAttemptBackoff:
assert compressor.should_compress_info(500_000)[0] is True
+ def test_stall_backoff_is_never_shorter_than_the_idle_window(self, tmp_path: Path, monkeypatch):
+ """The ladder's first rung (60s) undercut a 120s idle stall window, so the next oversized turn
+ re-entered the same silent route ~1 min after burning the whole window (#112420). The recorded
+ cooldown must cover at least one idle window; a window below the rung leaves the ladder as is."""
+ import agent.conversation_compression as cc
+
+ db, agent = _build_agent(tmp_path, "BACKOFF_FLOOR")
+ compressor = agent.context_compressor
+ monkeypatch.setattr(cc, "resolve_context_compression_timeouts", lambda compression_cfg=None: (120.0, 600.0))
+ compressor.record_timeout_failure("stall", failure_kind="stalled")
+ assert compressor._summary_failure_cooldown_until - time.monotonic() >= 119.0
+ durable = db.get_compression_failure_cooldown("BACKOFF_FLOOR")
+ assert durable is not None and durable["remaining_seconds"] >= 119.0
+
+ compressor._clear_compression_failure_cooldown()
+ monkeypatch.setattr(cc, "resolve_context_compression_timeouts", lambda compression_cfg=None: (0.05, 1.0))
+ compressor.record_timeout_failure("stall", failure_kind="stalled")
+ remaining = compressor._summary_failure_cooldown_until - time.monotonic()
+ assert 55.0 <= remaining <= 60.0
+
+
class TestSupersessionDiscardsLateResults:
def test_superseded_attempt_candidate_never_commits(self, tmp_path: Path):
db, agent = _build_agent(tmp_path, "SUPERSEDE")