{"record":{"id":"ebb20d65c187d0b4","repo":"nautechsystems/nautilus_trader","slug":"existing-existing-venue-order-id-for-client-ord","errorCode":null,"errorMessage":"Existing {existing_venue_order_id} for {client_order_id}\n                    did not match the given {venue_order_id}.\n                    If you are writing a test then try a different `venue_order_id`,\n                    otherwise this is probably a bug.","messagePattern":"Existing (.+?) for (.+?)\n                    did not match the given (.+?)\\.\n                    If you are writing a test then try a different `venue_order_id`,\n                    otherwise this is probably a bug\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/cache/mod.rs","lineNumber":4656,"sourceCode":"            .entry(*client_order_id)\n            .or_insert(*venue_order_id);\n\n        Ok(())\n    }\n\n    fn validate_venue_order_id_claim(\n        &self,\n        client_order_id: &ClientOrderId,\n        venue_order_id: &VenueOrderId,\n        overwrite: bool,\n    ) -> anyhow::Result<()> {\n        self.validate_venue_order_id_ownership(client_order_id, venue_order_id)?;\n\n        if let Some(existing_venue_order_id) = self.index.client_order_ids.get(client_order_id)\n            && !overwrite\n            && existing_venue_order_id != venue_order_id\n        {\n            anyhow::bail!(\n                \"Existing {existing_venue_order_id} for {client_order_id}\n                    did not match the given {venue_order_id}.\n                    If you are writing a test then try a different `venue_order_id`,\n                    otherwise this is probably a bug.\"\n            );\n        }\n\n        Ok(())\n    }\n\n    fn validate_venue_order_id_ownership(\n        &self,\n        client_order_id: &ClientOrderId,\n        venue_order_id: &VenueOrderId,\n    ) -> anyhow::Result<()> {\n        if let Some(existing_client_order_id) = self.index.venue_order_ids.get(venue_order_id)\n            && existing_client_order_id != client_order_id\n        {","sourceCodeStart":4638,"sourceCodeEnd":4674,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/cache/mod.rs#L4638-L4674","documentation":"When adding a venue order ID for a client order ID, the cache already has a different venue order ID mapped and `overwrite` is false. The cache treats a client_order_id -> venue_order_id mapping as immutable unless explicitly overwritten, so a mismatch is rejected as a likely bug or test artifact.","triggerScenarios":"Calling `add_venue_order_id` (or `update_venue_order_id` with overwrite=false) for a client_order_id that already maps to another venue_order_id; reusing a client_order_id across tests or order generations; venue assign/re-assign flows that pass overwrite=false.","commonSituations":"Test code reusing fixture client order IDs while generating sequential venue order IDs; sim replay of fills with a stale venue order ID; adapter emitting a different venue order ID for the same client order after amend.","solutions":["Pass `overwrite: true` if the venue legitimately reassigned the order ID.","In tests, use a unique venue_order_id per client_order_id (as the message suggests).","Verify which venue_order_id the adapter reports; fix the adapter mapping if it is wrong."],"exampleFix":"// before\ncache.add_venue_order_id(&client_order_id, venue_order_id, venue_order_id_assigned, false);\n// after\ncache.add_venue_order_id(&client_order_id, venue_order_id, venue_order_id_assigned, true); // if reassignment is intended","handlingStrategy":"try-catch","validationCode":"if let Some(existing) = cache.venue_order_id(&client_order_id) {\n    if existing != venue_order_id && !overwrite { /* handle mismatch before calling */ }\n}","typeGuard":null,"tryCatchPattern":"match cache.add_venue_order_id(&client_order_id, venue_order_id, ts, overwrite) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"did not match the given\") => {\n        // retry with overwrite=true or fix the venue_order_id\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Use unique client_order_id/venue_order_id pairs per test case.","Treat client_order_id -> venue_order_id mapping as immutable; use overwrite only for genuine venue reassignment.","Log both IDs on every order-report event."],"tags":["rust","cache","order-ids","identifier-conflict","testing"],"backgroundTag":"type-mismatch","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}