From 4b9490244692baf4f378bf7f5798825953c74d30 Mon Sep 17 00:00:00 2001 From: kartik-mem0 Date: Thu, 21 May 2026 18:27:47 +0530 Subject: [PATCH] =?UTF-8?q?fix(mem0-plugin):=20review=20fixes=20=E2=80=94?= =?UTF-8?q?=20loop=20guard,=20v3=20response=20format,=20robustness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - on_stop_cursor.sh: add loop_count guard to prevent infinite re-entry - on_stop.sh: drop set -e so stats failure doesn't kill the reminder - _identity.py: fix fallback stub signatures to match production (accept cwd arg) - on_pre_compact.py: add missing infer=False on session_state writes - on_session_start.sh: handle v3 search response format (dict with results key) - Align all plugin versions to 0.2.1 (Claude Code, Codex, Cursor) --- mem0-plugin/.codex-plugin/plugin.json | 2 +- mem0-plugin/.cursor-plugin/plugin.json | 2 +- mem0-plugin/scripts/_identity.py | 6 +++--- mem0-plugin/scripts/on_pre_compact.py | 1 + mem0-plugin/scripts/on_session_start.sh | 13 ++++++++----- mem0-plugin/scripts/on_stop.sh | 3 ++- mem0-plugin/scripts/on_stop_cursor.sh | 8 ++++++++ 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/mem0-plugin/.codex-plugin/plugin.json b/mem0-plugin/.codex-plugin/plugin.json index 89d01c3be..90ce43c45 100644 --- a/mem0-plugin/.codex-plugin/plugin.json +++ b/mem0-plugin/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "mem0", - "version": "0.2.0", + "version": "0.2.1", "description": "Mem0 memory layer for AI applications. Add persistent memory, personalization, and semantic search to Codex workflows using the Mem0 Platform MCP server.", "author": { "name": "Mem0", diff --git a/mem0-plugin/.cursor-plugin/plugin.json b/mem0-plugin/.cursor-plugin/plugin.json index 153b73786..3bb15d67c 100644 --- a/mem0-plugin/.cursor-plugin/plugin.json +++ b/mem0-plugin/.cursor-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "mem0", - "version": "0.2.0", + "version": "0.2.1", "description": "Mem0 memory layer for AI applications. Add persistent memory, personalization, and semantic search using the Mem0 Platform MCP server.", "author": { "name": "Mem0", diff --git a/mem0-plugin/scripts/_identity.py b/mem0-plugin/scripts/_identity.py index 5a0f971ec..16ae7e0ac 100644 --- a/mem0-plugin/scripts/_identity.py +++ b/mem0-plugin/scripts/_identity.py @@ -31,10 +31,10 @@ def resolve_user_id() -> str: try: from _project import resolve_branch, resolve_project_id, save_project_mapping except ImportError: - def resolve_project_id() -> str: - return os.path.basename(os.getcwd()) + def resolve_project_id(cwd: str | None = None) -> str: + return os.path.basename(cwd or os.getcwd()) - def resolve_branch() -> str: + def resolve_branch(cwd: str | None = None) -> str: return "unknown" def save_project_mapping(cwd: str, project_id: str) -> None: diff --git a/mem0-plugin/scripts/on_pre_compact.py b/mem0-plugin/scripts/on_pre_compact.py index 85f50bb55..712e9228c 100755 --- a/mem0-plugin/scripts/on_pre_compact.py +++ b/mem0-plugin/scripts/on_pre_compact.py @@ -186,6 +186,7 @@ def store_memory(api_key: str, content: str, user_id: str, source: str, session_ "app_id": project_id, "metadata": metadata, "expiration_date": expires, + "infer": False, } data = json.dumps(body).encode("utf-8") diff --git a/mem0-plugin/scripts/on_session_start.sh b/mem0-plugin/scripts/on_session_start.sh index bcabbf41f..b073b75ea 100755 --- a/mem0-plugin/scripts/on_session_start.sh +++ b/mem0-plugin/scripts/on_session_start.sh @@ -53,12 +53,15 @@ req = urllib.request.Request( ) try: with urllib.request.urlopen(req, timeout=5) as r: - results = json.loads(r.read()) - if isinstance(results, list): - n = len(results) - print(f'{n}+' if n >= 100 else str(n)) + data = json.loads(r.read()) + if isinstance(data, list): + results = data + elif isinstance(data, dict) and 'results' in data: + results = data['results'] else: - print('?') + print('?'); raise SystemExit + n = len(results) + print(f'{n}+' if n >= 100 else str(n)) except Exception: print('?') " 2>/dev/null || echo "?") diff --git a/mem0-plugin/scripts/on_stop.sh b/mem0-plugin/scripts/on_stop.sh index f9987744f..94af38bdc 100755 --- a/mem0-plugin/scripts/on_stop.sh +++ b/mem0-plugin/scripts/on_stop.sh @@ -10,7 +10,8 @@ # # IMPORTANT: Check stop_hook_active to avoid infinite loops. -set -euo pipefail +# Intentionally omit -e so the reminder always emits even if session_stats fails. +set -uo pipefail if [ -n "${MEM0_DEBUG:-}" ]; then mkdir -p "$HOME/.mem0" && exec 2>>"$HOME/.mem0/hooks.log" diff --git a/mem0-plugin/scripts/on_stop_cursor.sh b/mem0-plugin/scripts/on_stop_cursor.sh index 179d924ed..f9412715f 100755 --- a/mem0-plugin/scripts/on_stop_cursor.sh +++ b/mem0-plugin/scripts/on_stop_cursor.sh @@ -19,6 +19,14 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" INPUT=$(cat) +# Guard against infinite loops: if this is a re-entry after a prior followup, +# let the turn end. Cursor exposes loop_count in the input JSON. +LOOP_COUNT=$(echo "$INPUT" | jq -r '.loop_count // 0' 2>/dev/null || echo "0") +if [ "$LOOP_COUNT" -gt 1 ]; then + echo '{}' + exit 0 +fi + # Session-end report (best-effort) REPORT=$(python3 "$SCRIPT_DIR/session_stats.py" report 2>/dev/null || echo "") REPORT_BLOCK=""