{"record":{"id":"b098892409c3f3c7","repo":"nautechsystems/nautilus_trader","slug":"command-client-order-id-does-not-match-cached-o","errorCode":null,"errorMessage":"command client order ID {} does not match cached order {}","messagePattern":"command client order ID (.+?) does not match cached order (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":2106,"sourceCode":"            symbol = exec_data.contract.symbol.as_str(),\n            sec_type = ?exec_data.contract.security_type,\n            exchange = exec_data.contract.exchange.as_str(),\n            primary_exchange = exec_data.contract.primary_exchange.as_str(),\n            local_symbol = exec_data.contract.local_symbol.as_str(),\n            con_id = exec_data.contract.contract_id,\n            order_id = exec_data.execution.order_id,\n            order_ref = exec_data.execution.order_reference.as_str(),\n            execution_id = exec_data.execution.execution_id.as_str(),\n            error = %error,\n            \"Failed to parse IBKR historical fill report\",\n        );\n    }\n\n    fn validate_cancel_order_target(\n        cmd: &CancelOrder,\n        target_order: &OrderAny,\n    ) -> anyhow::Result<()> {\n        anyhow::ensure!(\n            cmd.client_order_id == target_order.client_order_id(),\n            \"command client order ID {} does not match cached order {}\",\n            cmd.client_order_id,\n            target_order.client_order_id()\n        );\n        anyhow::ensure!(\n            cmd.instrument_id == target_order.instrument_id(),\n            \"command instrument ID {} does not match cached order {}\",\n            cmd.instrument_id,\n            target_order.instrument_id()\n        );\n\n        // Command actor IDs identify the requester and are not ownership evidence\n        if let (Some(command_venue_order_id), Some(target_venue_order_id)) =\n            (cmd.venue_order_id.as_ref(), target_order.venue_order_id())\n        {\n            anyhow::ensure!(\n                command_venue_order_id == &target_venue_order_id,","sourceCodeStart":2088,"sourceCodeEnd":2124,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L2088-L2124","documentation":"`validate_cancel_order_target` uses `anyhow::ensure!` to verify that the `CancelOrder` command's `client_order_id` equals the `client_order_id` of the cached order it was resolved against. If they differ, an internal bookkeeping inconsistency exists — the cancel command was matched to the wrong cached order — and this error is returned instead of sending a cancel to IB for the wrong order.","triggerScenarios":"Calling cancel handling where `cmd.client_order_id` differs from `target_order.client_order_id()`: a stale/mismatched cache lookup, a command constructed with the wrong ID, or duplicated/rotated client order IDs after reconnect.","commonSituations":"Reconciliation leaving the order cache pointing at a different order; external systems issuing cancels with a recycled or mistyped client order ID; cache corruption or wrong index used to fetch the target order.","solutions":["Log both IDs and re-resolve the target order from the cache using `cmd.client_order_id` exactly.","Purge/rebuild the execution cache (reconcile) so cached orders match live client order IDs.","Fix the caller constructing the `CancelOrder` to use the correct client order ID for the target order."],"exampleFix":"// before\nlet target = cache.order(&some_other_id)?;\nvalidate_cancel_order_target(cmd, &target)?;\n// after\nlet target = cache.order(&cmd.client_order_id)?;\nvalidate_cancel_order_target(cmd, &target)?;","handlingStrategy":"validation","validationCode":"// Before sending a CancelOrder, confirm the cached order matches\nif let Some(order) = cache.order(&cmd.client_order_id) {\n    assert_eq!(order.client_order_id(), cmd.client_order_id, \"cache/client_order_id mismatch\");\n} else {\n    return Err(anyhow::anyhow!(\"no cached order for {}\", cmd.client_order_id));\n}","typeGuard":"fn cancel_target_matches(cmd: &CancelOrder, order: &OrderAny) -> bool {\n    cmd.client_order_id == order.client_order_id()\n}","tryCatchPattern":"match validate_cancel_order_target(&cmd, &target_order) {\n    Ok(()) => send_cancel_to_ib(&cmd),\n    Err(e) => {\n        log::error!(\"cancel target mismatch, rebuilding cache: {e}\");\n        reconcile_cache_and_retry(&cmd).await?;\n    }\n}","preventionTips":["Always resolve the target order via cmd.client_order_id, never via an unrelated index.","Reconcile the cache after reconnects before processing queued commands.","Log both IDs on mismatch to speed diagnosis."],"tags":["rust","validation","order-management","invariant"],"backgroundTag":"invalid-argument-value","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"}