oraios/serena · error · FileExistsError

Memory {new_name} already exists.

Error message

Memory {new_name} already exists.

What it means

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.

Source

Thrown at src/serena/memories/memory_manager.py:339

    def move_memory(self, old_name: str, new_name: str, is_tool_context: bool) -> str:
        """
        Rename or move a memory file.
        Moving between global and project scope (e.g. "global/foo" -> "bar") is supported.
        """
        old_name = self._sanitize_name(old_name)
        new_name = self._sanitize_name(new_name)
        self._check_not_ignored(old_name)
        self._check_not_ignored(new_name)
        self._check_write_access(new_name, is_tool_context)

        old_path = self.get_memory_file_path(old_name)
        new_path = self.get_memory_file_path(new_name)

        if not old_path.exists():
            raise FileNotFoundError(f"Memory {old_name} not found.")
        if new_path.exists():
            raise FileExistsError(f"Memory {new_name} already exists.")

        new_path.parent.mkdir(parents=True, exist_ok=True)
        shutil.move(old_path, new_path)

        return f"Memory renamed from {old_name} to {new_name}."

    def rename_memory_and_propagate_references(self, old_name: str, new_name: str, is_tool_context: bool) -> tuple[str, int]:
        """
        Renames a memory and updates every ``mem:OLD_NAME`` reference across all memories.

        Memories whose content does not contain a reference to ``old_name`` are left
        untouched (no spurious mtime changes). Memories that do are rewritten via
        :meth:`save_memory`.

        :param old_name: the current memory name (the source of the rename)
        :param new_name: the target memory name
        :param is_tool_context: forwarded to :meth:`save_memory` for read-only enforcement
        :return: a tuple of (rename message returned by :meth:`move_memory`, total number of

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Pick a distinct destination name that does not already exist (check list_memories or get_memory_file_path(new_name).exists()).
  2. If the destination content is disposable, delete it first with delete_memory, then move.
  3. If you intended to overwrite, read the destination, merge or discard as needed, and perform explicit save + delete instead of move.
  4. Guard the call: only invoke move_memory after verifying the destination path does not exist.

Example fix

// before
manager.move_memory("notes", "docs", is_tool_context=True)  # FileExistsError: docs exists
// after
if not manager.get_memory_file_path("docs").exists():
    manager.move_memory("notes", "docs", is_tool_context=True)
else:
    manager.move_memory("notes", "docs_v2", is_tool_context=True)
Defensive patterns

Strategy: validation

Validate before calling

if manager.get_memory_file_path(new_name).exists():
    raise FileExistsError(f"destination {new_name!r} already exists; pick another name")

Type guard

def destination_free(manager, new: str) -> bool:
    return not manager.get_memory_file_path(new).exists()

Try / catch

try:
    manager.move_memory(old_name, new_name, is_tool_context)
except FileExistsError:
    new_name = f"{new_name}_renamed"
    manager.move_memory(old_name, new_name, is_tool_context)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29). Data as JSON: /api/errors/dbcdfc5d7cac9ae6. Report an issue: GitHub.