{"record":{"id":"d986611c1464fd9e","repo":"nautechsystems/nautilus_trader","slug":"invalid-o-format-broker-client-order-id-payload-le","errorCode":null,"errorMessage":"invalid O-format broker client order ID payload length","messagePattern":"invalid O-format broker client order ID payload length","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/common/encoder.rs","lineNumber":240,"sourceCode":") -> anyhow::Result<ClientOrderId> {\n    let decoded = decode_broker_id_checked(encoded, broker_id)?;\n    ClientOrderId::new_checked(decoded)\n        .with_context(|| format!(\"invalid Binance client order ID '{encoded}'\"))\n}\n\nfn decode_broker_id_checked(encoded: &str, broker_id: &str) -> anyhow::Result<String> {\n    let prefix = broker_prefix(broker_id);\n    let Some(payload) = encoded.strip_prefix(&prefix) else {\n        return Ok(encoded.to_string());\n    };\n\n    let Some((&signal, data)) = payload.as_bytes().split_first() else {\n        anyhow::bail!(\"missing broker client order ID signal\");\n    };\n\n    match signal {\n        SIGNAL_O_HYPHENS | SIGNAL_O_NO_HYPHENS => {\n            anyhow::ensure!(\n                data.len() == O_FORMAT_B62_LEN,\n                \"invalid O-format broker client order ID payload length\"\n            );\n            let packed = decode_base62(data).context(\"invalid O-format broker client order ID\")?;\n            Ok(unpack_o_format(packed, signal == SIGNAL_O_HYPHENS))\n        }\n        SIGNAL_UUID_HYPHENS | SIGNAL_UUID_NO_HYPHENS => {\n            anyhow::ensure!(\n                data.len() == UUID_B62_LEN,\n                \"invalid UUID broker client order ID payload length\"\n            );\n            let value = decode_base62(data).context(\"invalid UUID broker client order ID\")?;\n            Ok(format_uuid(value, signal == SIGNAL_UUID_HYPHENS))\n        }\n        SIGNAL_RAW => {\n            let raw = std::str::from_utf8(data).context(\"invalid raw broker client order ID\")?;\n            anyhow::ensure!(\n                !raw.is_empty(),","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/common/encoder.rs#L222-L258","documentation":"Decoding a broker-prefixed client order ID whose signal byte marks the packed 'O-format' payload: the base62 characters after the signal must be exactly O_FORMAT_B62_LEN long. The observed payload length differs, so the packed representation cannot be unpacked into the original ID.","triggerScenarios":"An ID that starts with the broker prefix and carries an O-format signal byte but whose payload was truncated or extended - e.g. a foreign ID colliding with the prefix+signal, storage truncation at Binance's clientOrderId limit, or IDs produced by a different encoder version with another format length.","commonSituations":"Mixed adapter versions writing and reading the same orders; externally generated order IDs that coincidentally begin with prefix+signal; corrupted captured data being replayed.","solutions":["Ensure the same adapter version encoded and decodes the ID (format lengths changed across versions - align writer and reader)","Use a longer, distinctive broker_id so foreign IDs cannot collide with prefix+signal","Verify the ID was not truncated in transit or storage (Binance caps clientOrderId length)"],"exampleFix":"// before: mixing an old capture with a new decoder\nlet cid = decode_broker_id_checked(&stored_id, \"BNB\")?;\n\n// after: re-encode with the current adapter and re-store\nlet cid = ClientOrderId::new(stored_id.clone()); // accept as opaque raw value","handlingStrategy":"type-guard","validationCode":"fn is_valid_o_format(id: &str, prefix: &str, o_len: usize) -> bool {\n    match id.strip_prefix(prefix) {\n        Some(p) if !p.is_empty() => &p[1..].len() == o_len,\n        _ => true, // not ours / signal-less: pass through\n    }\n}","typeGuard":"fn looks_like_adapter_o_id(id: &str, prefix: &str, o_b62_len: usize) -> bool {\n    id.strip_prefix(prefix)\n        .is_some_and(|p| p.len() == 1 + o_b62_len)\n}","tryCatchPattern":"if let Err(e) = decode_broker_id_checked(encoded, broker_id) {\n    log::warn!(\"unparseable broker ID '{encoded}' (possible version mismatch): {e}\");\n    // fall back to opaque handling, keep order flow alive\n}","preventionTips":["Pin writer and reader adapter versions in deployments that share order state","Version your ID encoding if you persist it beyond the adapter's own storage","Treat decode failures as data-quality warnings with the raw ID preserved in logs"],"tags":["binance","order-ids","client-order-id","base62","encoding"],"backgroundTag":"identifier-decode-failed","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}