Skip to content

The agent that grows with you

fix(state): exports and the transcript list show a carried reply once too

Tekniumc8aa61b78830
diff --git a/hermes_state_messages.py b/hermes_state_messages.py
index 318cdce3088..d350dac52d4 100644
--- a/hermes_state_messages.py
+++ b/hermes_state_messages.py
@@ -1165,11 +1165,12 @@ class SessionMessagesMixin(SessionDetachedResultsMixin, SessionTodoResultMixin):
on one definition of a logical message; the live copy wins its group via the read
path's ``ORDER BY candidate.active DESC, candidate.id DESC``. Writes only on drift."""
first_id: dict[bytes, int] = {}
+ uid_identity: dict[str, bytes] = {} # message_uid -> its first copy's identity (the carrier rule)
last_id = 0
while True:
rows = conn.execute(
"SELECT id, role, content, timestamp, tool_call_id, tool_calls, tool_name, "
- "display_kind, display_metadata, display_order, display_identity "
+ "display_kind, display_metadata, display_order, display_identity, message_uid, _compressed_summary "
"FROM messages INDEXED BY idx_messages_session_id "
"WHERE session_id = ? AND id > ? AND (active = 1 OR compacted = 1) "
"ORDER BY id LIMIT 1000",
@@ -1179,6 +1180,12 @@ class SessionMessagesMixin(SessionDetachedResultsMixin, SessionTodoResultMixin):
for row in rows:
last_id = row["id"]
identity = self._display_identity(self._display_dedupe_key(row))
+ # Same rule as _dedupe_display_generations: a summary carrier is a copy of the message its uid names.
+ uid = row["message_uid"]
+ if uid and row["_compressed_summary"]:
+ identity = uid_identity.get(uid, identity)
+ elif uid:
+ uid_identity.setdefault(uid, identity)
# A row already holding this identity keeps its stored slot (an in-place prune changes a
# row's content, not its place); otherwise the slot is the identity's first row.
kept = row["display_order"] if row["display_identity"] == identity else None
diff --git a/tests/hermes_state/test_resume_summary_carrier_once.py b/tests/hermes_state/test_resume_summary_carrier_once.py
index da40a0a8edc..f3cd8420bf7 100644
--- a/tests/hermes_state/test_resume_summary_carrier_once.py
+++ b/tests/hermes_state/test_resume_summary_carrier_once.py
@@ -34,7 +34,12 @@ def test_summary_carrier_does_not_show_its_message_twice(tmp_path):
db.archive_and_compact("s", [stored[0], carried, *stored[2:]])
shown = db.get_messages_as_conversation("s", include_ancestors=True, include_compacted=True)
- assert sum(str(m.get("content")).count("REPLY-ONE") for m in shown) == 1, shown
- # The other messages are untouched: each still shows exactly once.
- for text in ("turn one", "turn two", "REPLY-TWO"):
- assert sum(str(m.get("content")).count(text) for m in shown) == 1, (text, shown)
+ listed = db.get_messages("s", include_compacted=True) # the SQL display read exports use
+ export = db.export_session("s", include_compacted=True)
+ assert export is not None
+ exported = export["messages"]
+ for read in (shown, listed, exported):
+ assert sum(str(m.get("content")).count("REPLY-ONE") for m in read) == 1, read
+ # The other messages are untouched: each still shows exactly once.
+ for text in ("turn one", "turn two", "REPLY-TWO"):
+ assert sum(str(m.get("content")).count(text) for m in read) == 1, (text, read)