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).
This commit is contained in:
Gille 2026-06-19 16:13:19 -07:00 committed by Teknium
parent c1a0b6a5f1
commit 013f9c8750
3 changed files with 15 additions and 5 deletions

13
cli.py
View file

@ -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 "<unknown>",
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 "<unknown>",
)
_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: