Skip to content

Hermes Agent context engine: the main model writes the compaction handoff on its cached prompt prefix

Name the fixed summary in the notice, and clear the streak at a session reset

Elevatormusic700be262e243
diff --git a/README.md b/README.md
index 5261f2a..38195d3 100644
--- a/README.md
+++ b/README.md
@@ -178,7 +178,8 @@ The plugin never stops a compaction: when the warm request cannot run, the fallb
⚠ Warm compaction unavailable: the last 3 compactions could not reuse the prompt cache (provider_error). Likely cause: the server refused the warm request (a provider error, or a gateway that needs a cookie). Compaction continues with the slower fallback summary — no messages were dropped. Details: the warm_compaction lines in logs/agent.log.
```
-- A warm compaction ends the streak, and the notice can show again after the next 3 failures. A cancelled attempt does not count, and `warm: false` is not a failure.
+- When the fallback summary also failed, the notice says how many times, and that those compactions used the fixed summary (no model, less detail).
+- A warm compaction or a session reset ends the streak, and the notice can show again after the next 3 failures. A cancelled attempt does not count, and `warm: false` is not a failure.
- Manual `/compress` has no status line from the engine: after manual compactions only, the notice is in the logs.
## Results
diff --git a/tests/test_wc_engine.py b/tests/test_wc_engine.py
index 90b0c87..77b3c56 100644
--- a/tests/test_wc_engine.py
+++ b/tests/test_wc_engine.py
@@ -658,6 +658,36 @@ class EngineTest(unittest.TestCase):
message = engine.get_automatic_compaction_status_message(phase="compress", default_message="Compacting")
self.assertTrue(message.startswith("\u26a0 Warm compaction unavailable: the last 3 compactions"))
+ def test_the_notice_tells_when_the_fallback_also_failed(self):
+ # The fixed summary has no model request: the notice must not say that the fallback summary works.
+ self.llm = FakeLlm(error=RuntimeError("down"))
+ engine = self.make()
+ history = [*old_turns(), assistant("done")]
+ with self.assertLogs("warm_compaction.engine", level="WARNING") as logs:
+ for _ in range(3):
+ engine.compress(history)
+ self.assertEqual(engine.warm_last["path"], "fixed")
+ notice = engine.get_automatic_compaction_status_message(phase="compress", default_message="Compacting")
+ self.assertNotIn("continues with the slower fallback summary", notice)
+ self.assertIn("the fallback summary also failed 3 of 3 times", notice)
+ self.assertIn("fixed summary", notice)
+ self.assertIn("no messages were dropped", notice)
+ self.assertEqual(sum("3 of them with the fixed summary" in line for line in logs.output), 1)
+
+ def test_a_session_reset_clears_the_failure_streak(self):
+ # A notice or a streak of the old session does not show in the new session.
+ engine = self.make()
+ history = [*old_turns(), assistant("done")]
+ for _ in range(3):
+ engine.compress(history)
+ engine.on_session_reset()
+ self.assertEqual(engine.get_automatic_compaction_status_message(phase="compress",
+ default_message="Compacting"), "Compacting")
+ for _ in range(2):
+ engine.compress(history)
+ self.assertEqual(engine.get_automatic_compaction_status_message(phase="compress",
+ default_message="Compacting"), "Compacting")
+
def test_an_unusable_capture_does_not_set_the_reasoning_rule(self):
# The capture is of this route, but its rows are not the stored rows: it does not show what the next
# request replays. The stored rows with reasoning_content do.
diff --git a/warm_compaction/engine.py b/warm_compaction/engine.py
index 40d0ce7..60d2631 100644
--- a/warm_compaction/engine.py
+++ b/warm_compaction/engine.py
@@ -164,9 +164,7 @@ class WarmCompactionEngine(ContextEngine):
# True after the first update_model: an empty provider and key are an identity too.
self._wc_identity_set = False
# Compactions in a row without the warm path, their reasons, and the notice for the next status.
- self._warm_failures = 0
- self._warm_failure_reasons: list[str] = []
- self._warm_notice: str | None = None
+ self._clear_warm_failures()
@property
def name(self) -> str:
@@ -247,6 +245,8 @@ class WarmCompactionEngine(ContextEngine):
def on_session_reset(self) -> None:
super().on_session_reset()
self.warm_last = None
+ # The failure streak and its notice are of the old session.
+ self._clear_warm_failures()
# The calibration of the old session: Hermes uses the real prompt count as a floor unless the latch is set.
self.last_real_prompt_tokens = 0
self.awaiting_real_usage_after_compression = False
@@ -651,6 +651,11 @@ class WarmCompactionEngine(ContextEngine):
record["cached_tokens"])
self._note_warm_result(record)
+ def _clear_warm_failures(self) -> None:
+ self._warm_failures, self._warm_fixed = 0, 0
+ self._warm_failure_reasons: list[str] = []
+ self._warm_notice: str | None = None
+
def _note_warm_result(self, record: dict[str, Any]) -> None:
"""Count the compactions in a row without the warm path. Each one is a WARNING (errors.log has it too).
After WARM_FAILURE_STREAK of them, one WARNING names the reasons and the cause, and the next automatic
@@ -660,23 +665,32 @@ class WarmCompactionEngine(ContextEngine):
if path == "warm":
if self._warm_failures >= WARM_FAILURE_STREAK:
logger.info("Warm compaction works again after %d compactions without it", self._warm_failures)
- self._warm_failures, self._warm_failure_reasons, self._warm_notice = 0, [], None
+ self._clear_warm_failures()
return
if path not in ("fallback", "fixed") or reason == "disabled":
return
logger.warning("Warm compaction skipped (%s); used the %s summary", reason, path)
self._warm_failures += 1
+ self._warm_fixed += path == "fixed"
self._warm_failure_reasons.append(reason)
if self._warm_failures == WARM_FAILURE_STREAK:
reasons = ", ".join(dict.fromkeys(self._warm_failure_reasons))
hint = FAILURE_HINTS.get(reason.split(":", 1)[0], "see the Limits section of the plugin README")
+ # The fixed summary has no model request: when the fallback also failed, the notice says so.
+ if self._warm_fixed:
+ continues = (f"Compaction continues, but the fallback summary also failed {self._warm_fixed} of "
+ f"{self._warm_failures} times, so those used the fixed summary (no model, less detail)")
+ log_continues = f"compaction continues, {self._warm_fixed} of them with the fixed summary"
+ else:
+ continues = "Compaction continues with the slower fallback summary"
+ log_continues = "compaction continues with the fallback summary"
# The Hermes warning style on screen: the sign, the subject, what continues, and where to look.
self._warm_notice = (
f"\u26a0 Warm compaction unavailable: the last {self._warm_failures} compactions could not reuse the "
- f"prompt cache ({reasons}). Likely cause: {hint}. Compaction continues with the slower fallback "
- "summary \u2014 no messages were dropped. Details: the warm_compaction lines in logs/agent.log.")
- logger.warning("Warm compaction failed %d times in a row (%s): %s; compaction continues with the "
- "fallback summary", self._warm_failures, reasons, hint)
+ f"prompt cache ({reasons}). Likely cause: {hint}. {continues} \u2014 no messages were dropped. "
+ "Details: the warm_compaction lines in logs/agent.log.")
+ logger.warning("Warm compaction failed %d times in a row (%s): %s; %s", self._warm_failures, reasons,
+ hint, log_continues)
def get_automatic_compaction_status_message(self, *, phase: str, default_message: str,
**context: Any) -> str | None: