{"record":{"id":"5c649faed97c0e33","repo":"chroma-core/chroma","slug":"transactional-write-request-contains-duplicate-id-5c649f","errorCode":null,"errorMessage":"transactional write request contains duplicate id \"{id}\"","messagePattern":"transactional write request contains duplicate id \"(.+?)\"","errorType":"exception","errorClass":"InvalidArgumentError","httpStatus":400,"severity":"error","filePath":"chromadb/api/conditional_http.py","lineNumber":287,"sourceCode":"                f\"{self._read_token} to {actual_read_token}\"\n            )\n\n    def _buffer_write(\n        self,\n        operation: str,\n        ids: IDs,\n        payload: ConditionalHttpJsonPayload,\n    ) -> None:\n        self._validate_buffered_write(operation, ids)\n        for id in ids:\n            self._buffered_write_ids.add(id)\n        self._operations.append({\"operation\": operation, \"payload\": payload})\n\n    def _validate_buffered_write(self, operation: str, ids: IDs) -> None:\n        call_ids: Set[str] = set()\n        for id in ids:\n            if id in call_ids:\n                raise InvalidArgumentError(\n                    f'transactional write request contains duplicate id \"{id}\"'\n                )\n            call_ids.add(id)\n            if id in self._buffered_write_ids:\n                raise InvalidArgumentError(\n                    f'transaction already has a buffered write for id \"{id}\"'\n                )\n            self._validate_write_precondition(operation, id)\n\n    def _validate_write_precondition(self, operation: str, id: str) -> None:\n        if operation == \"add\" and id not in self._known_absent:\n            raise InvalidArgumentError(\n                f'transactional add for id \"{id}\" requires a prior read '\n                \"proving the id is absent\"\n            )\n        if operation == \"update\" and id not in self._known_present:\n            raise InvalidArgumentError(\n                f'transactional update for id \"{id}\" requires a prior read '","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/conditional_http.py#L269-L305","documentation":"Raised by _validate_buffered_write (chromadb/api/conditional_http.py:287) when the same id appears more than once within the ids list of a single transactional add/update/upsert/delete call. The transaction buffer keys writes by id to maintain read-after-write consistency and OCC preconditions, so one request cannot carry two conflicting payloads for the same record. The check uses a per-call set (call_ids) and fires before anything is buffered.","triggerScenarios":"A single transactional write whose ids argument contains duplicates, e.g. collection.add(ids=[\"a\", \"b\", \"a\"], ...) inside a transaction; duplicates introduced by concatenating lists or generating ids with a non-unique key without deduping.","commonSituations":"Merging batches from multiple sources into one add() call without deduping; ID generation collisions (same hash or slug produced twice) feeding one call; off-by-one slicing that repeats the tail of a list.","solutions":["Deduplicate ids (preserving order) before the call and align the parallel embeddings/documents/metadata lists to the deduped ids","If the later occurrence should win, split into sequential calls only after a read, or use upsert semantics","Fix the upstream id generation so duplicates cannot be produced"],"exampleFix":"# before\ncollection.add(ids=[\"a\", \"b\", \"a\"], embeddings=[e1, e2, e3])\n# after\nids = list(dict.fromkeys([\"a\", \"b\", \"a\"]))   # ordered dedupe -> [\"a\", \"b\"]\ncollection.add(ids=ids, embeddings=[e1, e2])","handlingStrategy":"validation","validationCode":"def dedupe_ids(ids):\n    return list(dict.fromkeys(ids))  # order-preserving unique ids\n\nids = dedupe_ids(ids)\nassert len(ids) == len(embeddings), \"parallel arrays must match deduped ids\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate ids (order-preserving) before every transactional write call","Keep embeddings/documents/metadata arrays aligned with the deduped id list","Add a unit assertion on id uniqueness in batch-building code"],"tags":["chromadb","transaction","duplicate-ids","write-buffer"],"backgroundTag":"transaction-validation-failed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}