Skip to content

fix(gateway): in-place compaction no longer wipes the archived transcript - #61716

Merged
teknium1 merged 3 commits into
mainfrom
salvage/61209-hygiene-inplace
Jul 10, 2026
Merged

fix(gateway): in-place compaction no longer wipes the archived transcript#61716
teknium1 merged 3 commits into
mainfrom
salvage/61209-hygiene-inplace

Conversation

@teknium1

@teknium1 teknium1 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Gateway in-place compaction no longer destroys the transcript it just archived — the redundant destructive rewrite_transcript() after archive_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 /compress handler then both called rewrite_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 /compress handler (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 asserting rewrite_transcript is NOT called on the in-place path (our follow-up commit)

Validation

Before After
In-place compaction archived rows DELETEd by rewrite archived rows preserved
Targeted tests 2 pinned buggy behavior 36/36 green across 5 compression test files
E2E (real SessionDB) 6 archived rows wiped by replace_messages default premise + fix confirmed

Infographic

infographic

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 10, 2026
AlexFucuson9 and others added 3 commits July 9, 2026 17:52
…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
teknium1 force-pushed the salvage/61209-hygiene-inplace branch from 2d5e684 to 8b0ee36 Compare July 10, 2026 00:54
@teknium1
teknium1 merged commit 79f1274 into main Jul 10, 2026
31 checks passed
@teknium1
teknium1 deleted the salvage/61209-hygiene-inplace branch July 10, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway session-hygiene auto-compress destructively DELETEs transcript instead of soft-archiving (silent data loss)

3 participants