Skip to content

fix(gateway): only rewrite transcript when session rotation happened (#44794) - #44867

Closed
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-44794
Closed

fix(gateway): only rewrite transcript when session rotation happened (#44794)#44867
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-44794

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Fixes #44794. When _session_db is None or session rotation fails, rewrite_transcript() was called unconditionally on the original session, overwriting the full conversation history with only the compressed summary. This fix moves rewrite_transcript() inside the rotation check so it only executes when a new session was actually created.

@liuhao1024

Copy link
Copy Markdown
Contributor

Bug: rewrite_transcript called unconditionally — overwrites conversation history when no rotation happens

The rewrite_transcript(new_session_id, compressed) call at line ~2499 is outside the if new_session_id != session_entry.session_id: block. When rotation does NOT happen (e.g., _session_db is None or the session IDs match), the code still overwrites the current session's transcript with the compressed content — destroying the full conversation history.

The current code on main:

if new_session_id != session_entry.session_id:
    session_entry.session_id = new_session_id
    self.session_store._save()
    self._sync_telegram_topic_binding(...)

# This runs regardless of whether rotation happened
self.session_store.rewrite_transcript(new_session_id, compressed)

When new_session_id == session_entry.session_id (no rotation), rewrite_transcript overwrites the existing session's transcript with compressed content. This means a /compress command that fails to rotate (e.g., no _session_db) silently truncates the conversation to the compressed subset.

The fix in this PR correctly indents rewrite_transcript inside the if block so it only runs when a new session was actually created.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix. Adds guard to only call rewrite_transcript() when session rotation actually happened, preventing unconditional overwrite of original session with compressed content. Good inline comments explaining the bug (#44794) and why the guard is needed. No issues found.

@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 duplicate This issue or pull request already exists labels Jun 12, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #35905 (earliest open, same approach) — guard rewrite_transcript() behind the session-rotation check so compression doesn't overwrite full history when rotation fails / _session_db is None. Same rewrite-transcript-on-rotation family as #39704 / #40112 / #41000. This PR targets the manual /compress path (#44794).

@teknium1

Copy link
Copy Markdown
Contributor

Closing rather than merging this one. The current /compress path intentionally rewrites the active transcript with the compressed messages when compression does not rotate to a child session; that is the fallback that makes manual compression persist when there is no SessionDB-backed child to write to.

Moving rewrite_transcript() inside the rotation-only branch would make /compress report success while leaving the active transcript uncompressed on that fallback path. The safer fix for the broader compression-session-sync issue landed separately in PR #45529:
#45529

Thanks for chasing the history-loss angle here.

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 duplicate This issue or pull request already exists P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/compress deletes original messages from state.db when session rotation fails

5 participants