From 8eaaa5021c098544044cae3dd546f0a011104c1a Mon Sep 17 00:00:00 2001 From: kshitij Date: Mon, 27 Jul 2026 18:51:25 +0500 Subject: [PATCH] fix(compression): update _pre_msg_count after durable adoption Update _pre_msg_count after adopting the durable transcript so the post-compression log reflects the correct pre-adoption message count. Also use the existing _live_child_id() helper in the updated test instead of hand-rolled child-id extraction. Follow-up to #72631. --- agent/conversation_compression.py | 1 + contributors/emails/kshitijkapoor0611@gmail.com | 1 + tests/agent/test_compression_concurrent_fork.py | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 contributors/emails/kshitijkapoor0611@gmail.com diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py index 09df0c66c4d05..0f56f9a92c434 100644 --- a/agent/conversation_compression.py +++ b/agent/conversation_compression.py @@ -1737,6 +1737,7 @@ def compress_context( len(durable_parent), ) messages = durable_parent + _pre_msg_count = len(messages) # Token estimate was for the stale snapshot; clear it so # the compressor re-derives from the adopted transcript # instead of under-counting the newly visible rows. diff --git a/contributors/emails/kshitijkapoor0611@gmail.com b/contributors/emails/kshitijkapoor0611@gmail.com new file mode 100644 index 0000000000000..c7510483c049e --- /dev/null +++ b/contributors/emails/kshitijkapoor0611@gmail.com @@ -0,0 +1 @@ +kshitijk4poor diff --git a/tests/agent/test_compression_concurrent_fork.py b/tests/agent/test_compression_concurrent_fork.py index bc20dfcb7afa0..6e0360c515757 100644 --- a/tests/agent/test_compression_concurrent_fork.py +++ b/tests/agent/test_compression_concurrent_fork.py @@ -377,9 +377,8 @@ def test_durable_message_committed_before_lease_is_adopted( assert returned is not stale_snapshot assert returned[0]["content"] == "[CONTEXT COMPACTION] summary" assert agent.session_id != parent_sid - child = db.find_live_compression_child(parent_sid) - assert child is not None - child_id = child["id"] if isinstance(child, dict) else child + child_id = _live_child_id(db, parent_sid) + assert child_id is not None assert child_id == agent.session_id def test_skipped_compression_returns_messages_unchanged(tmp_path: Path) -> None: