The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(sessions): let a failed durable-uid probe fail the write it runs in
Teknium5f799922c1b7
diff --git a/agent/transcript_repair.py b/agent/transcript_repair.pyindex bce62550971..ed34938f2cf 100644--- a/agent/transcript_repair.py+++ b/agent/transcript_repair.py@@ -5,9 +5,8 @@ clone lookup) and sync markers after commit."""from __future__ import annotationsimport hashlib-import loggingimport sqlite3-from typing import Any, Callable, Dict, List, Mapping, Set+from typing import Any, Callable, Dict, List, Mappingfrom agent.context_compressor import _DB_PERSISTED_MARKERfrom agent.message_metadata import (@@ -16,8 +15,6 @@ from hermes_state_common import _id_chunks, _placeholdersfrom hermes_state_identity import _fill_missing_tool_call_uids, _restore_row_identityfrom hermes_state_messages import _MESSAGE_WRITE_COLUMNS-logger = logging.getLogger("agent.transcript_repair")-# Durable payload columns a row-addressed rewrite may change: every INSERT column except row identity,# role, active flag and the ones owned by the display index / timestamp / session linkage. ``message_uid``@@ -111,8 +108,8 @@ def _active_logical_message_row(def _active_uid_dedupe(- conn: sqlite3.Connection, session_id: str, messages: List[Dict[str, Any]]-) -> Set[str]:+ conn: sqlite3.Connection, session_id: str, messages: list[dict[str, Any]]+) -> set[str]:"""ACTIVE durable uids among *messages*' no-snapshot, no-``_row_id`` dicts — the re-insert guard.A dict rebuilt from durable rows (crash/failed-turn history restore, session resume, a repaired@@ -122,7 +119,7 @@ def _active_uid_dedupe(excluded: the CAS path below owns them — it rewrites the active row in place, so their live editsmust reach the row, never be skipped here. Runs INSIDE the caller's write transaction (the sameguarantee the repair path relies on: the active set cannot change between this read and the- INSERT). Fail-open: a probe error logs and returns an empty set — pre-guard append behavior.+ INSERT). A probe error fails the write like any other statement in it."""candidate_uids = sorted({uid@@ -132,22 +129,18 @@ def _active_uid_dedupe(and not isinstance(msg.get(DB_ROW_SNAPSHOT), str)and (uid := message_uid_or_none(msg))})- durable: Set[str] = set()+ durable: set[str] = set()if not candidate_uids:return durable- try:- for chunk in _id_chunks(candidate_uids):- durable.update(- row["message_uid"]- for row in conn.execute(- f"SELECT DISTINCT message_uid FROM messages "- f"WHERE session_id = ? AND active = 1 AND message_uid IN ({_placeholders(chunk)})",- (session_id, *chunk),- ).fetchall()- )- except Exception as exc:- logger.warning("durable-uid re-insert probe failed (dedupe skipped, append-only behavior): %s", exc)- return set()+ for chunk in _id_chunks(candidate_uids):+ durable.update(+ row["message_uid"]+ for row in conn.execute(+ f"SELECT DISTINCT message_uid FROM messages "+ f"WHERE session_id = ? AND active = 1 AND message_uid IN ({_placeholders(chunk)})",+ (session_id, *chunk),+ ).fetchall()+ )return durable