The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): keep the content key for tool result rows in display dedupe
kshitijk4poor24d05b24d069
diff --git a/hermes_state_identity.py b/hermes_state_identity.pyindex 712ed60e2a5..e40bbc649db 100644--- a/hermes_state_identity.py+++ b/hermes_state_identity.py@@ -97,15 +97,15 @@ def _restore_identity_columns(row: Any, msg: MutableMapping[str, Any]) -> None:def _stable_tool_key(row: Any) -> Optional[Tuple[Any, ...]]:- """Display-dedupe key of a tool-bearing row built from its stable call id(s) instead of the payload a prune- rewrites (#117750: a pruned carried-forward copy must collapse with its durable original). ``None`` when the- row has no complete id set, so the caller keeps the full content key and distinct id-less calls never merge."""- role = row["role"]- if role == "tool" and row["tool_call_id"]:- return (role, None, row["timestamp"], row["tool_call_id"], row["tool_calls"], row["tool_name"])- calls = _json_or(row["tool_calls"] or "[]", [], "Failed to deserialize tool_calls, falling back to []") \- if role == "assistant" else ()+ """Display-dedupe key of a tool-calling assistant row built from its stable call ids instead of the arguments a+ prune rewrites (#117750: a pruned carried-forward copy must collapse with its durable original). ``None`` for+ every other row and for an incomplete id set, so the caller keeps the full content key: a tool RESULT row keeps+ its payload in the key, because folding the archived full output into its pruned stub would drop the original+ from compacted history and transcript exports, and distinct id-less calls never merge."""+ if row["role"] != "assistant":+ return None+ calls = _json_or(row["tool_calls"] or "[]", [], "Failed to deserialize tool_calls, falling back to []")call_ids = tuple(coalesce_tool_call_id(tc) for tc in calls or ())if call_ids and all(call_ids):- return (role, None, row["timestamp"], row["tool_call_id"], call_ids, row["tool_name"])+ return ("assistant", None, row["timestamp"], row["tool_call_id"], call_ids, row["tool_name"])return Nonediff --git a/tests/hermes_state/test_display_dedupe_pruned_tool_payload.py b/tests/hermes_state/test_display_dedupe_pruned_tool_payload.pyindex 7773cbedc13..76d100bb8ac 100644--- a/tests/hermes_state/test_display_dedupe_pruned_tool_payload.py+++ b/tests/hermes_state/test_display_dedupe_pruned_tool_payload.py@@ -1,13 +1,14 @@-"""#117750: a prune rewrite of a carried-forward tool payload must not split the+"""#117750: a prune rewrite of a carried-forward tool call must not split thelogical event into a second display identity.-``_display_dedupe_key`` includes the payload bytes (tool-result content, call-arguments). The proactive prune shortens exactly those bytes on the carried-copies it publishes, so the rewritten copy and its archived durable original+``_display_dedupe_key`` includes the payload bytes (call arguments). The+proactive prune shortens exactly those bytes on the carried copies it+publishes, so the rewritten assistant copy and its archived durable originalused to project as two logical messages — the older one reappearing after a-later answer. Tool rows are now keyed on their stable tool identity; these-tests pin both directions (rewritten copies collapse, genuinely distinct calls-do not merge).+later answer. Tool-calling assistant rows are now keyed on their stable call+ids; tool RESULT rows keep their content key so the archived full output is+never folded into its pruned stub. These tests pin both directions (rewritten+calls collapse without losing the original output, distinct calls do not merge)."""import json@@ -38,7 +39,8 @@ def _seed_session(db, sid):def test_pruned_tool_payload_keeps_one_display_identity(db):"""The issue's synthetic repro: shorten the carried tool args + result, commit,- and the assistant sequence must not gain a duplicate of the earlier message."""+ and the assistant sequence must not gain a duplicate of the earlier message+ while the archived full tool output stays in compacted history and exports."""sid = "pruned-payload"_seed_session(db, sid)history = db.get_messages_as_conversation(sid, include_row_ids=True)@@ -48,8 +50,9 @@ def test_pruned_tool_payload_keeps_one_display_identity(db):visible = db.get_messages_as_conversation(sid, include_row_ids=True, include_compacted=True)assert [m.get("content") for m in visible if m["role"] == "assistant"] == \["Earlier progress", "Later answer"]- tool_rows = [m for m in visible if m["role"] == "tool"]- assert len(tool_rows) == 1+ exported = db.export_session(sid, include_compacted=True)["messages"]+ for messages in (visible, exported):+ assert "R" * 5000 in [m.get("content") for m in messages if m["role"] == "tool"]def test_distinct_idless_assistant_calls_are_not_merged(db):