mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-18 04:41:56 +00:00
fix(agent): notify context engine on commit_memory_session (#22764)
When session_id rotates (e.g. /new), commit_memory_session was firing
MemoryManager.on_session_end but skipping ContextEngine.on_session_end.
Engines that accumulate per-session state (LCM-style DAGs, summary
stores) leaked that state from the rotated-out session into whatever
continued under the same compressor instance.
Mirror the call shutdown_memory_provider already makes — same
lifecycle moment, same hook contract ("real session boundaries (CLI
exit, /reset, gateway expiry)"). /new is a real boundary for the old
session_id; providers keep their state but the rotated-out session_id
is done.
6 regression tests covering both-hooks-fire, no-memory-manager,
no-context-engine, both failure-tolerant paths.
Closes #22394.
This commit is contained in:
parent
dae94fa652
commit
e90aa7f280
2 changed files with 121 additions and 6 deletions
25
run_agent.py
25
run_agent.py
|
|
@ -5067,12 +5067,25 @@ class AIAgent:
|
|||
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 [])
|
||||
except Exception:
|
||||
pass
|
||||
if self._memory_manager:
|
||||
try:
|
||||
self._memory_manager.on_session_end(messages or [])
|
||||
except Exception:
|
||||
pass
|
||||
# Notify context engine of session end too — same lifecycle moment as
|
||||
# the memory manager's on_session_end. Without this, engines that
|
||||
# accumulate per-session state (DAGs, summaries) leak that state from
|
||||
# the rotated-out session into whatever comes next under the same
|
||||
# compressor instance. Mirrors the call in shutdown_memory_provider().
|
||||
# See issue #22394.
|
||||
if hasattr(self, "context_compressor") and self.context_compressor:
|
||||
try:
|
||||
self.context_compressor.on_session_end(
|
||||
self.session_id or "",
|
||||
messages or [],
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _sync_external_memory_for_turn(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue