fix(gateway): preserve transcript on /compress and hygiene auto-compress - #21313
Closed
SandroHub013 wants to merge 1 commit into
Closed
fix(gateway): preserve transcript on /compress and hygiene auto-compress#21313SandroHub013 wants to merge 1 commit into
SandroHub013 wants to merge 1 commit into
Conversation
Closes NousResearch#21301. Both `_handle_compress_command` (manual `/compress`) and the Gateway Session Hygiene auto-compress path build a temporary `AIAgent` to run context compression. Both omitted `session_db=self._session_db`, so the tmp agent's `_session_db` was None and `_compress_context()`'s session-rotate block (`if self._session_db:`) silently no-op'd. Downstream `rewrite_transcript(session_entry.session_id, compressed)` then overwrote the original session's transcript with the compressed list, destroying the searchable history that commits 1544638 and cd2e180 were specifically introduced to protect. Same bug class as PR NousResearch#20021 (ACP adapter) and PR NousResearch#4802 (API server adapter), both of which fixed identical missing-`session_db` omissions in their respective tmp-agent constructors. Add `session_db=self._session_db` to both constructors. With this, the session-rotate block runs, the original session is closed with `end_reason='compression'`, and the new continuation session gets a fresh session_id with `parent_session_id` linking back. Regression test asserts both constructor call sites carry the kwarg via static source inspection — avoids the SQLite + AIAgent wiring needed for a full integration test, which would be heavier than the bug.
13 tasks
Contributor
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.
Closes #21301.
Problem
Manual
/compressand Gateway Session Hygiene auto-compress both physically destroy the original transcript. Reproduction (per the issue):/compress.state.dbshows the original session'smessage_countcollapsed to the compressed count,end_reasonis NULL,parent_session_idis NULL, no continuation session was created.Documented behavior (sessions.md "Auto-Lineage on Compression") says the original should be closed with
end_reason='compression'and a new continuation session should carryparent_session_idpointing back.Root cause
Both code paths build a temporary
AIAgentfor the compression run:_handle_compress_commandatgateway/run.py:9445(tmp_agent = AIAgent(...))gateway/run.py:6218(_hyg_agent = AIAgent(...))Neither passes
session_db=. That makestmp_agent._session_db = None, and_compress_context()'s session-rotate block is guarded byif self._session_db:(run_agent.py:9048), so it silently no-ops.tmp_agent.session_idnever rotates.The downstream safeguard added in 1544638 / cd2e180:
assumes the rotate already happened. With
_session_db is Noneit didn't, sonew_session_id == session_entry.session_idandrewrite_transcriptoverwrites the original.Fix
Add
session_db=self._session_dbto both constructors:_hyg_agent = AIAgent( **_hyg_runtime, model=_hyg_model, max_iterations=4, quiet_mode=True, skip_memory=True, enabled_toolsets=["memory"], session_id=session_entry.session_id, + session_db=self._session_db, )tmp_agent = AIAgent( **runtime_kwargs, model=model, max_iterations=4, quiet_mode=True, skip_memory=True, enabled_toolsets=["memory"], session_id=session_entry.session_id, + session_db=self._session_db, )Same shape as PR #20021 (ACP adapter) and PR #4802 (API server adapter), which fixed identical omissions in their respective tmp-agent constructors.
Tests
New:
tests/gateway/test_compress_preserves_session_db.py— two static-source assertions that both constructor call sites carrysession_db=self._session_db. Avoids the SQLite + full AIAgent wiring a true integration test would need, which would be heavier than the bug. The reporter has independently validated end-to-end behavior in production (Telegram /compress on a 112-message session — original preserved, new session linked).Out of scope
_compress_context()to no longer requiresession_db. Theif self._session_db:guard exists for non-gateway callers (one-shot CLI, etc.) and removing it would change behavior beyond this fix.