The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): replace duplicate in-flight task replay
Yuan Lia14e929ec0e9
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 2aa5c8f2af5..2daecdf9411 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -5039,6 +5039,22 @@ Write only the summary body. Do not include any preamble or prefix.""")drop_stale_api_content(replay)+ # The replay is a replacement for the in-flight row, not an additional+ # occurrence of it. When the original survived in the protected head,+ # retaining it gives the durable transcript two active rows with the+ # same message_uid and renders the request twice after reload.+ replay_uid = replay.get("message_uid")+ if isinstance(replay_uid, str) and replay_uid:+ compressed[:] = [+ msg+ for msg in compressed+ if not (+ msg is not carrier+ and msg.get("role") == "user"+ and msg.get("message_uid") == replay_uid+ )+ ]+if last_visible_role == "user":# Alternation is judged on template-visible rows only (tool_calls /# tool rows are exempt), so a user-pinned summary followed by adiff --git a/tests/agent/test_cron_inflight_prompt_reappend.py b/tests/agent/test_cron_inflight_prompt_reappend.pyindex e5cea81fbde..a258e37b67f 100644--- a/tests/agent/test_cron_inflight_prompt_reappend.py+++ b/tests/agent/test_cron_inflight_prompt_reappend.py@@ -360,3 +360,23 @@ def test_flagged_scaffolding_row_is_never_the_inflight_task():found = ContextCompressor._find_inflight_user_task(msgs)assert found is not Noneassert JOB_SENTINEL in str(found.get("content"))+++def test_replay_replaces_surviving_user_row_with_same_message_uid():+ """A protected copy of the in-flight request must not remain active beside its replay."""+ from agent.context_compressor import _INFLIGHT_TASK_REPLAY_HEADER, COMPRESSED_SUMMARY_METADATA_KEY++ uid = "request-uid"+ carrier = {+ "role": "assistant",+ "content": SUMMARY_PREFIX + "\n## Summary\nran steps.\n\n" + _SUMMARY_END_MARKER,+ COMPRESSED_SUMMARY_METADATA_KEY: True,+ }+ original = {"role": "user", "content": JOB_SENTINEL, "message_uid": uid}+ out = _make_compressor()._reappend_inflight_user_task(+ [original, carrier], {**original}+ )++ matching = [m for m in out if m.get("message_uid") == uid]+ assert len(matching) == 1+ assert _INFLIGHT_TASK_REPLAY_HEADER in str(matching[0].get("content"))