The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(compression): pin leading-drop and request-copy row-count contracts
kshitijk4poor0b6bac9a1a4d
diff --git a/tests/agent/test_in_place_merged_user_rows.py b/tests/agent/test_in_place_merged_user_rows.pyindex 12497a9f451..c49f7a8fb61 100644--- a/tests/agent/test_in_place_merged_user_rows.py+++ b/tests/agent/test_in_place_merged_user_rows.py@@ -10,6 +10,8 @@ from types import SimpleNamespaceimport pytest+from agent.conversation_compression_archive import MERGED_DURABLE_ROWS, RETIRED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS+from agent.turn_context import build_api_messagesfrom tests.agent import test_in_place_preflight_rewind as _rewindfrom tests.agent.test_in_place_preflight_rewind import _replies_displayed, _turn@@ -48,6 +50,12 @@ def test_compaction_over_an_unanswered_prompt_keeps_one_copy_of_every_row(sessiocli.conversation_history = db.get_messages_as_conversation("sid", repair_alternation=True)elif surface == "resume": # --resume and the TUI load the same history with row idscli.conversation_history = db.get_resume_conversations("sid")[0]+ # The repair's row counts ride on the live dicts for the commit; the request copy never carries them.+ reload = db.get_messages_as_conversation("sid", repair_alternation=True)+ request, _ = build_api_messages(+ agent, reload, current_turn_user_idx=len(reload) - 1,+ ext_prefetch_cache="", plugin_user_context="", moa_config=None, active_system_prompt="")+ assert not any({MERGED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS, RETIRED_DURABLE_ROWS} & set(m) for m in request)_turn(db, agent, cli, surface, 13, 5_000)_turn(db, agent, cli, surface, 14, 200_000) # real usage over the threshold: the next turn compacts firstdiff --git a/tests/agent/test_message_sequence_repair.py b/tests/agent/test_message_sequence_repair.pyindex 6beae1174c4..42c82b5b8f8 100644--- a/tests/agent/test_message_sequence_repair.py+++ b/tests/agent/test_message_sequence_repair.py@@ -9,6 +9,8 @@ providers (violating role alternation), which retriggered the empty-retryrecovery every turn."""+import pytest+from run_agent import AIAgent@@ -1692,14 +1694,20 @@ def test_repair_decode_of_durable_sentinel_row_does_not_reappend(tmp_path):assert after == ["user", "assistant"], f"flush changed the durable transcript: {before} -> {after}"-def test_repair_records_dropped_unanswered_tool_call_row_on_survivor():+_UNANSWERED_CALL = {"role": "assistant", "content": "", "_row_id": 21,+ "tool_calls": [{"id": "unanswered", "type": "function",+ "function": {"name": "f", "arguments": "{}"}}]}+_STRAY_RESULT = {"role": "tool", "tool_call_id": "orphan", "content": "out", "_row_id": 21}++[email protected]("ahead", [False, True], ids=["behind_survivor", "ahead_of_first_survivor"])[email protected]("dropped", [_UNANSWERED_CALL, _STRAY_RESULT], ids=["unanswered_call", "stray_result"])+def test_repair_records_dropped_tool_row_on_survivor(dropped, ahead):+ """A dropped row is recorded on the survivor before it, or on the first survivor when nothing is kept+ ahead of it (#129162)."""agent = _bare_agent()- messages = [- {"role": "user", "content": "prompt", "_row_id": 20},- {"role": "assistant", "content": "", "_row_id": 21,- "tool_calls": [{"id": "unanswered", "type": "function",- "function": {"name": "f", "arguments": "{}"}}]},- ]+ prompt = {"role": "user", "content": "prompt", "_row_id": 20}+ messages = [dict(dropped), prompt] if ahead else [prompt, dict(dropped)]repairs = AIAgent._repair_message_sequence(agent, messages)