fix(plugin): expire stale state captures + document plugin-update restart
Memory expiration + recency
Hook-side captures (session_state in on_pre_compact.py and
compact_summary in capture_compact_summary.py) now set
expiration_date = today + 90 days. These types describe a single
moment of project state and become stale clutter after a quarter.
Durable types written by the agent (decision, anti_pattern,
convention, user_preference, task_learning, environmental) stay
unexpired by design -- a decision from a year ago is still a
decision.
Skill updated with two new sections:
- "Expiration: high-churn vs durable" -- table mapping each
metadata.type to whether it should carry an expiration_date.
- "Recency filter on recall" -- agent should layer a
created_at >= <90 days ago> filter on recall when the user
asks about *current* state, and skip it when looking for
durable facts.
Plugin-update / MCP reconnect
When the plugin updates, the MCP server connection in the running
client goes stale -- there's no in-process reconnection path from
inside the plugin. Documenting the workaround is the realistic
fix: README now has an "Updating the plugin" section explaining
/restart (Claude Code), quit-and-relaunch (Cursor), restart
(Codex). The auth header re-reads MEM0_API_KEY from the new
shell, so users don't have to re-enter the key.
This commit is contained in:
@@ -22,6 +22,7 @@ import os
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from datetime import date, timedelta
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from _identity import resolve_user_id
|
||||
@@ -45,6 +46,8 @@ if os.environ.get("MEM0_DEBUG"):
|
||||
API_URL = "https://api.mem0.ai"
|
||||
MAX_TAIL_LINES = 2000
|
||||
MAX_SUMMARY_CHARS = 50000
|
||||
# Compact summaries describe a single session's state -- stale after a quarter.
|
||||
COMPACT_SUMMARY_EXPIRY_DAYS = 90
|
||||
|
||||
|
||||
def tail_lines(filepath: str, n: int) -> list[str]:
|
||||
@@ -92,6 +95,7 @@ def find_compact_summary(lines: list[str]) -> str:
|
||||
|
||||
|
||||
def store_summary(api_key: str, summary: str, user_id: str, session_id: str) -> bool:
|
||||
expires = (date.today() + timedelta(days=COMPACT_SUMMARY_EXPIRY_DAYS)).isoformat()
|
||||
body = {
|
||||
"messages": [{"role": "user", "content": summary}],
|
||||
"user_id": user_id,
|
||||
@@ -101,6 +105,7 @@ def store_summary(api_key: str, summary: str, user_id: str, session_id: str) ->
|
||||
"session_id": session_id,
|
||||
},
|
||||
"infer": False,
|
||||
"expiration_date": expires,
|
||||
}
|
||||
|
||||
data = json.dumps(body).encode("utf-8")
|
||||
|
||||
Reference in New Issue
Block a user