{"record":{"id":"6d4e592ecf439611","repo":"nautechsystems/nautilus_trader","slug":"active-replacement-scan-intent-was-not-found","errorCode":null,"errorMessage":"Active replacement scan intent was not found","messagePattern":"Active replacement scan intent was not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":6291,"sourceCode":"            \"Replacement scan conflicts with the canonical nonce or manifest ledger\"\n        );\n        let current_status = sqlx::query_scalar::<_, String>(\n            \"\n            SELECT status\n            FROM execution_intent\n            WHERE id = $1 AND chain_id = $2 AND wallet_address = $3\n              AND nonce = $4 AND active\n            FOR UPDATE\n            \",\n        )\n        .bind(scan.intent_id)\n        .bind(chain_id)\n        .bind(scan.wallet_address)\n        .bind(nonce)\n        .fetch_optional(&mut *transaction)\n        .await\n        .context(\"failed to lock the replacement scan intent\")?\n        .ok_or_else(|| anyhow::anyhow!(\"Active replacement scan intent was not found\"))?;\n\n        if let Some(cursor) = scan.finalized_cursor {\n            let number = i64::try_from(cursor.number)\n                .context(\"Replacement scan cursor exceeds PostgreSQL BIGINT\")?;\n            let durable_hash = sqlx::query_scalar::<_, String>(\n                \"\n                SELECT hash\n                FROM execution_verified_finalized_header\n                WHERE chain_id = $1 AND wallet_address = $2 AND number = $3\n                \",\n            )\n            .bind(chain_id)\n            .bind(scan.wallet_address)\n            .bind(number)\n            .fetch_optional(&mut *transaction)\n            .await\n            .context(\"failed to validate replacement cursor against finalized headers\")?\n            .ok_or_else(|| {","sourceCodeStart":6273,"sourceCodeEnd":6309,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L6273-L6309","documentation":"After validating the nonce ledger, `record_execution_replacement_scan` locks the `execution_intent` row matching (intent_id, chain_id, wallet_address, nonce) that is still `active`, using `FOR UPDATE`. If no such row exists the scan has no live intent to attach evidence to, so the transaction fails with this error.","triggerScenarios":"Calling `record_execution_replacement_scan` with an `intent_id` that does not exist, that belongs to a different chain_id/wallet_address/nonce, or whose `active` flag is FALSE (already finalized, replaced, or deactivated).","commonSituations":"The intent was already marked replaced/recoverable by a prior scan run; a stale intent id was cached by the caller after an earlier scan completed; the scan payload was constructed against a re-keyed wallet or different chain.","solutions":["Confirm the intent still exists and `active = TRUE` in `execution_intent` for the exact (intent_id, chain_id, wallet_address, nonce) tuple.","Do not resubmit a scan for an intent that has already been finalized or replaced; treat this as a no-op in the caller.","Refresh the intent id from the current submission pipeline instead of reusing a cached one.","Check that the nonce bound to the intent matches the scan nonce."],"exampleFix":"// before: unconditional resubmission of a completed scan\nif let Err(e) = db.record_execution_replacement_scan(&scan).await { retry(e); }\n// after: check the intent is still active first\nif db.is_execution_intent_active(scan.intent_id).await? {\n    db.record_execution_replacement_scan(&scan).await?;\n}","handlingStrategy":"validation","validationCode":"let active = sqlx::query_scalar::<_, bool>(\"SELECT active FROM execution_intent WHERE id = $1 AND chain_id = $2 AND wallet_address = $3 AND nonce = $4\").bind(scan.intent_id).bind(chain_id).bind(scan.wallet_address).bind(scan.nonce as i64).fetch_optional(&pool).await?;\nif active != Some(true) { skip_scan(); }","typeGuard":"async fn intent_is_active(pool: &PgPool, intent_id: i64, chain_id: i32, wallet: &str, nonce: i64) -> anyhow::Result<bool> {\n    Ok(sqlx::query_scalar::<_, bool>(\"SELECT active FROM execution_intent WHERE id=$1 AND chain_id=$2 AND wallet_address=$3 AND nonce=$4\")\n        .bind(intent_id).bind(chain_id).bind(wallet).bind(nonce).fetch_optional(pool).await?.unwrap_or(false))\n}","tryCatchPattern":"match db.record_execution_replacement_scan(&scan).await {\n    Err(e) if e.to_string().contains(\"Active replacement scan intent was not found\") => info!(\"intent already finalized; skipping\"),\n    Err(e) => return Err(e),\n    Ok(()) => {},\n}","preventionTips":["Do not cache intent ids across scan runs; reload the active intent before each submission.","Treat a missing active intent as a terminal no-op, not a retryable failure.","Keep intent lifecycle transitions and scan submission in the same serialized pipeline."],"tags":["database","state-machine","entity-not-found"],"backgroundTag":"record-not-found","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"}