Skip to main content

compacted_history_shrinks

Function compacted_history_shrinks 

Source
pub fn compacted_history_shrinks(
    original_len: usize,
    compacted_len: usize,
    mode: CompactionMode,
) -> bool
Expand description

Whether a compaction result is worth keeping.

Local compaction always appends framing around the summarized history (a summary message plus the persisted session-memory envelope), so a result whose message count is not strictly smaller than the input grows the conversation instead of compacting it. This happens when the continuity tail already covers the whole history (small, tool-heavy sessions where a handful of user turns anchor dozens of assistant/tool messages): the rebuild keeps every message and adds framing on top (observed as 86 -> 88). Such results must be discarded in favor of the already-compact path so callers never report growth as a successful compaction.

The check is intentionally message-count based: that is the unit surfaced in user-facing progress (86 -> 12) and harness compact_boundary events, so the persisted history must never exceed it.