The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): canonical snapshots carry each row's durable row_id
Tekniuma7ac3a3a16d1
diff --git a/gateway/session_local_recovery.py b/gateway/session_local_recovery.pyindex 09cd7ff6a02..4e17b8766a9 100644--- a/gateway/session_local_recovery.py+++ b/gateway/session_local_recovery.py@@ -112,8 +112,15 @@ def transcript_target(authority, ref):def local_history(authority, ref):- """Display history from the current physical transcript; *ref* stays the logical root."""- return authority.db.get_messages_as_conversation(transcript_target(authority, ref))+ """Display history from the current physical transcript; *ref* stays the logical root.++ Each row carries its durable ``messages.id`` as ``row_id`` (the ``TranscriptMessage`` field+ Desktop hydration and the legacy ``session.history`` already use): a ``session.mutate`` rewind+ addresses its ``target_message_id`` by it, so a snapshot without it leaves no way to undo/retry.+ """+ rows = authority.db.get_messages_as_conversation(transcript_target(authority, ref), include_row_ids=True)+ return [{**{k: v for k, v in row.items() if k != '_row_id'}, 'row_id': row['_row_id']}+ if '_row_id' in row else row for row in rows]def reopen_local_session(authority, ref):diff --git a/tests/gateway/test_local_session_recovery.py b/tests/gateway/test_local_session_recovery.pyindex 0ecd3a393de..ec272676883 100644--- a/tests/gateway/test_local_session_recovery.py+++ b/tests/gateway/test_local_session_recovery.py@@ -94,9 +94,14 @@ def test_messaging_session_history_follows_the_compression_tip(tmp_path, monkeypepoch=begin_runtime_epoch(db, instance_id='current'))source = SimpleNamespace(platform=Platform.TELEGRAM, user_id='human')authority.sessions['root'] = LiveSession(source, 'agent:telegram:dm:1')- contents = [m['content'] for m in local_history(authority, SessionRef('owned', 'root'))]+ history = local_history(authority, SessionRef('owned', 'root'))+ contents = [m['content'] for m in history]assert 'AFTER_COMPRESSION' in contentsassert 'BEFORE_COMPRESSION' not in contents+ # Snapshot rows carry their durable row id (a session.mutate rewind's target_message_id),+ # under the public TranscriptMessage name, never the internal ``_row_id``.+ assert [m['row_id'] for m in history] == [m['id'] for m in db.get_messages('child')]+ assert not any('_row_id' in m for m in history)@pytest.mark.asynciodiff --git a/tests/gateway/test_session_mutation_model.py b/tests/gateway/test_session_mutation_model.pyindex ca018566324..0c29a0abc83 100644--- a/tests/gateway/test_session_mutation_model.py+++ b/tests/gateway/test_session_mutation_model.py@@ -82,7 +82,11 @@ def test_model_receipt_changes_next_wire_and_branch_keeps_independent_history(tmfork = await agent.fork_session(cwd=(await call('session.info', session_id=sid))['cwd'], session_id=sid)child = fork.session_idbranched = await call('session.resume', session_id=child)- assert branched['messages'] == after['messages']+ # Same logical history; each copy has its own physical ``row_id`` (rewind target).+ def logical(rows):+ return [{k: v for k, v in row.items() if k != 'row_id'} for row in rows]+ assert logical(branched['messages']) == logical(after['messages'])+ assert {r['row_id'] for r in branched['messages']}.isdisjoint(r['row_id'] for r in after['messages'])await turn(child, 'ONLY_BRANCH')parent = await call('session.resume', session_id=sid)assert 'ONLY_BRANCH' not in json.dumps(parent['messages'])