{"record":{"id":"ed0eb684ae466bf0","repo":"bytedance/deer-flow","slug":"mem0-failure-policy-write-must-be-one-of-sorted","errorCode":null,"errorMessage":"mem0 failure_policy.write must be one of {sorted(_WRITE_POLICIES)}","messagePattern":"mem0 failure_policy\\.write must be one of (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/packages/harness/deerflow/agents/memory/backends/mem0/config.py","lineNumber":101,"sourceCode":"\n        config = cls(\n            api_key_env=str(cfg.get(\"api_key_env\", \"MEM0_API_KEY\")),\n            base_url=str(cfg.get(\"base_url\", \"https://api.mem0.ai\")).rstrip(\"/\"),\n            allow_insecure_http=allow_insecure_http,\n            top_k=int(cfg.get(\"top_k\", 8)),\n            score_threshold=float(cfg.get(\"score_threshold\", 0.1)),\n            max_injection_chars=int(cfg.get(\"max_injection_chars\", 12000)),\n            timeout_seconds=float(cfg.get(\"timeout_seconds\", 10.0)),\n            startup_policy=str(cfg.get(\"startup_policy\", \"fail_fast\")),\n            read_policy=str(failure_policy.get(\"read\", \"fail_open\")),\n            write_policy=str(failure_policy.get(\"write\", \"log_and_drop\")),\n        )\n        if config.startup_policy not in _STARTUP_POLICIES:\n            raise ValueError(f\"mem0 startup_policy must be one of {sorted(_STARTUP_POLICIES)}\")\n        if config.read_policy not in _READ_POLICIES:\n            raise ValueError(f\"mem0 failure_policy.read must be one of {sorted(_READ_POLICIES)}\")\n        if config.write_policy not in _WRITE_POLICIES:\n            raise ValueError(f\"mem0 failure_policy.write must be one of {sorted(_WRITE_POLICIES)}\")\n        if not 1 <= config.top_k <= 1000:\n            raise ValueError(\"mem0 top_k must be in [1, 1000]\")\n        if not 0.0 <= config.score_threshold <= 1.0:\n            raise ValueError(\"mem0 score_threshold must be in [0, 1]\")\n        if config.max_injection_chars <= 0:\n            raise ValueError(\"mem0 max_injection_chars must be positive\")\n        if config.timeout_seconds <= 0:\n            raise ValueError(\"mem0 timeout_seconds must be positive\")\n        if not config.api_key_env.strip():\n            raise ValueError(\"mem0 api_key_env must be a non-empty env var name\")\n        parsed_base_url = urlsplit(config.base_url)\n        if parsed_base_url.scheme not in {\"http\", \"https\"} or not parsed_base_url.netloc:\n            raise ValueError(\"mem0 base_url must be an absolute http:// or https:// URL\")\n        if parsed_base_url.scheme == \"http\" and not config.allow_insecure_http:\n            raise ValueError(\"mem0 base_url must use https:// because it carries the API key; set allow_insecure_http: true only for trusted local development\")\n        return config\n\n    def resolve_api_key(self) -> str:","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/packages/harness/deerflow/agents/memory/backends/mem0/config.py#L83-L119","documentation":"Raised by Mem0Config.from_backend_config when memory.backend_config.failure_policy.write is not one of the two supported values: log_and_drop (default; write errors are logged and the memory write is dropped — at-most-once semantics) and raise (write errors raise MemoryManagerError). Checked after str() coercion, so typos and case variants are rejected.","triggerScenarios":"failure_policy: {write: drop}, {write: log-and-drop}, {write: retry}, or {write: Raise} in backend_config.","commonSituations":"Trying to configure a retry behavior that does not exist (write policy is only log_and_drop or raise); hyphenated instead of underscored spelling; copy-paste from other systems.","solutions":["Use exactly log_and_drop (default, fire-and-forget writes) or raise (writes fail the operation)","There is no write-retry policy — put retry/queueing concerns in the surrounding infra, not this key","Remove the write key to accept the log_and_drop default"],"exampleFix":"# before (config.yaml)\nmemory:\n  backend_config:\n    failure_policy:\n      write: log-and-drop   # hyphens not accepted\n\n# after\nmemory:\n  backend_config:\n    failure_policy:\n      write: log_and_drop","handlingStrategy":"validation","validationCode":"WRITE_POLICIES = {\"log_and_drop\", \"raise\"}\n\ndef write_policy_ok(backend_config: dict) -> bool:\n    fp = (backend_config or {}).get(\"failure_policy\") or {}\n    return str(fp.get(\"write\", \"log_and_drop\")) in WRITE_POLICIES","typeGuard":"def is_write_policy(v: object) -> bool:\n    return v in (\"log_and_drop\", \"raise\")","tryCatchPattern":null,"preventionTips":["Only two write behaviors exist (log_and_drop, raise) — there is no retry policy","Use underscore spelling; hyphenated forms from prose docs are rejected"],"tags":["config","mem0","memory","validation","failure-policy"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}