{"record":{"id":"73d9ea755d939f15","repo":"nautechsystems/nautilus_trader","slug":"ambiguous-lighter-active-order-lookup-for-client-o","errorCode":null,"errorMessage":"ambiguous Lighter active-order lookup for client_order_index {client_order_index} and nonce {nonce}","messagePattern":"ambiguous Lighter active-order lookup for client_order_index (.+?) and nonce (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/websocket/dispatch.rs","lineNumber":1762,"sourceCode":"    let query = Zeroizing::new(LighterAccountActiveOrdersQuery {\n        authorization: None,\n        auth: Some(auth.clone()),\n        account_index: credential.account_index(),\n        market_id: market_index,\n    });\n    let active = http_client\n        .get_account_active_orders(&query)\n        .await\n        .context(\"failed to fetch Lighter active orders\")?;\n\n    let mut matches = active\n        .orders\n        .iter()\n        .filter(|order| order.client_order_index == client_order_index && order.nonce == nonce);\n    let Some(order) = matches.next() else {\n        return Ok(None);\n    };\n    anyhow::ensure!(\n        matches.next().is_none(),\n        \"ambiguous Lighter active-order lookup for client_order_index {client_order_index} and nonce {nonce}\",\n    );\n\n    let report = parse_http_order_to_report(order, registry, account_id, clock.get_time_ns())\n        .ok_or_else(|| {\n            anyhow::anyhow!(\n                \"failed to parse Lighter active order {} for acknowledged create\",\n                order.order_index,\n            )\n        })?;\n    let report = dispatch\n        .translate_order_cloid(report)\n        .with_client_order_id(client_order_id);\n    Ok(Some(dispatch.preserve_pending_order_status(report)))\n}\n\n/// Look up a single order via the active and inactive HTTP endpoints, returning","sourceCodeStart":1744,"sourceCodeEnd":1780,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/websocket/dispatch.rs#L1744-L1780","documentation":"During reconciliation, the adapter filters the venue's active orders by (client_order_index, nonce) and requires exactly one match. If two or more active orders share the same client_order_index and nonce, the venue state is ambiguous and the lookup is aborted instead of guessing. This protects Nautilus order state from being built from the wrong venue order.","triggerScenarios":"Calling the active-order lookup/reconciliation path with a client_order_index+nonce pair that matches more than one order in the exchange's open-orders response (e.g. venue allowed a duplicate client_order_index with a colliding nonce).","commonSituations":"Reconnecting/reconciling after a network split where a submission was retried and the venue recorded two orders with the same client_order_index and nonce; bugs in client-generated nonce handling.","solutions":["Fetch the venue open orders and inspect duplicates for that client_order_index; cancel the unwanted duplicate on the venue.","Ensure the nonce used at submit time is unique per order (check nonce generation logic in the signing/submit path).","Re-run reconciliation after cancelling duplicates so the lookup resolves to a single order."],"exampleFix":"// before: reconcile by (client_order_index, nonce) with duplicates on venue\nanyhow::ensure!(matches.next().is_none(), \"ambiguous ...\");\n// after: prevent duplicates upstream by generating a strictly increasing unique nonce per CreateOrder tx","handlingStrategy":"validation","validationCode":"let dups: Vec<_> = active.orders.iter().filter(|o| o.client_order_index == idx && o.nonce == nonce).collect();\nif dups.len() > 1 { /* cancel duplicates before reconciling */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate a unique nonce per submitted order","Never reuse client_order_index values","Inspect venue open orders for duplicates after connection drops"],"tags":["reconciliation","websocket","duplicate-order"],"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-14T00:17:10.932Z"}