{"record":{"id":"d3f474cbd06aa1a8","repo":"nautechsystems/nautilus_trader","slug":"cached-client-order-is-associated-with-venue-or","errorCode":null,"errorMessage":"cached client order {} is associated with venue order {cached_venue_order_id}, not requested venue order {venue_order_id}","messagePattern":"cached client order (.+?) is associated with venue order (.+?), not requested venue order (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reports.rs","lineNumber":140,"sourceCode":"                client_order_id = Some(candidate);\n            }\n        }\n\n        if let Some(client_order_id) = client_order_id\n            && let Some(registered_venue_order_id) =\n                self.order_contexts.venue_order_id(&client_order_id)\n        {\n            anyhow::ensure!(\n                registered_venue_order_id == venue_order_id,\n                \"client order {client_order_id} is registered to venue order {registered_venue_order_id}, not requested venue order {venue_order_id}\",\n            );\n        }\n\n        let cached_order = client_order_id.and_then(|value| self.core.cache().order_owned(&value));\n        if let Some(cached_order) = cached_order.as_ref() {\n            let cached_venue_order_id = cached_order.venue_order_id();\n            if let Some(cached_venue_order_id) = cached_venue_order_id {\n                anyhow::ensure!(\n                    cached_venue_order_id == venue_order_id,\n                    \"cached client order {} is associated with venue order {cached_venue_order_id}, not requested venue order {venue_order_id}\",\n                    cached_order.client_order_id(),\n                );\n            } else {\n                anyhow::ensure!(\n                    cached_client_order_id == client_order_id\n                        || self\n                            .order_contexts\n                            .venue_order_id(&cached_order.client_order_id())\n                            == Some(venue_order_id),\n                    \"cached client order {} has no association with requested venue order {venue_order_id}\",\n                    cached_order.client_order_id(),\n                );\n            }\n\n            if let Some(requested_instrument_id) = requested_instrument_id {\n                anyhow::ensure!(","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reports.rs#L122-L158","documentation":"resolve_target_order_authority looks up the order cached in the Nautilus core cache for the given client_order_id and verifies that its associated venue_order_id equals the requested venue order id. This ensure! fires when the cached order points at a different venue order. It protects against generating reports that mix state from two distinct venue orders.","triggerScenarios":"query_order_command, generate_order_status_report_impl, or generate_fill_reports_impl called with a venue_order_id that disagrees with cache.order_owned(client_order_id).venue_order_id().","commonSituations":"Order was modified/replaced so the cache now holds the new venue order id, but the caller still passes the old one; multiple live orders sharing a client_order_id due to a strategy bug; a restart repopulated the cache differently.","solutions":["Pass the venue order id recorded on the cached order instead of the stale one","Confirm the order was not replaced; if it was, use the replacement's venue order id","Check strategy code for reusing client order ids across orders","Clear and re-sync the cache with current venue state"],"exampleFix":"// before\nlet report = client.generate_order_status_report(Some(coid), old_void_id).await?;\n// after\nlet cached = core.cache().order_owned(&coid).context(\"order not cached\")?;\nlet void_id = cached.venue_order_id().context(\"cached order has no venue id\")?;\nlet report = client.generate_order_status_report(Some(coid), void_id).await?;","handlingStrategy":"validation","validationCode":"let cached = core.cache().order_owned(&client_order_id).context(\"order not in cache\")?;\nlet cached_void = cached.venue_order_id().context(\"no venue id yet\")?;\nanyhow::ensure!(cached_void == venue_order_id, \"stale venue id\");","typeGuard":"fn cache_matches(core: &Cache, coid: &ClientOrderId, void_id: &VenueOrderId) -> bool {\n    core.order_owned(coid).and_then(|o| o.venue_order_id().map(|v| v == *void_id)).unwrap_or(false)\n}","tryCatchPattern":"match exec.generate_order_status_report_impl(...).await {\n    Err(e) if e.to_string().contains(\"cached client order\") => warn!(\"cache/registry diverged for {coid}\"),\n    other => other?,\n}","preventionTips":["Do not cache venue order ids locally in strategies; read them from the Nautilus cache","After any modify/replace, confirm the cache reflects the new venue order id before querying","Avoid reusing client_order_id values across separate orders"],"tags":["rust","order-management","cache","id-mismatch"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}