{"record":{"id":"dbcdfc5d7cac9ae6","repo":"oraios/serena","slug":"memory-new-name-already-exists","errorCode":null,"errorMessage":"Memory {new_name} already exists.","messagePattern":"Memory (.+?) already exists\\.","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"src/serena/memories/memory_manager.py","lineNumber":339,"sourceCode":"\n    def move_memory(self, old_name: str, new_name: str, is_tool_context: bool) -> str:\n        \"\"\"\n        Rename or move a memory file.\n        Moving between global and project scope (e.g. \"global/foo\" -> \"bar\") is supported.\n        \"\"\"\n        old_name = self._sanitize_name(old_name)\n        new_name = self._sanitize_name(new_name)\n        self._check_not_ignored(old_name)\n        self._check_not_ignored(new_name)\n        self._check_write_access(new_name, is_tool_context)\n\n        old_path = self.get_memory_file_path(old_name)\n        new_path = self.get_memory_file_path(new_name)\n\n        if not old_path.exists():\n            raise FileNotFoundError(f\"Memory {old_name} not found.\")\n        if new_path.exists():\n            raise FileExistsError(f\"Memory {new_name} already exists.\")\n\n        new_path.parent.mkdir(parents=True, exist_ok=True)\n        shutil.move(old_path, new_path)\n\n        return f\"Memory renamed from {old_name} to {new_name}.\"\n\n    def rename_memory_and_propagate_references(self, old_name: str, new_name: str, is_tool_context: bool) -> tuple[str, int]:\n        \"\"\"\n        Renames a memory and updates every ``mem:OLD_NAME`` reference across all memories.\n\n        Memories whose content does not contain a reference to ``old_name`` are left\n        untouched (no spurious mtime changes). Memories that do are rewritten via\n        :meth:`save_memory`.\n\n        :param old_name: the current memory name (the source of the rename)\n        :param new_name: the target memory name\n        :param is_tool_context: forwarded to :meth:`save_memory` for read-only enforcement\n        :return: a tuple of (rename message returned by :meth:`move_memory`, total number of","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/serena/memories/memory_manager.py#L321-L357","documentation":"move_memory (rename) raises FileExistsError when a memory file already exists at the destination name new_name. Serena refuses to overwrite existing memories during a move, preserving the destination's content.","triggerScenarios":"Calling move_memory(old_name, new_name) where get_memory_file_path(new_name).exists() is True — e.g. renaming to a name that is already taken, or re-running a rename after it partially succeeded conceptually (source still present) with a destination that was created in the meantime.","commonSituations":"Agents proposing names that collide with existing memories; retrying a rename after a first attempt created the destination; renaming onto a default/system memory name that already exists.","solutions":["Pick a distinct destination name that does not already exist (check list_memories or get_memory_file_path(new_name).exists()).","If the destination content is disposable, delete it first with delete_memory, then move.","If you intended to overwrite, read the destination, merge or discard as needed, and perform explicit save + delete instead of move.","Guard the call: only invoke move_memory after verifying the destination path does not exist."],"exampleFix":"// before\nmanager.move_memory(\"notes\", \"docs\", is_tool_context=True)  # FileExistsError: docs exists\n// after\nif not manager.get_memory_file_path(\"docs\").exists():\n    manager.move_memory(\"notes\", \"docs\", is_tool_context=True)\nelse:\n    manager.move_memory(\"notes\", \"docs_v2\", is_tool_context=True)","handlingStrategy":"validation","validationCode":"if manager.get_memory_file_path(new_name).exists():\n    raise FileExistsError(f\"destination {new_name!r} already exists; pick another name\")","typeGuard":"def destination_free(manager, new: str) -> bool:\n    return not manager.get_memory_file_path(new).exists()","tryCatchPattern":"try:\n    manager.move_memory(old_name, new_name, is_tool_context)\nexcept FileExistsError:\n    new_name = f\"{new_name}_renamed\"\n    manager.move_memory(old_name, new_name, is_tool_context)","preventionTips":["Check destination non-existence immediately before moving","Derive unique destination names (suffix with timestamp/version) in automated flows","If overwrite is intended, do explicit delete + move rather than relying on move to overwrite"],"tags":["python","memory","already-exists","rename"],"backgroundTag":"memory-already-exists","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}