Skip to content

The agent that grows with you

fix(sessions): an assistant fold ignores a non-dict uid map on the surviving turn too

kshitijk4poor0cabdf3f64b8
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py
index 205226bddfc..0db6fb0c829 100644
--- a/agent/agent_runtime_helpers.py
+++ b/agent/agent_runtime_helpers.py
@@ -395,7 +395,8 @@ def _merge_assistant_into(prev: Dict, msg: Dict) -> bool:
# The absorbed turn's calls keep the per-occurrence ids they were persisted with.
if isinstance(extra := msg.get(TOOL_CALL_UIDS), dict) and extra:
prev[TOOL_CALL_UIDS] = merge_tool_call_uids(
- per_occurrence_tool_call_uids(prev.get(TOOL_CALL_UIDS) or {}, prev_calls),
+ per_occurrence_tool_call_uids(
+ own if isinstance(own := prev.get(TOOL_CALL_UIDS), dict) else {}, prev_calls),
per_occurrence_tool_call_uids(extra, new_calls))
calls_changed = True
elif prev_calls:
diff --git a/tests/agent/test_context_engine_message_uid.py b/tests/agent/test_context_engine_message_uid.py
index 0d781e96ef4..05625676ff6 100644
--- a/tests/agent/test_context_engine_message_uid.py
+++ b/tests/agent/test_context_engine_message_uid.py
@@ -369,6 +369,23 @@ def test_an_assistant_fold_that_discards_the_later_text_is_no_witness(kept, drop
assert survivor["_absorbed_row_ids"] == [9]
+def test_a_fold_ignores_a_non_dict_uid_map_on_either_turn():
+ """A plugin-built dict can carry a malformed map; the fold keeps the well-formed side instead of raising."""
+ from agent.agent_runtime_helpers import _merge_assistant_into
+
+ def turn(call_id, uids):
+ return {"role": "assistant", "content": "",
+ "tool_calls": [{"id": call_id, "type": "function", "function": {"name": "t", "arguments": "{}"}}],
+ "_tool_call_uids": uids}
+
+ prev, new = turn("X", "junk"), turn("Y", {"Y": "b" * 32})
+ _merge_assistant_into(prev, new)
+ assert prev["_tool_call_uids"] == {"Y": "b" * 32}
+ prev, new = turn("X", {"X": "a" * 32}), turn("Y", ["junk"])
+ _merge_assistant_into(prev, new)
+ assert prev["_tool_call_uids"] == {"X": "a" * 32}
+
+
def test_a_select_context_selection_is_stripped_before_the_provider():
"""The request copy is stripped BEFORE ``select_context``; an engine that hands back the
``conversation_messages`` clones must not put the ids back on the wire."""