Skip to content

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

Compare the replayed reasoning fields of the captured rows

Elevatormusicd242e1a9d40f
diff --git a/evidence/plugin-integration.json b/evidence/plugin-integration.json
index d208268..7b5a133 100644
--- a/evidence/plugin-integration.json
+++ b/evidence/plugin-integration.json
@@ -1,6 +1,6 @@
{
"check": "standalone warm_compaction plugin on unpatched Hermes Agent",
- "started_utc": "2026-10-06T10:05:44Z",
+ "started_utc": "2026-10-06T10:19:34Z",
"hermes": {
"commit": "45871e100feceb89769536c88e5e6e265226a409",
"clean": true
@@ -16,7 +16,7 @@
"warm_compaction/layout.py": "5e730211647eed0beec1e6819dfc008b0855a0866dc920bb0cf8d6d8ab2dfa92",
"warm_compaction/plugin.yaml": "d67560fd4625ec80d9e26f3e6d712763e77474f68d469c7e48f09fd3506ccc71",
"warm_compaction/rows.py": "cc2a8a3d0561559f24fc40881453441d938ea9d7803e1df81a107a5e05e5f00a",
- "warm_compaction/warm.py": "b429103b13301e2eb82fb9c7bae422d28be5049114e27d71c5586762856b8c03"
+ "warm_compaction/warm.py": "1ceb52115da6186dccd9b6000224940a119b788858721bb2c144cb5e3ff20f18"
},
"privacy": "metadata only: names, counts, codes, booleans, and times; no message text",
"scenarios": [
@@ -75,11 +75,11 @@
"threshold_tokens": 100000,
"context_length": 200000
},
- "compress_seconds": 0.097,
+ "compress_seconds": 0.093,
"warm_last": {
"path": "warm",
"reason": "accepted",
- "elapsed_s": 0.022,
+ "elapsed_s": 0.018,
"prompt_tokens": 33883,
"cached_tokens": 16941
},
@@ -188,7 +188,7 @@
"install",
"run"
],
- "process_seconds": 57.137
+ "process_seconds": 53.953
},
{
"scenario": "manual_fallback",
@@ -247,11 +247,11 @@
"threshold_tokens": 100000,
"context_length": 200000
},
- "compress_seconds": 0.228,
+ "compress_seconds": 0.25,
"warm_last": {
"path": "fallback",
"reason": "provider_error",
- "elapsed_s": 0.093,
+ "elapsed_s": 0.11,
"prompt_tokens": null,
"cached_tokens": null
},
@@ -360,7 +360,7 @@
"install",
"run"
],
- "process_seconds": 33.072
+ "process_seconds": 32.264
},
{
"scenario": "manual_fixed",
@@ -418,7 +418,7 @@
"threshold_tokens": 100000,
"context_length": 200000
},
- "compress_seconds": 0.234,
+ "compress_seconds": 0.211,
"warm_last": {
"path": "fixed",
"reason": "provider_error",
@@ -430,7 +430,7 @@
"final_session_id": "wc-manual_fixed",
"continuation_keeps_custom_system_text": false,
"fence_denied": {
- "child_process_blocked": 4,
+ "child_process_blocked": 5,
"network_host_blocked": 1
},
"fence_blocked_programs": [
@@ -531,7 +531,7 @@
"install",
"run"
],
- "process_seconds": 29.807
+ "process_seconds": 29.438
},
{
"scenario": "auto_tool_loop",
@@ -617,20 +617,20 @@
"warm_last_1": {
"path": "warm",
"reason": "accepted",
- "elapsed_s": 0.016,
+ "elapsed_s": 0.0,
"prompt_tokens": 35201,
"cached_tokens": 17600
},
"warm_last_2": {
"path": "warm",
"reason": "accepted",
- "elapsed_s": 0.0,
+ "elapsed_s": 0.015,
"prompt_tokens": 18427,
"cached_tokens": 9213
},
"compression_count": 2,
"fence_denied": {
- "child_process_blocked": 8,
+ "child_process_blocked": 9,
"network_host_blocked": 1
},
"fence_blocked_programs": [
@@ -734,7 +734,7 @@
"install",
"run"
],
- "process_seconds": 32.601
+ "process_seconds": 32.516
},
{
"scenario": "rollback",
@@ -784,11 +784,11 @@
"threshold_tokens": 100000,
"context_length": 200000
},
- "compress_seconds": 0.155,
+ "compress_seconds": 0.159,
"warm_last": {
"path": "warm",
"reason": "accepted",
- "elapsed_s": 0.0,
+ "elapsed_s": 0.015,
"prompt_tokens": 33873,
"cached_tokens": 16936
},
@@ -796,7 +796,7 @@
"final_session_id": "wc-rollback",
"continuation_keeps_custom_system_text": false,
"fence_denied": {
- "child_process_blocked": 4,
+ "child_process_blocked": 5,
"network_host_blocked": 1
},
"fence_blocked_programs": [
@@ -947,8 +947,7 @@
"stored": 30
},
"fence_denied": {
- "child_process_blocked": 5,
- "network_host_blocked": 1
+ "child_process_blocked": 5
},
"fence_blocked_programs": [
"git",
@@ -956,9 +955,7 @@
"python",
"python3"
],
- "fence_blocked_hosts": [
- "hermes-assets.nousresearch.com"
- ]
+ "fence_blocked_hosts": []
},
"exit": [
0,
@@ -970,10 +967,10 @@
"run",
"rollback"
],
- "process_seconds": 39.1
+ "process_seconds": 37.062
}
],
- "finished_utc": "2026-10-06T10:08:56Z",
+ "finished_utc": "2026-10-06T10:22:40Z",
"passed": true,
"run_folder": "outside repository"
}
diff --git a/tests/test_wc_warm.py b/tests/test_wc_warm.py
index ed3f4ee..4e9b80e 100644
--- a/tests/test_wc_warm.py
+++ b/tests/test_wc_warm.py
@@ -309,6 +309,33 @@ class BuildRequestTest(unittest.TestCase):
with self.subTest(base_url=base_url):
self.assertEqual(sent.get("reasoning_details"), expected)
+ def test_refuses_changed_reasoning_fields_in_the_captured_rows(self):
+ # The provider reads reasoning_content, reasoning_details, and the thought signature of a captured
+ # assistant row. A middleware that changed them made a prefix that differs from the stored history.
+ details = [{"type": "reasoning.encrypted", "data": "abc"}]
+ signed = {"google": {"thought_signature": "sig-1"}}
+ echo = ([user("u1"), assistant("a1", reasoning_content="think"), user("u2")], ROUTE)
+ replay = ([user("u1"), assistant("a1", reasoning_details=details), user("u2")],
+ (ROUTE[0], "https://openrouter.ai/api/v1", ROUTE[2]))
+ gemini_row = assistant("", [("c0", "read", "{}")])
+ gemini_row["tool_calls"][0]["extra_content"] = signed
+ gemini = ([user("u1"), gemini_row, tool("c0", "r0"), user("u2")], ("gemini-3-pro", ROUTE[1], ROUTE[2]))
+ changes = [
+ (echo, lambda row: row.update(reasoning_content="other")),
+ (echo, lambda row: row.update(reasoning_content=" ")),
+ (replay, lambda row: row.pop("reasoning_details")),
+ (replay, lambda row: row.update(reasoning_details=[{"type": "reasoning.encrypted", "data": "x"}])),
+ (gemini, lambda row: row["tool_calls"][0].pop("extra_content")),
+ ]
+ for (rows, route), change in changes:
+ self.rows, self.messages = rows, [*rows, self.reply, tool("c1", "r1"), user("u3")]
+ self.build(capture_for(self.rows, self.reply, route=route), route)
+ capture = capture_for(self.rows, self.reply, route=route)
+ change(capture["body"]["messages"][2])
+ with self.subTest(route=route), self.assertRaises(WarmRefusal) as caught:
+ self.build(capture, route)
+ self.assertEqual(caught.exception.code, "source_transform_unsupported")
+
def test_accepts_request_time_context_and_reformatted_arguments(self):
capture = self._tool_round()
sent = capture["body"]["messages"]
diff --git a/warm_compaction/warm.py b/warm_compaction/warm.py
index 5882670..5407fb9 100644
--- a/warm_compaction/warm.py
+++ b/warm_compaction/warm.py
@@ -141,7 +141,16 @@ def _same_row(wire: Any, row: Any) -> bool:
_arguments(arguments) for _id, _name, arguments in tool_calls_of(row)]
-def check_source(body: dict[str, Any], history_rows: list) -> None:
+def _same_replay_fields(wire: Any, expected: dict[str, Any]) -> bool:
+ """True when the sent row has the reasoning fields and thought signatures that Hermes replays for the stored
+ row on this route. The provider reads them, so a change makes a prefix that the history does not have."""
+ if any(attr(wire, key) != expected.get(key) for key in ("reasoning_content", "reasoning_details")):
+ return False
+ return [attr(call, "extra_content") for call in attr(wire, "tool_calls") or []] == [
+ call.get("extra_content") for call in expected.get("tool_calls") or []]
+
+
+def check_source(body: dict[str, Any], history_rows: list, base_url: Any = None) -> None:
"""Refuse a request whose messages are not system rows followed by the stored rows. A row that a hook or
a middleware rewrote would make the handoff summarize text that is not in the history it replaces."""
sent = body["messages"]
@@ -150,6 +159,11 @@ def check_source(body: dict[str, Any], history_rows: list) -> None:
raise WarmRefusal("source_transform_unsupported")
if not all(_same_row(wire, row) for wire, row in zip(sent[offset:], history_rows)):
raise WarmRefusal("source_transform_unsupported")
+ # The replayed fields follow the captured request only: the new rows do not change what Hermes sent.
+ echo = needs_reasoning_echo(body, [])
+ if not all(_same_replay_fields(wire, wire_row(row, echo, body.get("model"), base_url))
+ for wire, row in zip(sent[offset:], history_rows)):
+ raise WarmRefusal("source_transform_unsupported")
def _reasoning_policy(source: dict, wire: dict, needs_pad: bool) -> None:
@@ -285,7 +299,7 @@ def build_request(capture: dict[str, Any], messages: list, route: tuple, context
raise WarmRefusal(capture.get("refusal") or "settings_unsupported")
check_settings(body)
new_rows, trailing = split_history(capture, messages)
- check_source(body, messages[: len(capture["digests"])])
+ check_source(body, messages[: len(capture["digests"])], route[1])
request = dict(body)
# Send the trailing user rows too: the tail can keep only the newest of them, and compaction removes the others.
echo = needs_reasoning_echo(body, new_rows)