{"record":{"id":"58b3f3b9198ea2e5","repo":"nautechsystems/nautilus_trader","slug":"provider-venue-order-repeats-with-contradictory","errorCode":null,"errorMessage":"provider venue order {} repeats with contradictory evidence","messagePattern":"provider venue order (.+?) repeats with contradictory evidence","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reconciliation.rs","lineNumber":1375,"sourceCode":"    load_ids: Option<&[InstrumentId]>,\n) -> anyhow::Result<(Vec<OrderStatusReport>, usize)> {\n    let mut reports = Vec::new();\n    let mut filtered = 0usize;\n    let mut selected_orders = AHashMap::new();\n\n    for order in orders {\n        let result = build_order_report_from_order(\n            order,\n            instruments,\n            ctx,\n            OrderEvidenceScope::Collection { instrument_filter },\n            ts_init,\n            load_ids,\n        )?;\n\n        if let Some(report) = result.report {\n            if let Some(previous) = selected_orders.get(&report.venue_order_id) {\n                anyhow::ensure!(\n                    *previous == order,\n                    \"provider venue order {} repeats with contradictory evidence\",\n                    report.venue_order_id,\n                );\n                continue;\n            }\n            selected_orders.insert(report.venue_order_id, order);\n            reports.push(report);\n        } else {\n            filtered += usize::from(result.counted_filtered);\n        }\n    }\n\n    Ok((reports, filtered))\n}\n\n/// Applies time-range filters to fill reports.\npub(crate) fn apply_fill_time_filters(","sourceCodeStart":1357,"sourceCodeEnd":1393,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reconciliation.rs#L1357-L1393","documentation":"During order-status reconciliation, `selected_orders` maps venue_order_id to the accepted report. If the same venue order id is produced again, the earlier and current order snapshots must compare equal; a mismatch means the provider returned contradictory evidence for one venue order, so the adapter aborts reconciliation with `anyhow::ensure!` instead of guessing which snapshot is right.","triggerScenarios":"Calling Polymarket order status/fill report generation (the code path that loads per-venue-order results and inserts into `selected_orders`) when two fetched order snapshots for the same venue_order_id differ in any field (size, filled qty, status, price, timestamps) — e.g. data changed between two provider queries within one reconciliation run.","commonSituations":"Order state advanced (partially filled -> filled) between paginated/incremental provider fetches inside one reconciliation pass; stale cached report replayed alongside fresh data; venue retroactively corrected an order record; concurrent reconciliation runs merging different snapshots.","solutions":["Log the diff between `*previous` and the new `order` snapshot to identify the diverging field, then re-fetch order reports in one consistent pass.","Ensure each reconciliation run sources all order reports from a single query window so the venue order state cannot shift mid-run.","Purge stale cached PolymarketOrderReport snapshots before reconciliation and rebuild from provider data.","If the venue legitimately amends order history, upgrade the adapter to a version that resolves amended snapshots deterministically."],"exampleFix":"// before: abort on divergent snapshots for one venue order\nanyhow::ensure!(\n    *previous == order,\n    \"provider venue order {} repeats with contradictory evidence\",\n    report.venue_order_id,\n);\n// after: keep the latest snapshot and log the divergence instead of failing the run\nif let Some(previous) = selected_orders.get(&report.venue_order_id) {\n    if *previous != order {\n        log::warn!(\n            \"Venue order {} snapshot changed ({:?} -> {:?}); using latest\",\n            report.venue_order_id, previous, order,\n        );\n    }\n}\nselected_orders.insert(report.venue_order_id.clone(), order);","handlingStrategy":"validation","validationCode":"let mut snapshots: AHashMap<Uuid, &PolymarketOrderReport> = AHashMap::new();\nfor order in fetched_order_reports() {\n    if let Some(prev) = snapshots.get(&order.venue_order_id) {\n        if *prev != order {\n            return Err(anyhow::anyhow!(\n                \"venue order {} snapshot changed; re-fetch all order reports in one pass\",\n                order.venue_order_id,\n            ));\n        }\n    } else {\n        snapshots.insert(order.venue_order_id, order);\n    }\n}","typeGuard":"fn is_identical_snapshot(prev: &&PolymarketOrderReport, next: &PolymarketOrderReport) -> bool {\n    *prev == next\n}","tryCatchPattern":"match reconciliation_result {\n    Err(e) if e.to_string().contains(\"provider venue order\") => {\n        log::warn!(\"order snapshot diverged mid-run; rebuilding from one consistent fetch\");\n        rebuild_order_reports();\n    }\n    other => other?,\n}","preventionTips":["Source all order reports for one reconciliation run from a single fetch window","Purge stale cached order snapshots before reconciliation","Avoid concurrent reconciliation runs writing different snapshots","Log snapshot diffs to catch venue-side corrections early"],"tags":["reconciliation","data-integrity","polymarket","duplicate-data"],"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"}