The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(worker): round-trip the owner-minted message_uid in row annotations
Teknium1266d2b4cdee
diff --git a/agent/runtime_session_compression.py b/agent/runtime_session_compression.pyindex 013deec20ba..c20bfe61e3e 100644--- a/agent/runtime_session_compression.py+++ b/agent/runtime_session_compression.py@@ -77,8 +77,8 @@ class RuntimeSessionCompressionMixin:model_config_patch=model_config_patch, watermark=watermark, lock_holder=lock_holder,tail_count=tail_count, carried_messages=carried, covered_ids=covered_ids,unresolved_held=unresolved))- for message, row_id in zip(compacted_messages, result['row_ids'], strict=True):- message['_row_id'] = row_id+ from agent.runtime_session_store import apply_row_annotations+ apply_row_annotations(compacted_messages, result['annotations'])return result['value']def publish_compression_child(self, *, parent_session_id, child_session_id, source, messages,@@ -91,8 +91,8 @@ class RuntimeSessionCompressionMixin:cwd=cwd, profile_name=profile_name, compression_lock_holder=compression_lock_holder,require_compression_lease=require_compression_lease, require_lease_refresh=require_lease_refresh,lease_ttl_seconds=lease_ttl_seconds, watermark=watermark, watermark_ceiling=watermark_ceiling))- for message, row_id in zip(messages, result['row_ids'], strict=True):- message['_row_id'] = row_id+ from agent.runtime_session_store import apply_row_annotations+ apply_row_annotations(messages, result['annotations'])def _compression_receipt_journal(self, candidate, result):assignment = result.get('worker_assignment')diff --git a/hermes_state_runtime.py b/hermes_state_runtime.pyindex 336cc8d7f75..46c3dc89dc7 100644--- a/hermes_state_runtime.py+++ b/hermes_state_runtime.py@@ -7,7 +7,9 @@ import jsonimport uuidfrom agent.conversation_compression_archive import ABSORBED_ROW_IDS-from agent.message_metadata import CANONICAL_ROW, DB_ROW_SNAPSHOT, PERSISTENCE_ONLY_MESSAGE_FIELDS+from agent.message_metadata import (+ CANONICAL_ROW, DB_ROW_SNAPSHOT, MESSAGE_UID, PERSISTENCE_ONLY_MESSAGE_FIELDS, TOOL_CALL_UID, TOOL_CALL_UIDS,+)from hermes_state_keys import admission_fingerprint@@ -512,9 +514,12 @@ _MESSAGE_FIELDS = frozenset({# Compaction handoffs (archive/publish) also carry the summary's user-turn flag. This is the closed# boundary the owner validates AND the projection the worker facade applies to live dicts first.HANDOFF_MESSAGE_FIELDS = _MESSAGE_FIELDS | {'_compressed_summary_has_user_turn'}-# Row state the owner's transcript repair stamps on each message (main mutates the caller's dict-# in place; a worker gets it back as an annotation). None = absent, so a stale adoption is cleared.-_ROW_ANNOTATION_KEYS = ('_row_id', 'timestamp', DB_ROW_SNAPSHOT, CANONICAL_ROW)+# Row state the owner's insert and transcript repair stamp on each message (main mutates the caller's+# dict in place; a worker gets it back as an annotation). None = absent, so a stale adoption is cleared.+# The owner-minted identity rides too: a worker dict without it re-mints a new uid on every later+# archive/rotation copy, so the logical message changes identity across generations.+_ROW_ANNOTATION_KEYS = ('_row_id', 'timestamp', DB_ROW_SNAPSHOT, CANONICAL_ROW,+ MESSAGE_UID, TOOL_CALL_UIDS, TOOL_CALL_UID)def row_annotations(messages):diff --git a/hermes_state_worker_compression.py b/hermes_state_worker_compression.pyindex 929a303ed7e..056347d3278 100644--- a/hermes_state_worker_compression.py+++ b/hermes_state_worker_compression.py@@ -272,7 +272,8 @@ def worker_archive(db, conn, sid, payload):value = archive_on_connection(db, conn, sid, payload['messages'], model_config_patch=patch,watermark=payload['watermark'], lock_holder=payload['lock_holder'], tail_count=payload['tail_count'],carried_messages=carried, covered_ids=covered, unresolved_held=unresolved)- return {'value': value, 'row_ids': [message['_row_id'] for message in payload['messages']]}+ from hermes_state_runtime import row_annotations+ return {'value': value, 'annotations': row_annotations(payload['messages'])}def _migrate_worker_automation(db, conn, parent, child):@@ -339,8 +340,9 @@ def worker_publish(db, conn, sid, payload):"WHERE json_extract(lineage_json,'$[#-1]')=? AND generation=? AND owner_epoch=? ""AND status IN ('started','unknown')",(child, sid, worker['generation'], worker['owner_epoch']))+ from hermes_state_runtime import row_annotationsreturn {'value': None, 'worker_assignment': {'parent': sid, 'session_id': child},- 'row_ids': [message['_row_id'] for message in payload['messages']]}+ 'annotations': row_annotations(payload['messages'])}def worker_receipt_assignment(conn, execution_id, session_id, generation, sequence, digest):diff --git a/tests/hermes_state/test_runtime_worker_compression_annotations.py b/tests/hermes_state/test_runtime_worker_compression_annotations.pyindex ee88fcc7f74..8f524897a8e 100644--- a/tests/hermes_state/test_runtime_worker_compression_annotations.py+++ b/tests/hermes_state/test_runtime_worker_compression_annotations.py@@ -36,3 +36,23 @@ def test_compacted_messages_keep_current_row_ids_across_repeated_compaction(tmp_store.journal['pending'] = []store.close()db.close()+++def test_owner_minted_message_uid_round_trips_through_append_and_archive(worker):+ """The owner mints ``message_uid`` at the first insert; the worker's live dict must carry it back+ so every later archive copy re-issues the SAME logical identity (direct SessionDB stamps the caller's+ dict in place). Without it each compaction generation mints a fresh uid (helix4u #4)."""+ db, store = worker+ messages = [{'role': 'user', 'content': 'kept'}, {'role': 'assistant', 'content': 'reply'}]+ store.append_messages_batch('owned', messages)++ def stored():+ with db._read_ctx() as conn:+ return [r[0] for r in conn.execute(+ 'SELECT message_uid FROM messages WHERE session_id=? AND active=1 ORDER BY id', ('owned',))]++ first = stored()+ assert [m.get('message_uid') for m in messages] == first and all(first)+ for _ in range(2):+ store.archive_and_compact('owned', messages, tail_count=0)+ assert stored() == first == [m['message_uid'] for m in messages]