From 013f9c875092fbc06f78cc8b77b2d8a9ee208284 Mon Sep 17 00:00:00 2001 From: Gille <4317663+helix4u@users.noreply.github.com> Date: Fri, 19 Jun 2026 16:13:19 -0700 Subject: [PATCH] fix(memory): log CLI shutdown hook failures Makes the CLI memory-provider shutdown path observable: log when CLI cleanup calls memory shutdown (with session id + message count), warn instead of swallowing CLI memory-shutdown exceptions, warn on on_session_end failures during agent shutdown, and raise the MemoryManager provider-hook failure log from debug to warning with a traceback. Salvaged from PR #49287 (authored by Gille / @helix4u). --- agent/memory_manager.py | 3 ++- cli.py | 13 +++++++++++-- run_agent.py | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/agent/memory_manager.py b/agent/memory_manager.py index dcd50a2997a..c4baf44fe9a 100644 --- a/agent/memory_manager.py +++ b/agent/memory_manager.py @@ -721,9 +721,10 @@ class MemoryManager: try: provider.on_session_end(messages) except Exception as e: - logger.debug( + logger.warning( "Memory provider '%s' on_session_end failed: %s", provider.name, e, + exc_info=True, ) def on_session_switch( diff --git a/cli.py b/cli.py index 49da337dfd8..794bf65763f 100644 --- a/cli.py +++ b/cli.py @@ -1031,11 +1031,20 @@ def _run_cleanup(*, notify_session_finalize: bool = True): # partially-initialised agents where the attribute is missing. _session_msgs = getattr(_active_agent_ref, '_session_messages', None) if isinstance(_session_msgs, list): + logger.info( + "CLI cleanup calling memory shutdown for session %s with %d message(s)", + getattr(_active_agent_ref, "session_id", None) or "", + len(_session_msgs), + ) _active_agent_ref.shutdown_memory_provider(_session_msgs) else: + logger.info( + "CLI cleanup calling memory shutdown for session %s without session message list", + getattr(_active_agent_ref, "session_id", None) or "", + ) _active_agent_ref.shutdown_memory_provider() - except Exception: - pass + except Exception as e: + logger.warning("CLI cleanup memory shutdown failed: %s", e, exc_info=True) def _should_emit_cleanup_session_finalize(session_id: str | None) -> bool: diff --git a/run_agent.py b/run_agent.py index 167d11c5ced..2c78123829c 100644 --- a/run_agent.py +++ b/run_agent.py @@ -3034,8 +3034,8 @@ class AIAgent: if self._memory_manager: try: self._memory_manager.on_session_end(messages or []) - except Exception: - pass + except Exception as e: + logger.warning("Memory provider on_session_end failed during shutdown: %s", e, exc_info=True) try: self._memory_manager.shutdown_all() except Exception: