{"record":{"id":"d6b74ee4a5efc07a","repo":"nautechsystems/nautilus_trader","slug":"replacement-scan-cursor-timestamp-is-negative","errorCode":null,"errorMessage":"Replacement scan cursor timestamp is negative","messagePattern":"Replacement scan cursor timestamp is negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":6220,"sourceCode":"        .bind(chain_id)\n        .bind(wallet_address)\n        .bind(nonce)\n        .fetch_optional(&self.pool)\n        .await\n        .context(\"failed to load replacement scan cursor\")?;\n        row.map(\n            |(number, hash, parent_hash, timestamp, base_fee, stored_digest)| {\n                anyhow::ensure!(\n                    stored_digest == manifest_digest,\n                    \"Replacement scan manifest identity changed\"\n                );\n                Ok(ExecutionVerifiedHeader {\n                    number: u64::try_from(number)\n                        .context(\"Replacement scan cursor number is negative\")?,\n                    hash,\n                    parent_hash,\n                    timestamp: u64::try_from(timestamp)\n                        .context(\"Replacement scan cursor timestamp is negative\")?,\n                    base_fee_per_gas: base_fee\n                        .map(|value| {\n                            value.parse::<u128>().map_err(|_| {\n                                anyhow::anyhow!(\"Replacement scan cursor base fee is invalid\")\n                            })\n                        })\n                        .transpose()?,\n                })\n            },\n        )\n        .transpose()\n    }\n\n    pub(crate) async fn record_execution_replacement_scan(\n        &self,\n        scan: &ExecutionReplacementScan<'_>,\n    ) -> anyhow::Result<()> {\n        anyhow::ensure!(","sourceCodeStart":6202,"sourceCodeEnd":6238,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L6202-L6238","documentation":"Data-integrity check when loading the replacement scan cursor: the stored cursor row's timestamp column decoded to a negative value, which cannot be a valid Unix timestamp, so the cursor is rejected as corrupt.","triggerScenarios":"load_execution_replacement_cursor reads a row whose execution_verified_finalized_header.timestamp is negative and calls u64::try_from(timestamp).","commonSituations":"Corrupted or hand-edited rows; clock skew bugs in the writer producing negative values; schema/type confusion from external tooling.","solutions":["Inspect and fix or delete the row with the negative timestamp","Fix or re-run the writer that produced the negative timestamp","Re-record the replacement scan so a valid header is stored"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let ts: i64 = /* loaded timestamp */;\nif ts < 0 {\n    // corrupt row: purge and re-record the scan\n}","typeGuard":"fn valid_timestamp(ts: i64) -> bool { ts >= 0 }","tryCatchPattern":"match db.load_execution_replacement_cursor(..).await {\n    Err(e) if e.to_string().contains(\"cursor timestamp is negative\") => {\n        // delete corrupted row and re-run record_execution_replacement_scan\n    }\n    other => other,\n}","preventionTips":["Write timestamps only from trusted clock sources","Add CHECK (timestamp >= 0) constraints","Detect-and-rescan rather than trusting legacy rows after tooling changes"],"tags":["database","timestamp","data-corruption"],"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-14T05:17:10.506Z"}