The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): a superseded verification candidate is not a merge-witness constituent
Evac85beecacd8d
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.pyindex b7a6f6b5c50..d72624d86dd 100644--- a/agent/agent_runtime_helpers.py+++ b/agent/agent_runtime_helpers.py@@ -453,7 +453,7 @@ def _merge_assistant_into(prev: Dict, msg: Dict) -> None:prev.pop(_DB_PERSISTED_MARKER, None)-def _remember_absorbed_row(survivor: Dict[str, Any], dropped: Dict[str, Any]) -> None:+def _remember_absorbed_row(survivor: Dict[str, Any], dropped: Dict[str, Any], *, folded: bool = True) -> None:"""Record durable ids a merge folded into *survivor* and then dropped from the list.Both the physical ``_row_id`` (``_absorbed_row_ids``, consumed by the in-place archive) and the durable@@ -474,7 +474,10 @@ def _remember_absorbed_row(survivor: Dict[str, Any], dropped: Dict[str, Any]) ->for row_id in ids:if row_id not in absorbed:absorbed.append(row_id)- record_absorbed_message(survivor, dropped)+ # The uid witness claims the dropped dict's TEXT lives on in the survivor: only a fold earns it. A+ # superseded row (``folded=False``) is retired like any absorbed row but its content is discarded.+ if folded:+ record_absorbed_message(survivor, dropped)def _merge_consecutive_assistants(messages: List[Dict]) -> Tuple[List[Dict], int]:@@ -490,7 +493,7 @@ def _merge_consecutive_assistants(messages: List[Dict]) -> Tuple[List[Dict], int):# A provisional verification candidate is superseded, not unioned.if prev.get("finish_reason") in {"verification_required", "verify_hook_continue"}:- _remember_absorbed_row(msg, prev)+ _remember_absorbed_row(msg, prev, folded=False)collapsed[-1] = msgelse:_merge_assistant_into(prev, msg)diff --git a/tests/agent/test_context_engine_message_uid.py b/tests/agent/test_context_engine_message_uid.pyindex 155733c2b61..1eb3b6da843 100644--- a/tests/agent/test_context_engine_message_uid.py+++ b/tests/agent/test_context_engine_message_uid.py@@ -287,6 +287,23 @@ def test_the_live_list_walk_binds_a_result_to_the_nearest_call_that_names_it():assert tool_call_uid_from_history([call("1" * UID_LEN), {"role": "user", "content": "q"}, result], 2) is None+def test_a_superseded_verification_candidate_is_not_a_witness_constituent():+ """Alternation repair DISCARDS a provisional verification candidate in favour of the final answer; its+ row is retired like an absorbed row, but its uid is not a constituent of anything."""+ from agent.agent_runtime_helpers import _merge_consecutive_assistants++ candidate = {"role": "assistant", "content": "provisional", "finish_reason": "verification_required",+ "message_uid": "p" * UID_LEN, "_row_id": 7}+ final = {"role": "assistant", "content": "verified answer", "message_uid": "f" * UID_LEN}++ merged, repairs = _merge_consecutive_assistants([candidate, final])++ assert repairs == 1 and merged == [final]+ assert final["message_uid"] == "f" * UID_LEN+ assert "_absorbed_message_uids" not in final+ assert final["_absorbed_row_ids"] == [7]++def test_assistant_merge_keeps_the_absorbed_turns_tool_call_uids():from agent.agent_runtime_helpers import _merge_consecutive_assistantsdiff --git a/website/docs/developer-guide/context-engine-plugin.md b/website/docs/developer-guide/context-engine-plugin.mdindex bbd90b1aae8..ec16fa13fb4 100644--- a/website/docs/developer-guide/context-engine-plugin.md+++ b/website/docs/developer-guide/context-engine-plugin.md@@ -171,7 +171,9 @@ What the host guarantees:restored with it, so after a restart an engine still sees that `A\n\nB` isthe host's fold of `A` and `B` rather than a new message. Merges made whilerestoring a history (`repair_alternation=True`) record the witness the same- way.+ way. A row the host discards rather than folds (a provisional verification+ candidate superseded by the final answer) is not recorded: the witness+ names text that lives on in the composite, nothing else.- **Engine-authored rows keep the uid the engine sets.** If your `compress()`output pre-stamps `message_uid` on a summary carrier (or any row it emits),the host writes that value through the commit, both in place and on