Hermes Agent context engine: the main model writes the compaction handoff on its cached prompt prefix
Word the warnings in the Hermes style
Elevatormusicd81152348816
diff --git a/README.md b/README.mdindex fb5ff6a..5261f2a 100644--- a/README.md+++ b/README.md@@ -171,11 +171,11 @@ The engine status (`get_status()`) has the same values in `warm_last`. The log nThe plugin never stops a compaction: when the warm request cannot run, the fallback summary does the work. So that this does not go unseen:-- Each compaction without the warm path also writes a WARNING with its reason. Hermes copies warnings to `logs/errors.log`.-- After 3 compactions in a row without the warm path, the plugin writes one WARNING that names the reasons and the likely cause. Hermes shows the same notice with the status of the next automatic compaction, also when the compaction status is turned off. For example:+- Each compaction without the warm path also writes a WARNING with its reason, for example `Warm compaction skipped (provider_error); used the fallback summary`. Hermes copies warnings to `logs/errors.log`.+- After 3 compactions in a row without the warm path, the plugin writes one WARNING that names the reasons and the likely cause. Hermes shows a notice in its warning style with the status of the next automatic compaction, also when the compaction status is turned off. For example:```text- warm_compaction: the last 3 compactions did not use the warm cache (provider_error). Compaction still works with the fallback summary, but it is slower. Likely cause: the server refused the warm request (a provider error, or a gateway that needs a cookie). Details: the warm_compaction lines in logs/agent.log.+ ⚠ 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.diff --git a/evidence/plugin-integration.json b/evidence/plugin-integration.jsonindex fafe47d..00b5ffc 100644--- a/evidence/plugin-integration.json+++ b/evidence/plugin-integration.json@@ -1,17 +1,17 @@{"check": "standalone warm_compaction plugin on unpatched Hermes Agent",- "started_utc": "2026-10-07T02:34:54Z",+ "started_utc": "2026-10-07T02:42:31Z","hermes": {"commit": "45871e100feceb89769536c88e5e6e265226a409","clean": true},"python": "3.11.14",- "script_sha256": "3f14b3f48f0d9dff5928ebdb1cf4570a1ebcb90b417eec8aaa263d265937cd6f",+ "script_sha256": "6131d94a86e7fcbe74f3a3c3bbf19ec1bdc861a36a80d06a98f046e55b8047db","plugin_files_sha256": {- "warm_compaction/__init__.py": "11e038f05813627b2d1d8b82b3b775ecfe41015746c8e90ed6d452cfdaec65a6",+ "warm_compaction/__init__.py": "760484ace80b9da77d7397828f69178905c9ac95df7b8114956bde727bd98aef","warm_compaction/capture.py": "3158562b9b4d4ab50c0ec7a6524bbc1b1c364b137c6d8d27c5801220959021c8",- "warm_compaction/engine.py": "10ec684e79e13765bcd7984a0fea6f1fc1138a2d0cb1ffed41c9914e04c2df0e",- "warm_compaction/fallback.py": "fcd385298c295a019af52381f90effc38417aec02e0415b28e6cb3b242afd7d1",+ "warm_compaction/engine.py": "2b4e788658531a77ef02684f7969645e03bc06856ffbcee036a6206ac6c52d21",+ "warm_compaction/fallback.py": "dc2b7fbfdee292601e52549d23d9b7224d40da1d8c06f553f3d0b8e10a23534d","warm_compaction/handoff.py": "fcab51def8fbcc2b1928957930c9a5c58a4ad202c949fd9f870a77f3b30276ae","warm_compaction/layout.py": "b49314c5236268247c337d9fae939135c97b47384300dcdfd00b0da0c040db93","warm_compaction/plugin.yaml": "d67560fd4625ec80d9e26f3e6d712763e77474f68d469c7e48f09fd3506ccc71",@@ -76,11 +76,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.144,+ "compress_seconds": 0.135,"warm_last": {"path": "warm","reason": "accepted",- "elapsed_s": 0.038,+ "elapsed_s": 0.036,"prompt_tokens": 33892,"cached_tokens": 16946},@@ -189,7 +189,7 @@"install","run"],- "process_seconds": 80.092+ "process_seconds": 61.93},{"scenario": "manual_fallback",@@ -248,11 +248,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.345,+ "compress_seconds": 0.273,"warm_last": {"path": "fallback","reason": "provider_error",- "elapsed_s": 0.172,+ "elapsed_s": 0.125,"prompt_tokens": null,"cached_tokens": null},@@ -260,10 +260,11 @@"final_session_id": "wc-manual_fallback","continuation_keeps_custom_system_text": false,"fence_denied": {- "network_host_blocked": 1,- "child_process_blocked": 3+ "child_process_blocked": 4,+ "network_host_blocked": 1},"fence_blocked_programs": [+ "git","pip","python","python3"@@ -272,6 +273,7 @@"hermes-assets.nousresearch.com"],"fence_blocked_callers": [+ "child_process_blocked from hermes_cli/source_check.py:_git_run < hermes_cli/source_check.py:_git_stdout < hermes_cli/source_check.py:_read_checkout","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_pip_python_version","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_python_version_of","network_host_blocked from hermes_cli/release_channels.py:read < hermes_cli/release_channels.py:read_bytes < hermes_cli/release_channels.py:read_record"@@ -359,7 +361,7 @@"install","run"],- "process_seconds": 47.001+ "process_seconds": 35.685},{"scenario": "manual_fixed",@@ -417,11 +419,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.276,+ "compress_seconds": 0.296,"warm_last": {"path": "fixed","reason": "provider_error",- "elapsed_s": 0.125,+ "elapsed_s": 0.156,"prompt_tokens": null,"cached_tokens": null},@@ -530,7 +532,7 @@"install","run"],- "process_seconds": 38.423+ "process_seconds": 32.033},{"scenario": "auto_tool_loop",@@ -625,7 +627,7 @@"warm_last_2": {"path": "warm","reason": "accepted",- "elapsed_s": 0.016,+ "elapsed_s": 0.0,"prompt_tokens": 19504,"cached_tokens": 9752},@@ -734,7 +736,7 @@"install","run"],- "process_seconds": 38.631+ "process_seconds": 35.213},{"scenario": "auto_warm_failures",@@ -888,7 +890,7 @@]],"notices": [- "🗜️ Compacting context — summarizing earlier conversation so I can continue...\nwarm_compaction: the last 3 compactions did not use the warm cache (provider_error). Compaction still works with the fallback summary, but it is slower. Likely cause: the server refused the warm request (a provider error, or a gateway that needs a cookie). Details: the warm_compaction lines in logs/agent.log."+ "🗜️ Compacting context — summarizing earlier conversation so I can continue...\n⚠ 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."],"status_count": 13,"log_counts": {@@ -897,8 +899,8 @@"errors_notice": 1},"fence_denied": {- "child_process_blocked": 8,- "network_host_blocked": 1+ "network_host_blocked": 1,+ "child_process_blocked": 7},"fence_blocked_programs": ["git",@@ -912,7 +914,6 @@"fence_blocked_callers": ["child_process_blocked from hermes_cli/local_runtime/processes.py:spawn_server < hermes_cli/_subprocess_compat.py:bounded_probe_run < hermes_cli/_subprocess_compat.py:bounded_git_probe","child_process_blocked from hermes_cli/local_runtime/processes.py:spawn_server < hermes_cli/_subprocess_compat.py:bounded_probe_run < hermes_cli/_subprocess_compat.py:noninteractive_repo_git_env",- "child_process_blocked from hermes_cli/source_check.py:_git_run < hermes_cli/source_check.py:_git_stdout < hermes_cli/source_check.py:_read_checkout","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_pip_python_version","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_python_version_of","network_host_blocked from hermes_cli/release_channels.py:read < hermes_cli/release_channels.py:read_bytes < hermes_cli/release_channels.py:read_record"@@ -1001,7 +1002,7 @@"install","run"],- "process_seconds": 38.35+ "process_seconds": 37.846},{"scenario": "rollback",@@ -1051,11 +1052,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.187,+ "compress_seconds": 0.168,"warm_last": {"path": "warm","reason": "accepted",- "elapsed_s": 0.015,+ "elapsed_s": 0.016,"prompt_tokens": 33882,"cached_tokens": 16941},@@ -1237,10 +1238,10 @@"run","rollback"],- "process_seconds": 44.95+ "process_seconds": 40.403}],- "finished_utc": "2026-10-07T02:39:42Z",+ "finished_utc": "2026-10-07T02:46:34Z","passed": true,"run_folder": "outside repository"}diff --git a/scripts/check_plugin_hermes.py b/scripts/check_plugin_hermes.pyindex f469ad2..69df420 100644--- a/scripts/check_plugin_hermes.py+++ b/scripts/check_plugin_hermes.py@@ -67,7 +67,7 @@ SCENARIOS = ("enable_manual_warm", "manual_fallback", "manual_fixed", "auto_tool"rollback")# The scenarios with automatic compaction in a tool loop.AUTO_SCENARIOS = ("auto_tool_loop", "auto_warm_failures")-NOTICE_MARK = "did not use the warm cache"+NOTICE_MARK = "Warm compaction unavailable"# The rollback scenario has a third process: a new Hermes process with the built-in compressor.PHASES = {"rollback": ("install", "run", "rollback")}DEFAULT_PHASES = ("install", "run")@@ -813,12 +813,12 @@ def run_auto_failures(agent, engine, history, server, result, checks, statuses,path = logs / namereturn path.read_text(encoding="utf-8", errors="replace") if path.is_file() else ""agent_log, errors_log = read_log("agent.log"), read_log("errors.log")- refusal = "warm request was not used (provider_error)"+ refusal = "Warm compaction skipped (provider_error)"result["log_counts"] = {"agent_refusals": agent_log.count(refusal), "errors_refusals": errors_log.count(refusal),- "errors_notice": errors_log.count(NOTICE_MARK)}+ "errors_notice": errors_log.count("Warm compaction failed 3 times in a row")}checks["each_refusal_in_agent_log"] = agent_log.count(refusal) == 3checks["each_refusal_in_errors_log"] = errors_log.count(refusal) == 3- checks["notice_in_errors_log"] = errors_log.count(NOTICE_MARK) == 1+ checks["notice_in_errors_log"] = errors_log.count("Warm compaction failed 3 times in a row") == 1# ---------------------------------------------------------------------------------------------------------diff --git a/tests/test_wc_engine.py b/tests/test_wc_engine.pyindex adb0321..90b0c87 100644--- a/tests/test_wc_engine.py+++ b/tests/test_wc_engine.py@@ -594,12 +594,20 @@ class EngineTest(unittest.TestCase):for _ in range(3):engine.compress(history)self.assertEqual((engine.warm_last["path"], engine.warm_last["reason"]), ("fallback", "no_capture"))- self.assertEqual(sum("warm request was not used (no_capture)" in line for line in logs.output), 3)- self.assertEqual(sum("last 3 compactions did not use the warm cache" in line for line in logs.output), 1)+ self.assertEqual(sum("Warm compaction skipped (no_capture); used the fallback summary" in line+ for line in logs.output), 3)+ self.assertEqual(sum("Warm compaction failed 3 times in a row (no_capture)" in line for line in logs.output), 1)+ # Hermes log style: no module prefix in the text (the log format shows the logger name), no emoji.+ self.assertFalse(any(line.split(":", 2)[2].startswith(("warm_compaction:", "\u26a0")) for line in logs.output))message = engine.get_automatic_compaction_status_message(phase="compress", default_message="Compacting")self.assertTrue(message.startswith("Compacting\n"))- self.assertIn("last 3 compactions did not use the warm cache (no_capture)", message)- self.assertIn("no main-model request completed", message)+ # Hermes warning style on screen: the warning sign, a subject, what continues, and where to look.+ notice = message.split("\n", 1)[1]+ self.assertTrue(notice.startswith("\u26a0 Warm compaction unavailable: the last 3 compactions could not "+ "reuse the prompt cache (no_capture)."))+ self.assertIn("no main-model request completed", notice)+ self.assertIn("no messages were dropped", notice)+ self.assertIn("logs/agent.log", notice)# One time only.self.assertEqual(engine.get_automatic_compaction_status_message(phase="compress",default_message="Compacting"), "Compacting")@@ -628,7 +636,7 @@ class EngineTest(unittest.TestCase):engine._compression_cancelled_check = lambda: Falsefor _ in range(2):engine.compress(history)- self.assertIn("did not use the warm cache",+ self.assertIn("Warm compaction unavailable",engine.get_automatic_compaction_status_message(phase="compress", default_message="Compacting"))def test_the_warm_setting_off_is_not_a_failure(self):@@ -648,7 +656,7 @@ class EngineTest(unittest.TestCase):engine.compress(history)engine.emit_automatic_compaction_status = Falsemessage = engine.get_automatic_compaction_status_message(phase="compress", default_message="Compacting")- self.assertTrue(message.startswith("warm_compaction: the last 3 compactions"))+ self.assertTrue(message.startswith("\u26a0 Warm compaction unavailable: the last 3 compactions"))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 nextdiff --git a/warm_compaction/__init__.py b/warm_compaction/__init__.pyindex 02ce465..b0ebee7 100644--- a/warm_compaction/__init__.py+++ b/warm_compaction/__init__.py@@ -61,8 +61,8 @@ def register(ctx: Any) -> None:"API.", ", ".join(missing))returnif missing:- logger.warning("warm_compaction: Hermes does not have these plugin APIs: %s. The plugin registers "- "nothing, and Hermes keeps its built-in compressor.", ", ".join(missing))+ logger.warning("Hermes is missing plugin APIs that warm_compaction needs (%s); the plugin registers "+ "nothing and Hermes keeps its built-in compressor", ", ".join(missing))returnfrom .capture import CaptureStorefrom .engine import WarmCompactionEngine, read_settings@@ -74,12 +74,12 @@ def register(ctx: Any) -> None:defaults={"timeout": 120})except Exception as error:task = None- logger.warning("warm_compaction: the auxiliary task was not registered (%s). The fallback summary uses "- "the main model route.", type(error).__name__)+ logger.warning("warm_compaction could not register its auxiliary task (%s); the fallback summary uses "+ "the main model route", type(error).__name__)store = CaptureStore()engine = WarmCompactionEngine(store=store, llm=ctx.llm, settings=read_settings(ctx.get_config), task=task)if ctx.register_context_engine(engine) is None:- logger.warning("warm_compaction: Hermes did not accept the context engine. The plugin registers no hooks.")+ logger.warning("Hermes did not accept the warm_compaction context engine; the plugin registers no hooks")returnctx.register_hook("pre_api_request", store.on_pre_api_request)ctx.register_middleware(MIDDLEWARE, store.on_llm_execution)diff --git a/warm_compaction/engine.py b/warm_compaction/engine.pyindex 1ce410b..40d0ce7 100644--- a/warm_compaction/engine.py+++ b/warm_compaction/engine.py@@ -80,7 +80,7 @@ def read_settings(get_config: Callable[..., Any] | None) -> dict[str, Any]:if _valid(key, value):settings[key] = float(value) if key == "threshold" else valueelse:- logger.warning("warm_compaction: the setting %s is not valid; the default %r applies", key, default)+ logger.warning("Invalid warm_compaction setting %s; using the default %r", key, default)return settings@@ -283,7 +283,7 @@ class WarmCompactionEngine(ContextEngine):if summary is not None and not self._summary_fits(summary, overhead, reserve):# A dense handoff can pass the byte gate and still not fit below the threshold: the next request would# compact again at once. The fallback summary has a smaller limit.- logger.warning("warm_compaction: the warm summary does not fit in the room; fallback used")+ logger.warning("Warm compaction summary does not fit in the free context; using the fallback summary")record.update(path=None, reason="summary_too_large")summary = None# The middles that the tail cuts (see layout.bound_tail): the rows before the tail do not have them.@@ -303,7 +303,8 @@ class WarmCompactionEngine(ContextEngine):# A dense summary (CJK, for example) above the reserve: the tail would cut more than the# transcript had. Or above the room (a large system prompt and a low threshold): the next request# would compact again at once. The fixed summary quotes what the final tail cuts, in the room.- logger.warning("warm_compaction: the fallback summary is above the reserve; fixed summary used")+ logger.warning("Warm compaction fallback summary is above its token reserve or the free context; "+ "using the fixed summary")summary = Noneif summary is not None:record["path"] = "fallback"@@ -351,7 +352,8 @@ class WarmCompactionEngine(ContextEngine):else:# No quote fits after the summary: the cut middle would be lost. The fixed summary has# the room for it.- logger.warning("warm_compaction: no room for the cut quote; fixed summary used")+ logger.warning("No room for the cut quote after the fallback summary; using the fixed "+ "summary")record["path"] = "fixed"cut = []if record["path"] == "fixed":@@ -657,23 +659,24 @@ class WarmCompactionEngine(ContextEngine):path, reason = record["path"], str(record["reason"])if path == "warm":if self._warm_failures >= WARM_FAILURE_STREAK:- logger.info("warm_compaction: the warm path works again after %d compactions without it",- self._warm_failures)+ 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, [], Nonereturnif path not in ("fallback", "fixed") or reason == "disabled":return- logger.warning("warm_compaction: the warm request was not used (%s); the %s summary was used", reason, path)+ logger.warning("Warm compaction skipped (%s); used the %s summary", reason, path)self._warm_failures += 1self._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 Hermes warning style on screen: the sign, the subject, what continues, and where to look.self._warm_notice = (- f"warm_compaction: the last {self._warm_failures} compactions did not use the warm cache ({reasons}). "- f"Compaction still works with the fallback summary, but it is slower. Likely cause: {hint}. "- "Details: the warm_compaction lines in logs/agent.log.")- logger.warning(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)def get_automatic_compaction_status_message(self, *, phase: str, default_message: str,**context: Any) -> str | None:diff --git a/warm_compaction/fallback.py b/warm_compaction/fallback.pyindex ef15666..e721fc7 100644--- a/warm_compaction/fallback.py+++ b/warm_compaction/fallback.py@@ -211,7 +211,7 @@ def llm_summary(llm: Any, messages: list, prefixes: Iterable[str], *, focus_topitry:result = llm.complete(request, task=task, max_tokens=MAX_TOKENS, timeout=timeout_s, purpose=PURPOSE)except Exception as error:- logger.warning("warm_compaction: the fallback summary request failed (%s)", type(error).__name__)+ logger.warning("Warm compaction fallback summary request failed (%s)", type(error).__name__)return None, None# The same checks as the warm reply: the five headings, the byte limit, and no summary markers. A reply# without them (cut off, or an answer to the conversation) must not replace the history.@@ -219,7 +219,7 @@ def llm_summary(llm: Any, messages: list, prefixes: Iterable[str], *, focus_topifinish, body = _complete_reply(result, raw)text, reason = gate({"content": body, "finish_reason": finish}, prefixes)if text is None:- logger.warning("warm_compaction: the fallback summary was refused (%s)", reason)+ logger.warning("Warm compaction fallback summary refused (%s)", reason)return None, Nonetokens = getattr(getattr(result, "usage", None), "input_tokens", None)return text, tokens if isinstance(tokens, int) and tokens > 0 else None