fix(memory): reject blank memory_id on edit and delete (#6342)

In src/ai_interaction.py, when parsing text-format edit or delete actions, an empty line 2 caused memory_id to resolve to empty string. Because startswith("") is always True, the first stored memory was inadvertently edited or deleted.

This change validates that memory_id is non-empty before searching the memory list, restoring parity with the MCP memory tool.

Fixes #6342.
This commit is contained in:
Aashish
2026-10-01 16:27:42 -06:00
committed by Nicholai
parent e3035826bc
commit 6749d6cd81
2 changed files with 62 additions and 0 deletions
+4
View File
@@ -420,6 +420,8 @@ async def do_manage_memory(content: str, session_id: Optional[str] = None, owner
return {"error": "Edit needs line 2: memory_id, line 3: new text"}
memory_id = lines[1].strip()
new_text = lines[2].strip()
if not memory_id:
return {"error": "Edit needs line 2: memory_id"}
if not new_text:
return {"error": "New text cannot be empty"}
@@ -453,6 +455,8 @@ async def do_manage_memory(content: str, session_id: Optional[str] = None, owner
if len(lines) < 2:
return {"error": "Delete needs line 2: memory_id"}
memory_id = lines[1].strip()
if not memory_id:
return {"error": "Delete needs line 2: memory_id"}
memories = _memory_manager.load_all()
original_len = len(memories)