{"record":{"id":"5f4ed7bd7324f9ba","repo":"nautechsystems/nautilus_trader","slug":"stored-execution-payload-has-a-truncated-envelope","errorCode":null,"errorMessage":"Stored execution payload has a truncated envelope header","messagePattern":"Stored execution payload has a truncated envelope header","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":7551,"sourceCode":"    );\n    Ok(())\n}\n\nasync fn validate_execution_payload_key_inventory(\n    transaction: &mut Transaction<'_, Postgres>,\n    keys: &PayloadKeySet,\n) -> anyhow::Result<()> {\n    let envelopes = sqlx::query_scalar::<_, Vec<u8>>(\n        \"SELECT DISTINCT substring(sealed_transaction FROM 1 FOR 33) \\\n         FROM execution_transaction_hash \\\n         WHERE sealed_transaction IS NOT NULL\",\n    )\n    .fetch_all(&mut **transaction)\n    .await\n    .context(\"failed to inspect execution payload key inventory\")?;\n\n    for header in envelopes {\n        anyhow::ensure!(\n            header.len() == 33,\n            \"Stored execution payload has a truncated envelope header\"\n        );\n        let mut envelope = header;\n        envelope.extend_from_slice(&[0; 12 + 16]);\n        let key_id = envelope_key_id(&envelope)?;\n        anyhow::ensure!(\n            keys.contains_key(&key_id),\n            \"Stored execution payload requires unavailable key {}\",\n            alloy::hex::encode(key_id)\n        );\n    }\n    Ok(())\n}\n\nasync fn load_execution_intent(\n    transaction: &mut Transaction<'_, Postgres>,\n    intent_id: i64,","sourceCodeStart":7533,"sourceCodeEnd":7569,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L7533-L7569","documentation":"During key-inventory inspection the code reads stored envelope headers and requires each to be exactly 33 bytes (a version/type byte plus a 32-byte key ID). A shorter header means the stored envelope blob is corrupt or was written by an incompatible writer, so processing cannot proceed safely.","triggerScenarios":"Running the key inventory validation when any stored execution payload envelope header in the database is shorter than 33 bytes.","commonSituations":"Corrupted rows from a partial write or crash; manual edits/truncated imports of the payload tables; restoring data from an incompatible backup or an older schema.","solutions":["Identify and repair or delete the corrupt envelope row(s) in the execution payload tables","Rebuild the cache/database from a known-good source if corruption is widespread","Confirm the data was restored from a backup produced by a compatible software version"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for header in stored_envelope_headers() {\n    if header.len() != 33 {\n        flag_corrupt_row(header); // quarantine and repair before validation\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never manually edit or import rows into payload tables","Restore data only from backups made by a compatible version","Monitor for partial writes/crashes and verify DB integrity after incidents"],"tags":["database","rust","data-corruption"],"backgroundTag":"unexpected-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"}