Skip to content

The agent that grows with you

refactor(compression): name the repair row stamps by their constants

kshitijk4poor05f3f25d67dc
diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py
index 4e10eda0dc8..2abee76f4fb 100644
--- a/agent/conversation_compression.py
+++ b/agent/conversation_compression.py
@@ -3767,15 +3767,15 @@ def _commit_compaction(
1 for m in messages[max(_turn_idx, len(messages) - tail_count):]
if isinstance(m, dict) and not m.get(_DB_PERSISTED_MARKER)
and not isinstance(m.get("_row_id"), int))
- # An alternation repair folds a durable user;user pair into one dict, which then stands
- # for every row it absorbed: counted once, the oldest carried original stays compacted=1
- # beside its live copy and is recalled twice. Only rows still active: a live list keeps
- # the ids after an earlier compaction archived them.
+ # A tail dict stands for every row a repair retired into it (merged users, dropped orphan
+ # tool rows): counted once, the oldest carried original stays compacted=1 beside its live
+ # copy and is recalled twice. Only rows still active: a live list keeps the ids after an
+ # earlier compaction archived them.
+ from agent.conversation_compression_archive import ABSORBED_ROW_IDS, _positive_id
tail_count += len({
r for m in _tail_held if isinstance(m, dict)
- for r in m.get("_absorbed_row_ids") or ()
- if type(r) is int and r > 0
- and agent._session_db.get_message_role(agent.session_id, r) is not None})
+ for r in map(_positive_id, m.get(ABSORBED_ROW_IDS) or ())
+ if r is not None and agent._session_db.get_message_role(agent.session_id, r) is not None})
persisted = compressed
if verbatim_tail:
# The kept exchanges are durable rows under the watermark, so the archive below covers
diff --git a/gateway/run.py b/gateway/run.py
index 743e9a285e1..73c0e7ed390 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -1159,7 +1159,10 @@ def _build_replay_entry(
# A merged user dict lost that stamp; this one is what ties it to its durable rows at compaction.
# The other counts the rows the repair dropped behind a dict or folded into an assistant turn,
# which this view cannot name either; the last names them for the commit.
- for stamp in ("_merged_durable_rows", "_unnamed_durable_rows", "_retired_durable_rows"):
+ from agent.conversation_compression_archive import (
+ MERGED_DURABLE_ROWS, RETIRED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS)
+
+ for stamp in (MERGED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS, RETIRED_DURABLE_ROWS):
if msg.get(stamp):
entry[stamp] = msg[stamp]
return entry
diff --git a/tests/agent/test_message_sequence_repair.py b/tests/agent/test_message_sequence_repair.py
index 2a1e24fcfad..6beae1174c4 100644
--- a/tests/agent/test_message_sequence_repair.py
+++ b/tests/agent/test_message_sequence_repair.py
@@ -1703,6 +1703,6 @@ def test_repair_records_dropped_unanswered_tool_call_row_on_survivor():
repairs = AIAgent._repair_message_sequence(agent, messages)
- assert repairs >= 1
+ assert repairs == 1
assert len(messages) == 1
assert messages[0]["_absorbed_row_ids"] == [21]