9d9d9194d4
archive_and_compact() soft-archives every active row with compacted=1 and then re-inserts compacted_messages as fresh live rows. When the compressor's protected tail rides inside that list verbatim - which is the normal batch-compaction shape ([summary] + tail) - the tail's ORIGINALS end up stored twice per compaction: (active=0, compacted=1) next to their live clones. search_messages() recalls both flags without DISTINCT, so every carried-forward message came back once per compaction (measured up to 4 identical hits) and was mislabeled to users and the agent as archived "summarized away" content. Add an optional tail_count parameter: the last tail_count archived rows are superseded byte-identical duplicates, stamped rewind-style (active=0, compacted=0, hidden from recall) instead of compacted=1. Callers: - batch in-place compaction counts the compressor-tagged tail dicts (_COMPACTION_TAIL_MARKER set by compress() on every carried-forward message); - micro-compaction splices [prefix, marker, suffix] - everything except the single marker row is carried forward, so tail_count=len-1; - proactive tool-result pruning rewrites content in place (not verbatim), keeping the historical archive-everything behavior. Fixes #86366