bytedance/deer-flow · error · ValueError

Duplicate fact id {fact_id!r} in upserts

Error message

Duplicate fact id {fact_id!r} in upserts

What it means

Error "Duplicate fact id {fact_id!r} in upserts" thrown in bytedance/deer-flow.

Source

Thrown at backend/packages/harness/deerflow/agents/memory/backends/deermem/deermem/core/storage.py:741

        files are neither opened for backup nor rewritten nor re-indexed.
        """
        current_memory = self._load_memory_file(path)
        current_revision = int((current_memory or {}).get("revision") or 0)
        if expected_revision is not None and expected_revision != current_revision:
            raise MemoryManifestRevisionConflict(f"Expected user-memory revision {expected_revision}, found {current_revision}")
        if (upserts or deletes) and agent_name is None:
            raise ValueError("agent_name is required for fact repository changes")

        scope = _scope_dict(user_id, agent_name)
        prepared: dict[str, tuple[dict[str, Any], dict[str, Any] | None, Path]] = {}
        for incoming in upserts:
            if not isinstance(incoming, dict):
                raise ValueError("change_set.upserts must contain fact objects")
            candidate = copy.deepcopy(incoming)
            candidate["id"] = str(candidate.get("id") or f"fact_{uuid.uuid4().hex}")
            fact_id = candidate["id"]
            if fact_id in prepared:
                raise ValueError(f"Duplicate fact id {fact_id!r} in upserts")
            if agent_name is None:  # guarded above
                raise ValueError("agent_name is required for fact repository changes")
            existing, fact_path = self._read_fact(path, fact_id, user_id=user_id, agent_name=agent_name)
            if upsert_revisions is not None and fact_id in upsert_revisions:
                expected_fact_revision = upsert_revisions[fact_id]
                if expected_fact_revision is None and existing is not None:
                    raise MemoryFactRevisionConflict(f"Fact {fact_id!r} must not already exist")
                if expected_fact_revision is not None:
                    actual_fact_revision = None if existing is None else existing.get("revision")
                    if actual_fact_revision != expected_fact_revision:
                        raise MemoryFactRevisionConflict(f"Expected fact {fact_id!r} revision {expected_fact_revision}, found {actual_fact_revision}")
            normalized = _normalize_fact(candidate, scope=scope, existing=existing)
            if existing != normalized:
                prepared[fact_id] = (normalized, existing, fact_path)

        delete_ids = [str(fact_id) for fact_id in deletes]
        if len(delete_ids) != len(set(delete_ids)):
            raise ValueError("Duplicate fact ids are not allowed in deletes")

View on GitHub (pinned to 1dd6ba1acb)

Solutions

  1. Remove the duplicate fact id from the upserts list; each id may appear once.
  2. Merge the duplicate entries into a single upsert.

When it happens

Trigger: Thrown at backend/packages/harness/deerflow/agents/memory/backends/deermem/deermem/core/storage.py:741 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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