fix(gateway): preserve archived compaction history on /retry and yuanbao recall - #80913
Merged
kshitijk4poor merged 3 commits intoAug 7, 2026
Merged
Conversation
/retry truncates the live transcript to before the last user message and persists it via SessionStore.rewrite_transcript, which calls replace_messages() with the default active_only=False. That DELETEs every row for the session, including the soft-archived active=0/compacted=1 rows that in-place compaction keeps on disk (NousResearch#38763), so any /retry after a compaction permanently wiped the archived history. NousResearch#57803 named this call site as a residual gap after its global-default approach was rejected; the TUI sibling was fixed in NousResearch#80195. The handler now probes has_archived_messages() (new SessionStore wrapper, auto-exposed through AsyncSessionStore) and passes active_only=True when archives exist, so only the live rows are replaced. rewrite_transcript gains an active_only parameter that defaults to False, keeping the destructive semantics yuanbao recall redaction depends on. Also corrects the rewrite_transcript docstring, which still listed /undo as a caller even though /undo soft-archives via rewind_session. The regression test drives _handle_retry_command against a real SessionStore and SessionDB seeded with archived compaction rows and asserts the archives survive.
Sibling-site fix for NousResearch#80216: yuanbao recall redaction also calls rewrite_transcript() and was subject to the same archived-history data loss when active_only defaulted to False. Pass active_only=True at both yuanbao call sites — load_transcript only returns active rows, so the redacted content is in the active set and the archived pre-compaction history should survive the rewrite. Also drops the stale 'callers that mean to purge (e.g. yuanbao recall redaction) keep the default' note from the rewrite_transcript docstring — no caller intentionally purges archived rows.
This was referenced Aug 7, 2026
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
After in-place compaction,
rewrite_transcript()calledreplace_messages()with the defaultactive_only=False, DELETEing every row for the session — including soft-archived (active=0) pre-compaction history thatarchive_and_compact()deliberately keeps on disk (#38763). After any/retryor yuanbao recall redaction on a compacted session, the archived history was gone permanently.Root cause
gateway/session.pyrewrite_transcriptcalledreplace_messages(session_id, messages)withactive_onlydefaulting toFalse. The DELETE had noAND active = 1clause, so it took the archived rows too. Same data-loss class as #61145; #57803 named this call site as a residual gap after rejecting the auto-detect-inside-rewrite_transcript approach in favor of per-caller guards.Changes
gateway/session.py:rewrite_transcriptgains anactive_onlyparameter (defaultFalse, forwarded toreplace_messages). Docstring updated to remove stale/undoreference and document theactive_onlycontract.gateway/slash_commands.py:/retrypassesactive_only=Trueunconditionally — no probe needed (when no archived rows exist,AND active = 1matches the same rows as no clause). Avoids TOCTOU race and fail-open exception path that a probe would introduce.gateway/platforms/yuanbao.py: both yuanbao recall redaction call sites now passactive_only=True.load_transcriptonly returns active rows, so the redacted content is in the active set and archived pre-compaction history should survive the rewrite.tests/gateway/test_retry_replacement.py: new regression test seeds archived compaction rows, simulates a probe failure, and asserts archives survive/retryand the live set reflects the truncation + retried exchange.Attribution
Cherry-picked from PR #80218 by @Adolanium (original fix + regression test) and @poisdahl (fail-safe follow-up). Sibling-site fix (yuanbao callers + docstring cleanup) added on top.
Closes #80216. Closes #80218. Supersedes #80695.
Test plan
tests/gateway/test_retry_replacement.py tests/gateway/test_retry_response.py tests/gateway/test_session.py tests/gateway/test_compress_command.py tests/gateway/test_session_hygiene.py— 87 passed, 0 failedtests/gateway/ -k 'yuanbao'— 16 passed, 1 skippedrewrite_transcript(active_only=True)preserves all 4 archived rows;active_only=Falsedestroys them (confirms the bug)