The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): do not match a folded assistant's synthetic text against durable rows (#129123)
unsupportedpastels556139aa02a6
diff --git a/hermes_state_messages.py b/hermes_state_messages.pyindex f76cd908f74..5feb9f68581 100644--- a/hermes_state_messages.py+++ b/hermes_state_messages.py@@ -1097,7 +1097,8 @@ class SessionMessagesMixin:if covered_ids is None:return Nonefrom agent.context_compressor import _DB_PERSISTED_MARKER- from agent.conversation_compression_archive import MERGED_DURABLE_ROWS, OWN_ROW, RETIRED_ROW+ from agent.conversation_compression_archive import (+ MERGED_DURABLE_ROWS, OWN_ROW, RETIRED_DURABLE_ROWS, RETIRED_ROW)proved = [int(row_id) for row_id in covered_ids if isinstance(row_id, int) and row_id > 0]merged_away: Set[int] = set()@@ -1114,6 +1115,10 @@ class SessionMessagesMixin:if not message.get(OWN_ROW):merged_away.update(matches)continue+ # A folded assistant's own row is named by its OWN_ROW record above. Its combined text never+ # existed in storage, so matching it by content could only claim another surface's row.+ if any(isinstance(row, dict) and row.get(OWN_ROW) for row in message.get(RETIRED_DURABLE_ROWS) or ()):+ continue# The stamp is provenance and text is not: a surface may have re-rendered the dict since the# repair (gateway timestamps), and a later row can equal the merged text. So the run is# resolved first, and a stamped dict that names none is still durable, never an unpersisted turn.diff --git a/tests/hermes_state/test_chained_repair_coverage.py b/tests/hermes_state/test_chained_repair_coverage.pyindex 6987455083c..b20e84222e9 100644--- a/tests/hermes_state/test_chained_repair_coverage.py+++ b/tests/hermes_state/test_chained_repair_coverage.py@@ -48,3 +48,40 @@ def test_composed_repairs_preserve_unseen_context(tmp_path, row_ids, shape):]finally:db.close()++[email protected]("row_ids", [False, True])[email protected]("layout", ["gap", "after_watermark"])+def test_folded_assistant_does_not_claim_unseen_row_with_its_text(tmp_path, row_ids, layout):+ db = SessionDB(tmp_path / "state.db")+ try:+ db.create_session("sid", source="test")+ db.append_message("sid", "user", "U1")+ db.append_message("sid", "assistant", "A1")+ held = db.get_messages_as_conversation("sid", include_row_ids=row_ids)+ # Another surface's reply whose text equals the fold of A2 and A2b, below or above the watermark.+ if layout == "gap":+ db.append_message("sid", "user", "UNSEEN_USER")+ db.append_message("sid", "assistant", "A2\nA2b")+ db.append_message("sid", "user", "U2")+ db.append_message("sid", "assistant", "A2")+ db.append_message("sid", "assistant", "A2b")+ db.append_message("sid", "user", "U3")+ db.append_message("sid", "assistant", "A3")+ loaded = db.get_messages_as_conversation("sid", include_row_ids=row_ids)+ held.extend(loaded[4:] if layout == "gap" else loaded[2:])+ watermark = db.get_active_message_watermark("sid")+ repair_message_sequence(None, held)+ if layout == "after_watermark":+ db.append_message("sid", "user", "UNSEEN_USER")+ db.append_message("sid", "assistant", "A2\nA2b")+ covered, unresolved = coverage_for_commit(db, "sid", held)+ db.archive_and_compact(+ "sid", [{"role": "user", "content": "summary HELD only"}],+ watermark=watermark, covered_ids=covered, unresolved_held=unresolved,+ )+ assert [m["content"] for m in db.get_messages("sid")] == [+ "summary HELD only", "UNSEEN_USER", "A2\nA2b",+ ]+ finally:+ db.close()