From 141e9c17f531d04edc6032493ccb566b8639ad12 Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 25 May 2026 10:59:30 -0400 Subject: [PATCH] fix: patch SessionDB methods for session_search user_id compat --- __init__.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/__init__.py b/__init__.py index ef497ea..abd3037 100644 --- a/__init__.py +++ b/__init__.py @@ -237,6 +237,56 @@ def _apply_honcho_patch(): logger.warning("identity: failed to patch Honcho init: %s", exc) +# ── SessionDB patch (version compat: user_id kwarg) ────────────────────── + +_session_db_patched = False + + +def _patch_session_db() -> None: + """Monkey-patch SessionDB methods to accept (and ignore) the ``user_id`` + kwarg that the built-in ``session_search`` tool passes but the upstream + backend no longer supports. Same zero-fork pattern as the Honcho patch.""" + global _session_db_patched + if _session_db_patched: + return + + try: + from hermes_state import SessionDB + except ImportError as exc: + logger.warning("identity: hermes_state not importable (%s), skipping SessionDB patch", exc) + return + except Exception as exc: + logger.warning("identity: failed to import SessionDB: %s", exc) + return + + # search_messages + orig_search = SessionDB.search_messages + if orig_search is None: + logger.warning("identity: SessionDB.search_messages not found") + return + + def _patched_search(self, *args, **kwargs): + kwargs.pop("user_id", None) + return orig_search(self, *args, **kwargs) + + SessionDB.search_messages = _patched_search + + # list_sessions_rich + orig_list = SessionDB.list_sessions_rich + if orig_list is None: + logger.warning("identity: SessionDB.list_sessions_rich not found") + return + + def _patched_list(self, *args, **kwargs): + kwargs.pop("user_id", None) + return orig_list(self, *args, **kwargs) + + SessionDB.list_sessions_rich = _patched_list + + _session_db_patched = True + logger.info("identity: patched SessionDB methods ✓") + + # ── Hooks ─────────────────────────────────────────────────────────────────── @@ -382,6 +432,7 @@ def register(ctx: Any) -> None: # Apply the runtime monkey-patch to Honcho's session init # NO files modified, NO fork needed — pure Python at import time _apply_honcho_patch() + _patch_session_db() # Register hooks ctx.register_hook("pre_gateway_dispatch", _pre_gateway_dispatch)