From 260ae621346882156a5ba6cfcd4641b52a621566 Mon Sep 17 00:00:00 2001 From: Stefan Dimitrov Date: Tue, 21 Apr 2026 18:16:39 -0700 Subject: [PATCH] Invoke session finalize hooks on expiry flush --- gateway/run.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gateway/run.py b/gateway/run.py index 75db1972a..f7d8e8b70 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -2366,6 +2366,17 @@ class GatewayRunner: for key, entry in _expired_entries: try: await self._async_flush_memories(entry.session_id, key) + try: + from hermes_cli.plugins import invoke_hook as _invoke_hook + _parts = key.split(":") + _platform = _parts[2] if len(_parts) > 2 else "" + _invoke_hook( + "on_session_finalize", + session_id=entry.session_id, + platform=_platform, + ) + except Exception: + pass # Shut down memory provider and close tool resources # on the cached agent. Idle agents live in # _agent_cache (not _running_agents), so look there.