{"record":{"id":"45a6c307609a29da","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"clear-chat-memory-requires-a-non-empty-memory-ids","errorCode":null,"errorMessage":"clear_chat_memory requires a non-empty memory_ids list","messagePattern":"clear_chat_memory requires a non-empty memory_ids list","errorType":"validation","errorClass":"ParamError","httpStatus":null,"severity":"error","filePath":"sdk/memory-core/python/tencentdb_agent_memory/v3/client.py","lineNumber":550,"sourceCode":"        名称、可见性 —— 清空后 Agent 继续用原 ``memory_id`` 写入，无需重建。\n\n        与 L0/L1 删除接口不同，本接口是**资产级**操作：\n\n        * 作用域由 ``memory_ids`` 自身决定，不使用隔离三元组\n        * 任一 ``memory_id`` 不存在或不是 chat_memory 时**整批拒绝**，一条都不清\n        * 幂等：已清空过的再次调用仍返回成功，计数为 0\n\n        权限：与其它删除接口一致，内核不做用户级鉴权。若需要\"仅 Owner 可清空\"\n        的约束，请走面板后端 ``/api/v1/chat-memory/clear``（那里会校验 Owner）。\n\n        失败项会带 ``retryable`` 标志；为 True 表示服务端已自动重试仍未成功，\n        稍后重试即可补齐残留内容。\n\n        :param memory_ids: 待清空的资产 id，1–100 个（自动去重）\n        \"\"\"\n        normalized = _normalize_delete_ids(\"memory_ids\", memory_ids, 100)\n        if not normalized:\n            raise ParamError(\"clear_chat_memory requires a non-empty memory_ids list\")\n        # 注意：不带隔离三元组 —— 作用域由 memory_ids 决定。\n        return self._stub.post(f\"{_V3}/chat-memory/clear\", {\"memory_ids\": normalized})\n\n    # -- Lifecycle ---------------------------------------------------------\n\n    def close(self) -> None:\n        self._stub.close()\n\n    def __enter__(self) -> \"MemoryClient\":\n        return self\n\n    def __exit__(self, *exc: Any) -> None:\n        self.close()\n\n\n# ---------------------------------------------------------------------------\n# Asynchronous client\n# ---------------------------------------------------------------------------","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/sdk/memory-core/python/tencentdb_agent_memory/v3/client.py#L532-L568","documentation":"clear_chat_memory clears 1–100 chat-memory assets identified by memory_ids; after normalization (strip+dedup) the list must be non-empty. An empty or fully-invalid list raises ParamError and no request is sent. Isolation triple is intentionally omitted since scope is defined solely by memory_ids.","triggerScenarios":"clear_chat_memory(memory_ids=[]) ; memory_ids containing only empty/whitespace strings; a variable holding ids that turned out empty after dedup.","commonSituations":"Reset/cleanup jobs whose id query returned no rows; copying the 100-item cap but passing nothing; mistaking clear_chat_memory (id-scoped) for a whole-conversation clear.","solutions":["Pass 1–100 non-empty memory_ids: clear_chat_memory(memory_ids=[\"m1\",\"m2\"])\n","Check the list is non-empty before calling; skip otherwise\n","If you intended to clear by conversation, use delete_conversation with session_ids instead","Deduplicate first so a duplicated id list still passes the 100 cap"],"exampleFix":"// before\nclient.clear_chat_memory(memory_ids=ids_from_query)  # may be []\n// after\nif ids_from_query:\n    client.clear_chat_memory(memory_ids=ids_from_query)","handlingStrategy":"validation","validationCode":"def clear_memory_safe(client, memory_ids):\n    clean = list({m.strip() for m in memory_ids if isinstance(m, str) and m.strip()})\n    if not clean or len(clean) > 100:\n        raise ValueError(\"need 1-100 non-empty memory_ids\")\n    return client.clear_chat_memory(memory_ids=clean)","typeGuard":"def ok_memory_ids(v) -> bool:\n    return 1 <= len(v) <= 100 and all(isinstance(m, str) and m.strip() for m in v)","tryCatchPattern":"try:\n    client.clear_chat_memory(memory_ids=ids)\nexcept ParamError as e:\n    if \"non-empty memory_ids\" in str(e):\n        logger.warning(\"no memory ids to clear; skipping\")","preventionTips":["Verify the id query returned rows before clearing","Remember scope comes only from memory_ids — no session/team fallback","Deduplicate to stay within the 100 cap","For conversation-wide cleanup use delete_conversation instead"],"tags":["python","validation","parameter-error"],"backgroundTag":"empty-required-list","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}