From 3cad3c6db8b84598ee70fd111b73cb0443e689af Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 15 Sep 2026 11:33:18 +0530 Subject: [PATCH] fix(supermemory): route capture-write logging through _quietly; drop dead default in custom id Two cleanups on the salvaged per-turn capture path (review of #109359): - _write_turns hand-rolled the try/except/log that the file's own _quietly helper already provides (same exception class, level, exc_info shape); the deleted _ingest path used _quietly for the identical call. Consolidate: add_memory always returns a dict, so a None result is the failure sentinel. - _capture_custom_id's `or 'hermes'` never fires: _sanitize_tag already returns _DEFAULT_CONTAINER_TAG on empty input, and the literal duplicated the constant the helper owns. Verified behavior-preserving (tests green with the fallback artificially restored). --- plugins/memory/supermemory/__init__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/memory/supermemory/__init__.py b/plugins/memory/supermemory/__init__.py index 50e61173d0..3a503653f7 100644 --- a/plugins/memory/supermemory/__init__.py +++ b/plugins/memory/supermemory/__init__.py @@ -241,7 +241,7 @@ def _format_turn(user: str, assistant: str) -> str: def _capture_custom_id(session_id: str, now: Optional[datetime] = None) -> str: """__b<0..5>: same id within a 4h window, so the API appends turns to one document.""" now = now or datetime.now(timezone.utc) - return f"{_sanitize_tag(session_id) or 'hermes'}_{now:%Y-%m-%d}_b{now.hour // _CAPTURE_BUCKET_HOURS}" + return f"{_sanitize_tag(session_id)}_{now:%Y-%m-%d}_b{now.hour // _CAPTURE_BUCKET_HOURS}" def _build_client(api_key: str, config: dict, container_tag: str) -> _SupermemoryClient: @@ -427,12 +427,11 @@ class SupermemoryMemoryProvider(MemoryProvider): now = datetime.now(timezone.utc) content = "\n\n".join(_format_turn(t["user"], t["assistant"]) for t in batch) metadata = {"type": "conversation", "session_id": sid, "timestamp": now.isoformat()} # no sm_capture_mode: Hermes policy - try: - self._client.add_memory(content, metadata=metadata, entity_context=self._entity_context, - custom_id=_capture_custom_id(sid, now)) - except Exception: - logger.log(logging.WARNING if mode != "turn" else logging.DEBUG, "Supermemory capture failed (%s, session=%s, %d turns pending)", - mode, sid, len(batch), exc_info=True) + result = _quietly(lambda: self._client.add_memory(content, metadata=metadata, entity_context=self._entity_context, + custom_id=_capture_custom_id(sid, now)), + "Supermemory capture failed (%s, session=%s, %d turns pending)", mode, sid, len(batch), + level=logging.WARNING if mode != "turn" else logging.DEBUG) + if result is None: # add_memory always returns a dict on success; None = it raised failed += batch self._pending_turns = failed