mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-12 08:51:53 +00:00
fix: in-memory transcript blocks empty-session prune
CI caught tests/cli/test_cli_new_session.py asserting that /new keeps the old session row when conversation history exists in memory. The live transcript is authoritative: a session whose messages haven't flushed to the DB yet (or whose flush failed) must not be pruned. Guard _discard_session_if_empty on self.conversation_history and pin the behavior with a test.
This commit is contained in:
parent
e96ca1a0d3
commit
4490c7cf8d
2 changed files with 19 additions and 0 deletions
6
cli.py
6
cli.py
|
|
@ -5833,6 +5833,12 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
|
|||
"""
|
||||
if not self._session_db or not session_id:
|
||||
return False
|
||||
# In-memory transcript is authoritative: if this CLI object holds
|
||||
# conversation messages (flushed to the DB or not), the session is
|
||||
# not empty. Protects against pruning a real conversation whose DB
|
||||
# flush failed or hasn't happened yet.
|
||||
if getattr(self, "conversation_history", None):
|
||||
return False
|
||||
try:
|
||||
from hermes_constants import get_hermes_home as _ghh
|
||||
return self._session_db.delete_session_if_empty(
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ class TestCLIDiscardSessionIfEmpty:
|
|||
|
||||
cli = HermesCLI.__new__(HermesCLI)
|
||||
cli._session_db = db
|
||||
cli.conversation_history = []
|
||||
return cli
|
||||
|
||||
def test_discards_empty(self, db):
|
||||
|
|
@ -146,3 +147,15 @@ class TestCLIDiscardSessionIfEmpty:
|
|||
|
||||
cli = self._make_cli(Boom())
|
||||
assert cli._discard_session_if_empty("x") is False
|
||||
|
||||
def test_in_memory_history_blocks_prune(self, db):
|
||||
"""The live transcript is authoritative: even if the DB row has no
|
||||
flushed messages yet, a CLI holding conversation history must not
|
||||
prune the session (covers flush-failed / not-yet-flushed turns)."""
|
||||
db.create_session(session_id="unflushed", source="cli", model="test")
|
||||
db.end_session("unflushed", "new_session")
|
||||
|
||||
cli = self._make_cli(db)
|
||||
cli.conversation_history = [{"role": "user", "content": "hello"}]
|
||||
assert cli._discard_session_if_empty("unflushed") is False
|
||||
assert db.get_session("unflushed") is not None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue