Skip to content

The agent that grows with you

refactor(compression): hoist the commit's helper imports above the in_place split

kshitijk4poorb1cd88a68902
diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py
index f09d07e7b4e..c8064cc6521 100644
--- a/agent/conversation_compression.py
+++ b/agent/conversation_compression.py
@@ -3746,10 +3746,11 @@ def _commit_compaction(
return _CommitOutcome(
compressed=messages, refused_prompt=_refused_sp, commit_started_at=commit_started_at
)
+ from agent.context_compressor import PROACTIVE_PRUNE_REARM_MODEL_CONFIG_KEY, stamp_db_persisted_markers
+ from hermes_cli.partial_compress import rejoin_compressed_head_and_tail
if in_place:
# In-place compaction: same session_id; soft-archive old turns (active=0, still
# searchable) + insert `compressed` atomically; no pre-flush (tail already in).
- from agent.context_compressor import PROACTIVE_PRUNE_REARM_MODEL_CONFIG_KEY, stamp_db_persisted_markers
# Tail rows tagged by compress() are archived as superseded duplicates, not
# compacted=1. Count against the FINAL list — salvage may have dropped rows.
tail_count = sum(1 for m in compressed if id(m) in _tail_tagged_ids)
@@ -3781,7 +3782,6 @@ def _commit_compaction(
# The kept exchanges are durable rows under the watermark, so the archive below covers
# them too. Store them after the head in the same transaction, with the seam the caller
# would build, and count their originals as carried duplicates like compress()'s tail.
- from hermes_cli.partial_compress import rejoin_compressed_head_and_tail
persisted = rejoin_compressed_head_and_tail(compressed, verbatim_tail)
tail_count += len(verbatim_tail)
from agent.conversation_compression_archive import coverage_for_commit
@@ -3829,14 +3829,12 @@ def _commit_compaction(
if verbatim_tail:
# Publish the kept exchanges with the head, as the in-place branch stores them: the
# gateway no longer rewrites a published child, so a head-only handoff loses the tail.
- from hermes_cli.partial_compress import rejoin_compressed_head_and_tail
compressed = rejoin_compressed_head_and_tail(compressed, verbatim_tail)
_publish_rotated_compaction(
agent, messages, compressed, new_system_prompt=new_system_prompt, lease=lease,
old_session_id=old_session_id, compressed_user_turn_outcome=compressed_user_turn_outcome,
)
if verbatim_tail:
- from agent.context_compressor import stamp_db_persisted_markers
stamp_db_persisted_markers(verbatim_tail)
split_status = "rotated_committed"
agent._last_flushed_db_idx = len(compressed)