fix(gateway): in-place compaction no longer wipes the archived transcript - #61716
Merged
Conversation
…anscript When gateway session-hygiene auto-compression fires with in-place compaction, the flow was: 1. _compress_context() calls archive_and_compact() — soft-archives old rows (active=0, compacted=1) and inserts compacted messages as the new active set. This is the non-destructive, durable path. 2. The hygiene handler then called rewrite_transcript() — which calls replace_messages(active_only=False) — DELETEing ALL rows including the just-archived turns. Silent permanent data loss (#61145). The interactive /compress handler had the same bug. Fix: only call rewrite_transcript() when session rotation produced a new session id (legacy path). When in-place compaction succeeded, skip the rewrite — archive_and_compact() already handled persistence. Closes #61145.
Flip the two tests that pinned the old buggy behavior (rewrite_transcript called after in-place compaction) to assert the corrected invariant from #61145: archive_and_compact() already persisted, so the handler must NOT call rewrite_transcript — its replace_messages(active_only=False) would DELETE the just-archived rows. E2E-verified against a real SessionDB: 6 soft-archived rows are wiped by replace_messages' default path, confirming the data-loss premise.
His noreply email has no numeric-id+ prefix, so the attribution CI's auto-resolve pattern doesn't match it.
teknium1
force-pushed
the
salvage/61209-hygiene-inplace
branch
from
July 10, 2026 00:54
2d5e684 to
8b0ee36
Compare
2 tasks
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Gateway in-place compaction no longer destroys the transcript it just archived — the redundant destructive
rewrite_transcript()afterarchive_and_compact()is skipped. Closes #61145.Root cause: in-place compaction (default since #52658) soft-archives the previous active rows and inserts the compacted set inside
_compress_context(). The hygiene handler and the/compresshandler then both calledrewrite_transcript()→replace_messages(active_only=False), which the docstring itself calls "DESTRUCTIVE by default: every row for the session is DELETEd" — wiping the just-archived turns. Silent, permanent data loss on every routine compaction.Salvages PR #61209 by @AlexFucuson9 (cherry-picked, authorship preserved).
Changes
gateway/run.py: hygiene path rewrites only when rotation produced a new session id; in-place success re-baselines counters without touching the DB (contributor commit)gateway/slash_commands.py: same guard for the interactive/compresshandler (contributor commit)tests/gateway/test_compress_command.py,tests/gateway/test_session_hygiene.py: flipped the two tests that pinned the old destructive behavior into regression tests assertingrewrite_transcriptis NOT called on the in-place path (our follow-up commit)Validation
replace_messagesdefaultInfographic