{"record":{"id":"c80b378ce178f1c7","repo":"nautechsystems/nautilus_trader","slug":"execution-payload-batch-size-must-be-positive","errorCode":null,"errorMessage":"Execution payload batch size must be positive","messagePattern":"Execution payload batch size must be positive","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":4895,"sourceCode":"             ON CONFLICT (key_id) DO NOTHING\",\n        )\n        .bind(keys.active_key_id().as_slice())\n        .execute(&mut *transaction)\n        .await\n        .context(\"failed to initialize execution payload key state\")?;\n        transaction\n            .commit()\n            .await\n            .context(\"failed to commit execution payload activation\")?;\n        Ok(())\n    }\n\n    async fn migrate_execution_payload_batch(\n        &self,\n        keys: &PayloadKeySet,\n        batch_size: i64,\n    ) -> anyhow::Result<bool> {\n        anyhow::ensure!(\n            batch_size > 0,\n            \"Execution payload batch size must be positive\"\n        );\n        let mut transaction = self\n            .pool\n            .begin()\n            .await\n            .context(\"failed to start execution payload migration batch\")?;\n        lock_execution_payload_operation(&mut transaction).await?;\n        let state_row = sqlx::query(\n            \"SELECT deployment_id, protocol_version, operation, active_key_id \\\n             FROM execution_payload_state WHERE component = 'signed_transactions' FOR UPDATE\",\n        )\n        .fetch_optional(&mut *transaction)\n        .await\n        .context(\"failed to lock execution payload migration state\")?\n        .ok_or_else(|| anyhow::anyhow!(\"Execution payload migration state is missing\"))?;\n        let state = execution_payload_state_from_row(&state_row)?;","sourceCodeStart":4877,"sourceCodeEnd":4913,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L4877-L4913","documentation":"migrate_execution_payload_batch validates its batch_size parameter before opening a transaction. Migration proceeds in bounded batches, so a non-positive batch size is a caller programming error rejected up front with anyhow::ensure!.","triggerScenarios":"Calling migrate_execution_payload_batch with batch_size <= 0 (e.g. 0, or a negative value from a misparsed config or an integer underflow when computing remaining work).","commonSituations":"Config file with migrate_batch_size: 0; computing batch_size as remaining - processed when remaining <= processed; wiring a signed value from the wrong source.","solutions":["Pass a positive batch size (>= 1); clamp or validate the value at the call site","Fix the config/source supplying batch_size so it cannot be zero or negative","Use .max(1) or a checked computation when deriving batch_size from counters"],"exampleFix":"// before\nlet migrated = db.migrate_execution_payload_batch(&keys, batch_size).await?;\n// after\nlet batch_size = batch_size.max(1);\nlet migrated = db.migrate_execution_payload_batch(&keys, batch_size).await?;","handlingStrategy":"validation","validationCode":"fn validate_batch_size(batch_size: i64) -> Result<i64, String> {\n    if batch_size > 0 { Ok(batch_size) } else { Err(format!(\"batch_size must be positive, got {batch_size}\")) }\n}","typeGuard":"fn is_positive_batch(n: i64) -> bool { n > 0 }","tryCatchPattern":"let batch_size = validate_batch_size(cfg.migrate_batch_size).map_err(anyhow::Error::msg)?;\nlet done = db.migrate_execution_payload_batch(&keys, batch_size).await?;","preventionTips":["Validate config-driven batch sizes at load time","Use non-zero defaults and reject zero/negative config values eagerly","When deriving batch size from counters, clamp with .max(1)"],"tags":["argument-validation","migration"],"backgroundTag":"invalid-argument-value","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"}