{"record":{"id":"7d887db78e4be6aa","repo":"nautechsystems/nautilus_trader","slug":"ax-open-orders-total-count-changed-during-paginati","errorCode":null,"errorMessage":"AX open-orders total_count changed during pagination: expected {total_count}, was {}","messagePattern":"AX open-orders total_count changed during pagination: expected (.+?), was (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/adapters/architect_ax/src/http/client.rs","lineNumber":2014,"sourceCode":"\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,\n                \"AX open-orders total_count changed during pagination: expected {total_count}, was {}\",\n                response.total_count\n            );\n\n            let page_len = i64::try_from(response.orders.len())\n                .context(\"AX open-orders page length exceeds i64\")?;\n            anyhow::ensure!(\n                page_len <= i64::from(response.limit),\n                \"AX open-orders page length {page_len} exceeds applied limit {}\",\n                response.limit\n            );\n            let next_offset = offset\n                .checked_add(page_len)\n                .context(\"AX open-orders offset overflow\")?;\n            anyhow::ensure!(\n                next_offset <= total_count,\n                \"AX open-orders page exceeds total_count: next offset {next_offset}, total {total_count}\"","sourceCodeStart":1996,"sourceCodeEnd":2032,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/http/client.rs#L1996-L2032","documentation":"The Architect AX open-orders paginated fetch tracks the total_count advertised on the first page and asserts every subsequent page reports the same value. If the venue's total changes between page requests, the client aborts rather than return an inconsistent, possibly duplicated or missing, order snapshot. This is an integrity guard for concurrent state churn during offset-based pagination.","triggerScenarios":"The venue order book mutates between page fetches: an order is created, canceled, or filled while the client pages through open orders, so a later page's total_count differs from the first page's.","commonSituations":"Active trading periods where orders are placed/canceled mid-poll; polling open orders for an account whose automation runs concurrently; slow multi-page fetches over a fast-moving book.","solutions":["Retry the full pagination loop from offset 0 to capture a consistent snapshot","Reduce polling frequency or fetch during quieter periods","Fetch with a larger page size to complete pagination in fewer round trips and shrink the mutation window","Check for bots/strategies concurrently mutating orders on the same account"],"exampleFix":"// before\nlet page = client.open_orders_paginated().await?; // fails if book churns mid-page\n// after\nlet page = retry_with_backoff(3, || async {\n    client.open_orders_paginated().await\n}).await?; // restart pagination on consistency failure","handlingStrategy":"retry","validationCode":"// Ensure snapshot consistency by re-running pagination on failure\nasync fn fetch_with_retry<F, T>(mut f: F, attempts: u32) -> anyhow::Result<T>\nwhere F: FnMut() -> anyhow::Result<T> {\n    for _ in 0..attempts {\n        match f() {\n            Ok(v) => return Ok(v),\n            Err(e) if e.to_string().contains(\"total_count changed\") => continue,\n            Err(e) => return Err(e),\n        }\n    }\n    anyhow::bail(\"pagination never reached a consistent snapshot\")\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"total_count changed during pagination\") => restart_pagination(),\n    Err(e) => return Err(e),\n    Ok(orders) => use(orders),\n}","preventionTips":["Retry the entire pagination from offset 0 rather than resuming mid-way","Increase page size so pagination completes in fewer round trips","Avoid placing/canceling orders from the same account while polling open orders","Poll during low-activity windows"],"tags":["pagination","http","consistency"],"backgroundTag":"unexpected-api-response-shape","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"}