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:
14
run_agent.py
14
run_agent.py
@@ -3040,15 +3040,15 @@ class AIAgent:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def rotate_memory_session(self, new_session_id: str, messages: list = None) -> None:
|
||||
"""Commit the current memory session, then rebind providers to
|
||||
new_session_id. Keeps HTTP clients/state alive across the transition.
|
||||
Called when session_id rotates (e.g. /new, context compression)."""
|
||||
def commit_memory_session(self, messages: list = None) -> None:
|
||||
"""Trigger end-of-session extraction without tearing providers down.
|
||||
Called when session_id rotates (e.g. /new, context compression);
|
||||
providers keep their state and continue running under the old
|
||||
session_id — they just flush pending extraction now."""
|
||||
if not self._memory_manager:
|
||||
return
|
||||
try:
|
||||
self._memory_manager.on_session_end(messages or [])
|
||||
self._memory_manager.on_session_reset(new_session_id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -6838,11 +6838,11 @@ class AIAgent:
|
||||
try:
|
||||
# Propagate title to the new session with auto-numbering
|
||||
old_title = self._session_db.get_session_title(self.session_id)
|
||||
# Trigger memory extraction on the old session before it rotates.
|
||||
self.commit_memory_session(messages)
|
||||
self._session_db.end_session(self.session_id, "compression")
|
||||
old_session_id = self.session_id
|
||||
self.session_id = f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:6]}"
|
||||
# Commit the old memory session and rebind providers to the new one.
|
||||
self.rotate_memory_session(self.session_id, messages)
|
||||
# Update session_log_file to point to the new session's JSON file
|
||||
self.session_log_file = self.logs_dir / f"session_{self.session_id}.json"
|
||||
self._session_db.create_session(
|
||||
|
||||
Reference in New Issue
Block a user