{"record":{"id":"adc8aa59e5b324de","repo":"nautechsystems/nautilus_trader","slug":"ax-fills-total-count-must-be-non-negative-was-to","errorCode":null,"errorMessage":"AX fills total_count must be non-negative, was {total_count}","messagePattern":"AX fills total_count must be non-negative, was (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/http/client.rs","lineNumber":2242,"sourceCode":"\n            anyhow::ensure!(\n                page_len <= PAGE_SIZE as usize,\n                \"AX fills page length {page_len} exceeds requested limit {PAGE_SIZE}\"\n            );\n\n            if let Some(limit) = response.limit {\n                anyhow::ensure!(\n                    (0..=PAGE_SIZE).contains(&limit),\n                    \"AX fills applied limit must be between 0 and {PAGE_SIZE}, was {limit}\"\n                );\n                anyhow::ensure!(\n                    page_len <= limit as usize,\n                    \"AX fills page length {page_len} exceeds applied limit {limit}\"\n                );\n            }\n\n            if let Some(total_count) = response.total_count {\n                anyhow::ensure!(\n                    total_count >= 0,\n                    \"AX fills total_count must be non-negative, was {total_count}\"\n                );\n\n                if let Some(expected) = expected_total {\n                    anyhow::ensure!(\n                        total_count == expected,\n                        \"AX fills total_count changed during pagination: expected {expected}, was {total_count}\"\n                    );\n                } else {\n                    expected_total = Some(total_count);\n                }\n            }\n\n            for fill in response.fills {\n                anyhow::ensure!(\n                    seen_trade_ids.insert(fill.trade_id.clone()),\n                    \"AX fills pagination returned duplicate trade ID {}\",","sourceCodeStart":2224,"sourceCodeEnd":2260,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/http/client.rs#L2224-L2260","documentation":"When the AX fills response includes `total_count`, the client requires it to be non-negative before using it as the pagination denominator. A negative total_count is a malformed server response and would make the consistency checks (equality with accumulated rows) meaningless, so the fetch is aborted.","triggerScenarios":"A fills page response whose `total_count` field is negative (e.g. -1) — typically a server sentinel or serialization bug — passed to the fills paginator.","commonSituations":"Backend uses -1 as a 'count unknown' sentinel; integer underflow in the AX service counter; corrupted JSON numeric field produced by a proxy or middleware.","solutions":["Dump the raw response JSON and confirm the negative total_count; if it's a sentinel, the server should omit the field instead.","Report the malformed total_count to the AX service team; the client cannot paginate reliably without a valid count.","Retry without expecting total_count (server omitting the field skips this check) once the server bug is fixed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.paginate_fills(params).await {\n    Ok(fills) => apply(fills),\n    Err(e) if e.to_string().contains(\"total_count must be non-negative\") => {\n        error!(\"AX returned malformed total_count; aborting fills sync\");\n        Err(e)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Treat negative server counts as a backend bug and alert the AX service team.","Sanity-check raw responses in a proxy during incidents.","Prefer API versions where unknown counts are omitted rather than sentineled."],"tags":["rust","pagination","validation","http-client"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}