{"record":{"id":"c71543b6321beb4e","repo":"bytedance/deer-flow","slug":"fact-scope-mismatch-for-fact-path-expected-exp","errorCode":null,"errorMessage":"Fact scope mismatch for {fact_path}: expected {expected_scope!r}, found {fact.get('scope')!r}","messagePattern":"Fact scope mismatch for (.+?): expected (.+?), found (.+?)","errorType":"exception","errorClass":"MemoryStorageCorruption","httpStatus":null,"severity":"error","filePath":"backend/packages/harness/deerflow/agents/memory/backends/deermem/deermem/core/storage.py","lineNumber":496,"sourceCode":"                logger.exception(\"Retrieval notification failed for %s\", value)\n                with self._cache_lock:\n                    self._retrieval_dirty_scopes.add(self._cache_key(agent_name, user_id=user_id))\n\n    @staticmethod\n    def _validate_loaded_fact(\n        fact: dict[str, Any],\n        fact_path: Path,\n        *,\n        user_id: str | None,\n        agent_name: str,\n    ) -> dict[str, Any]:\n        if str(fact.get(\"id\")) != fact_path.stem:\n            raise MemoryStorageCorruption(f\"Fact id mismatch for {fact_path}\")\n        expected_scope = _scope_dict(user_id, agent_name)\n        actual_scope = fact.get(\"scope\")\n        scope_matches = isinstance(actual_scope, dict) and actual_scope.get(\"userId\") == user_id and isinstance(actual_scope.get(\"agentName\"), str) and actual_scope[\"agentName\"].lower() == agent_name.lower()\n        if not scope_matches:\n            raise MemoryStorageCorruption(f\"Fact scope mismatch for {fact_path}: expected {expected_scope!r}, found {fact.get('scope')!r}\")\n        try:\n            return _normalize_fact(fact, scope=copy.deepcopy(actual_scope))\n        except ValueError as exc:\n            raise MemoryStorageCorruption(f\"Invalid canonical fact {fact_path}: {exc}\") from exc\n\n    def _load_agent_facts(self, path: Path, agent_name: str | None, *, user_id: str | None) -> list[dict[str, Any]]:\n        if agent_name is None:\n            return []\n        facts: list[dict[str, Any]] = []\n        for fact_path in sorted(agent_facts_directory(path, agent_name).glob(\"**/*.md\")):\n            fact = _parse_fact_markdown(fact_path)\n            facts.append(self._validate_loaded_fact(fact, fact_path, user_id=user_id, agent_name=agent_name))\n        # Shard directories are an internal layout detail and must not change\n        # the stable fact order observed by callers.\n        return sorted(facts, key=lambda fact: str(fact[\"id\"]))\n\n    def _read_fact(self, path: Path, fact_id: str, *, user_id: str | None, agent_name: str) -> tuple[dict[str, Any] | None, Path]:\n        fact_path = fact_file_path(path, fact_id, agent_name=agent_name)","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/packages/harness/deerflow/agents/memory/backends/deermem/deermem/core/storage.py#L478-L514","documentation":"Error \"Fact scope mismatch for {fact_path}: expected {expected_scope!r}, found {fact.get('scope')!r}\" thrown in bytedance/deer-flow.","triggerScenarios":"Thrown at backend/packages/harness/deerflow/agents/memory/backends/deermem/deermem/core/storage.py:496 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the fact file into the directory of its declared scope, or fix its scope field.","Re-save the fact through the memory API under the correct scope."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}