{"record":{"id":"a86c2a6711faca03","repo":"nautechsystems/nautilus_trader","slug":"venue-order-venue-order-id-has-contradictory-cli","errorCode":null,"errorMessage":"venue order {venue_order_id} has contradictory client associations {known} and {candidate}","messagePattern":"venue order (.+?) has contradictory client associations (.+?) and (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reports.rs","lineNumber":117,"sourceCode":"    fn resolve_target_order_authority(\n        &self,\n        explicit_client_order_id: Option<ClientOrderId>,\n        venue_order_id: VenueOrderId,\n        requested_instrument_id: Option<InstrumentId>,\n    ) -> anyhow::Result<TargetOrderAuthority> {\n        let context = self.order_contexts.get(&venue_order_id);\n        let cached_client_order_id = self.core.cache().client_order_id(&venue_order_id).copied();\n\n        let mut client_order_id = explicit_client_order_id;\n        for candidate in [\n            context.map(|value| value.identity.client_order_id),\n            cached_client_order_id,\n        ]\n        .into_iter()\n        .flatten()\n        {\n            if let Some(known) = client_order_id {\n                anyhow::ensure!(\n                    candidate == known,\n                    \"venue order {venue_order_id} has contradictory client associations {known} and {candidate}\",\n                );\n            } else {\n                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","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reports.rs#L99-L135","documentation":"`resolve_target_order_authority` collects every client-order-id candidate associated with a venue order (report payload, cached index, cached order). The first candidate fixes the association; any subsequent candidate that differs means the venue order is linked to two different client orders, which would make report routing ambiguous, so the adapter fails with `anyhow::ensure!`.","triggerScenarios":"Raised in `resolve_target_order_authority` (called by query_order_command, generate_order_status_report_impl, generate_fill_reports_impl) when, for one venue_order_id, at least two distinct client_order_ids are derivable — e.g. a venue order id was reused across strategy restarts with fresh client ids, a client id collided, or cached index entries disagree with the incoming report.","commonSituations":"Reusing the same Polymarket venue order across strategy instances that each minted a different client_order_id; restoring a cache partially so the index and cached order disagree; client_order_id generation not unique after restart; manually replaying archived reports with remapped client ids.","solutions":["Inspect the two reported client ids ({known} and {candidate}) in the message and purge the stale/incorrect association from the execution cache for that venue_order_id.","Make client_order_id generation deterministic or collision-free across restarts (e.g. derive from venue order id or use a persistent UUID source) so reloaded orders keep their original association.","Run reconciliation/cache rebuild so cached index and cached order agree before querying order status or fill reports for that venue order.","If reports were replayed with remapped client ids, re-ingest with the original client_order_id mapping intact."],"exampleFix":"// before: nondeterministic client ids per run cause contradictory associations\nclient_order_id = self.order_factory.generate_client_order_id()  // new each restart\n// after: stable mapping so a venue order always resolves to one client id\nclient_order_id = persisted_mapping.get(venue_order_id)\n    or self.order_factory.generate_client_order_id();\npersisted_mapping.insert(venue_order_id, client_order_id);","handlingStrategy":"validation","validationCode":"candidates = {\n    report.client_order_id,\n    cache.client_order_id_for_venue_order(venue_order_id),\n    cached_order.client_order_id if cached_order else None,\n} - {None}\nif len(candidates) > 1:\n    raise ValueError(\n        f\"venue order {venue_order_id} maps to multiple client ids {candidates}; \"\n        \"rebuild cache before querying reports\"\n    )","typeGuard":"def has_unambiguous_client_association(venue_order_id, cache) -> bool:\n    candidates = {\n        cid for cid in (\n            cache.client_order_id_for_venue_order(venue_order_id),\n        )\n        if cid is not None\n    }\n    return len(candidates) <= 1","tryCatchPattern":"try:\n    reports = client.generate_order_status_reports(venue_order_id=venue_order_id)\nexcept Exception as e:\n    if \"contradictory client associations\" in str(e):\n        log.error(\"venue order %s linked to multiple client ids; \"\n                  \"purge stale cache entry or make client ids stable across restarts\", venue_order_id)\n    raise","preventionTips":["Make client_order_id generation deterministic or collision-free across restarts","Persist the venue_order_id -> client_order_id mapping alongside the cache","Rebuild/reconcile the execution cache fully after restarts so index and cached orders agree","Never replay archived reports with remapped client ids"],"tags":["polymarket","order-cache","client-order-id","report-generation"],"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"}