Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions agent/conversation_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,22 @@ def _release_lock() -> None:
agent._last_flushed_db_idx = 0
except Exception as e:
logger.warning("Session DB compression split failed — new session will NOT be indexed: %s", e)
else:
# _session_db is None — still rotate the session_id so the caller
# (gateway hygiene) can distinguish old vs new transcripts and
# avoid overwriting the original session's messages.
old_session_id = agent.session_id
agent.session_id = f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:6]}"
try:
from gateway.session_context import set_current_session_id

set_current_session_id(agent.session_id)
except Exception:
os.environ["HERMES_SESSION_ID"] = agent.session_id
logger.info(
"Session hygiene: rotated session_id %s → %s (no session DB)",
old_session_id, agent.session_id,
)

# Notify the context engine that the session_id rotated because of
# compression (not a fresh /new). Plugin engines (e.g. hermes-lcm) use
Expand Down
17 changes: 13 additions & 4 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9273,10 +9273,19 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str, run_g
source, session_entry,
reason="hygiene-compression",
)

self.session_store.rewrite_transcript(
session_entry.session_id, _compressed
)
self.session_store.rewrite_transcript(
session_entry.session_id, _compressed
)
else:
# _session_db was None so no session rotation
# occurred. Do NOT overwrite the original
# transcript — the compressed messages are
# used in-memory only for this turn.
logger.info(
"Session hygiene: compression applied "
"in-memory (no session DB — original "
"transcript preserved)"
)
# Reset stored token count — transcript was rewritten
session_entry.last_prompt_tokens = 0
history = _compressed
Expand Down
Loading