{"record":{"id":"ba594df2266a079a","repo":"nautechsystems/nautilus_trader","slug":"ax-open-orders-total-count-must-be-non-negative-w","errorCode":null,"errorMessage":"AX open-orders total_count must be non-negative, was {}","messagePattern":"AX open-orders 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":1997,"sourceCode":"        let mut offset = 0_i64;\n        let mut expected_total = None;\n\n        loop {\n            let request_offset = i32::try_from(offset)\n                .context(\"AX open-orders offset exceeds the documented int32 range\")?;\n            let params = GetOpenOrdersParams {\n                account_id: None,\n                limit: Some(PAGE_SIZE),\n                offset: Some(request_offset),\n                sort_ts: Some(\"desc\".to_string()),\n            };\n            let response = self\n                .inner\n                .get_open_orders_page(&params)\n                .await\n                .map_err(|e| anyhow::anyhow!(e))?;\n\n            anyhow::ensure!(\n                response.total_count >= 0,\n                \"AX open-orders total_count must be non-negative, was {}\",\n                response.total_count\n            );\n            anyhow::ensure!(\n                response.limit >= 0 && response.limit <= PAGE_SIZE,\n                \"AX open-orders applied limit must be between 0 and {PAGE_SIZE}, was {}\",\n                response.limit\n            );\n            anyhow::ensure!(\n                i64::from(response.offset) == offset,\n                \"AX open-orders response offset mismatch: requested {offset}, was {}\",\n                response.offset\n            );\n\n            let total_count = *expected_total.get_or_insert(response.total_count);\n            anyhow::ensure!(\n                response.total_count == total_count,","sourceCodeStart":1979,"sourceCodeEnd":2015,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/http/client.rs#L1979-L2015","documentation":"A defensive invariant check on a paginated open-orders response: the venue-reported total_count must be non-negative. anyhow::ensure! aborts the open-orders aggregation loop if AX returns a negative value, which would otherwise corrupt pagination termination logic. This indicates a malformed or semantically invalid API response rather than a request failure.","triggerScenarios":"Calling the paginated open-orders fetch when AX returns a page whose total_count field is negative — only possible if the response schema/serialization changed or a proxy/gateway returned unexpected body content.","commonSituations":"AX API version change altering the response schema; a misbehaving gateway or mock server returning placeholder values; deserializing an unrelated error body into the page struct due to a wrong endpoint or content-type.","solutions":["Check whether the AX API version changed and update the client's response models.","Dump the raw response body to see what was actually returned.","Confirm the request hit the correct open-orders endpoint (not an error page deserialized as a page).","Report the malformed response to the AX venue/adapter maintainers if the API is unchanged."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// after receiving a page, check invariants yourself\nif response.total_count < 0 {\n    return Err(anyhow!(\"malformed AX page: negative total_count {}\", response.total_count));\n}","typeGuard":null,"tryCatchPattern":"match client.request_open_orders_paged().await {\n    Ok(orders) => orders,\n    Err(e) if e.to_string().contains(\"total_count\") => {\n        tracing::error!(\"AX returned malformed open-orders page: {e:#}\");\n        Vec::new() // or surface a schema-drift alert\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Pin the AX API version the adapter was built against and verify on deploy.","Log raw response bodies on validation failures for post-mortem.","Alert on schema-invariant failures — they indicate venue/API drift, not transient faults.","Use mock servers that replay real captured AX responses, not hand-made ones."],"tags":["pagination","schema","invariant","api-client"],"backgroundTag":"schema-validation-failed","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"}