{"record":{"id":"91948a600ba0dca8","repo":"nautechsystems/nautilus_trader","slug":"cached-client-order-has-no-association-with-req","errorCode":null,"errorMessage":"cached client order {} has no association with requested venue order {venue_order_id}","messagePattern":"cached client order (.+?) has no association with requested venue order (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reports.rs","lineNumber":146,"sourceCode":"                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!(\n                    cached_order.instrument_id() == requested_instrument_id,\n                    \"cached order instrument {} does not match requested instrument {requested_instrument_id}\",\n                    cached_order.instrument_id(),\n                );\n            }\n        }","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reports.rs#L128-L164","documentation":"When the cached order has no venue_order_id of its own, the adapter still requires some association: the cached order's client order id must equal the requested client order id, or the registry must map the cached order's client order id to the requested venue order id. This ensure! fires when neither holds, meaning the cached order has no relationship at all to the requested venue order.","triggerScenarios":"generate_fill_reports_impl or generate_order_status_report_impl called with a venue_order_id for an order whose cached client order is a different order and has not yet received a venue id (e.g. a pre-submit or unfilled order).","commonSituations":"Querying fills for a venue order before the cache learned its client-order linkage; strategy passing ids from two different orders; a partially initialized cache after restart.","solutions":["Wait for submit acknowledgment so the cached order gains its venue_order_id before querying","Query using the venue order's own registered client order id","Check that the venue_order_id belongs to the order you intend","Rebuild order_contexts registration if the registry lost the mapping"],"exampleFix":"// before\nlet reports = client.generate_fill_reports(Some(other_coid), venue_order_id).await?;\n// after\nif let Some(cached) = core.cache().order_owned(&coid) {\n    anyhow::ensure!(cached.venue_order_id().is_some(), \"order not yet acknowledged by venue\");\n}\nlet reports = client.generate_fill_reports(Some(coid), venue_order_id).await?;","handlingStrategy":"validation","validationCode":"if let Some(cached) = core.cache().order_owned(&coid) {\n    anyhow::ensure!(cached.venue_order_id().is_some(), \"order not yet acknowledged; defer fill query\");\n}","typeGuard":"fn is_acknowledged(core: &Cache, coid: &ClientOrderId) -> bool {\n    core.order_owned(coid).map(|o| o.venue_order_id().is_some()).unwrap_or(false)\n}","tryCatchPattern":"match client.generate_fill_reports_impl(Some(coid), void_id).await {\n    Err(e) if e.to_string().contains(\"no association\") => {\n        // order not yet linked; schedule retry after submit ack\n    }\n    other => other?,\n}","preventionTips":["Only query fills after the order reaches an acknowledged/submitted state","Gate fill-report generation on Submitted or later order events","Keep submit -> ack -> query sequencing explicit in strategy logic"],"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"}