bytedance/deer-flow · error · OSError

Failed to save cleared memory data

Error message

Failed to save cleared memory data

What it means

Raised by clear_memory_data on the legacy save path when _save_memory_to_file returns False after building a facts-empty copy of the current memory. The apply_changes fast path retries revision conflicts up to 3 times; this OSError means either that path is unavailable (legacy storage) and the single save attempt failed, or a plain I/O failure occurred.

Source

Thrown at backend/packages/harness/deerflow/agents/memory/backends/deermem/deermem/core/updater.py:884

                        {
                            "deletes": [str(fact.get("id")) for fact in facts],
                            "deleteRevisions": {str(fact.get("id")): int(fact.get("revision") or 1) for fact in facts},
                        },
                        agent_name=agent_name,
                        user_id=user_id,
                        expected_manifest_revision=int(current.get("revision") or 0),
                    )
                    return self.reload_memory_data(agent_name, user_id=user_id)
                except MemoryManifestRevisionConflict:
                    if attempt == 2:
                        raise
                    logger.info("Retrying scoped memory clear from a fresh snapshot after a revision conflict")
            raise AssertionError("bounded scoped-clear retry did not return or raise")
        current = self.get_memory_data(agent_name, user_id=user_id)
        cleared_memory = copy.deepcopy(current)
        cleared_memory["facts"] = []
        if not self._save_memory_to_file(cleared_memory, agent_name, user_id=user_id, expected_revision=int(current.get("revision") or 0)):
            raise OSError("Failed to save cleared memory data")
        return cleared_memory

    def clear_all_memory_data(self, *, user_id: str | None = None) -> dict[str, Any]:
        """Clear global summaries and every agent fact bucket for one user."""
        if getattr(type(self._storage), "clear_all", None) is not MemoryStorage.clear_all:
            return self._storage.clear_all(user_id=user_id)
        current = self.get_memory_data(user_id=user_id)
        cleared_memory = create_empty_memory()
        if not self._save_memory_to_file(
            cleared_memory,
            user_id=user_id,
            expected_revision=int(current.get("revision") or 0),
        ):
            raise OSError("Failed to save cleared memory data")
        return cleared_memory

    def create_memory_fact(self, content: str, category: str = "context", confidence: float = 0.5, agent_name: str | None = None, *, user_id: str | None = None) -> tuple[dict[str, Any], str | None]:
        """Create a new fact, persist it, and return ``(updated_memory, fact_id)``.

View on GitHub (pinned to 1dd6ba1acb)

Solutions

  1. Retry the clear operation — a lost revision race is transient and the next attempt re-reads the current revision
  2. Fix write permissions on the memory storage directory for the Gateway process user
  3. Check disk space and that the directory is not on a read-only mount
  4. Use a storage backend that overrides apply_changes so clears retry revision conflicts automatically (3 attempts)
Defensive patterns

Strategy: retry

Try / catch

try:
    memory.clear_memory_data(agent_name=agent)
except OSError:
    time.sleep(0.2)
    memory.clear_memory_data(agent_name=agent)  # re-reads current revision

Prevention

When it happens

Trigger: Calling clear/forget-memory for one agent on the legacy file backend while the memory file cannot be written (permissions, full disk), or a concurrent update changed the file revision between get_memory_data() and the conditional save, since the legacy path has no retry loop.

Common situations: Memory directory made read-only after a container restart, NFS/overlayfs rename failures, or a background memory-update job racing a user-initiated 'clear agent memory' action.

Related errors


AI-assisted analysis of bytedance/deer-flow@1dd6ba1acb (2026-08-14). Data as JSON: /api/errors/6c40a3abcab3c210. Report an issue: GitHub.