refactor(memory): drop on_session_reset — commit-only is enough

OV transparently handles message history across /new and /compress: old
messages stay in the same session and extraction is idempotent, so there's
no need to rebind providers to a new session_id. The only thing the
session boundary actually needs is to trigger extraction.

- MemoryProvider / MemoryManager: remove on_session_reset hook
- OpenViking: remove on_session_reset override (nothing to do)
- AIAgent: replace rotate_memory_session with commit_memory_session
  (just calls on_session_end, no rebind)
- cli.py / run_agent.py: single commit_memory_session call at the
  session boundary before session_id rotates
- tests: replace on_session_reset coverage with routing tests for
  MemoryManager.on_session_end

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
zhiheng.liu 2026-04-16 00:38:19 +08:00 committed by Teknium
parent 8275fa597a
commit 7cb06e3bb3
6 changed files with 30 additions and 156 deletions

10
cli.py
View file

@ -4095,12 +4095,13 @@ class HermesCLI:
def new_session(self, silent=False):
"""Start a fresh session with a new session ID and cleared agent state."""
old_history = self.conversation_history
if self.agent and old_history:
if self.agent and self.conversation_history:
try:
self.agent.flush_memories(old_history)
self.agent.flush_memories(self.conversation_history)
except (Exception, KeyboardInterrupt):
pass
# Trigger memory extraction on the old session before session_id rotates.
self.agent.commit_memory_session(self.conversation_history)
self._notify_session_boundary("on_session_finalize")
elif self.agent:
# First session or empty history — still finalize the old session
@ -4149,9 +4150,6 @@ class HermesCLI:
)
except Exception:
pass
# Commit the old session and rebind memory providers to the
# new session_id so subsequent turns are tracked correctly.
self.agent.rotate_memory_session(self.session_id, old_history)
self._notify_session_boundary("on_session_reset")
if not silent: