{"record":{"id":"1020b8d105f81127","repo":"nautechsystems/nautilus_trader","slug":"execution-payload-has-no-envelope-during-rewrap","errorCode":null,"errorMessage":"Execution payload {} has no envelope during rewrap","messagePattern":"Execution payload (.+?) has no envelope during rewrap","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":5490,"sourceCode":"                \"Execution payload rewrap left {remaining} row(s)\"\n            );\n            sqlx::query(\n                \"UPDATE execution_payload_state SET operation = 'ready', updated_at = NOW() \\\n                 WHERE component = 'signed_transactions' AND operation = 'rewrap'\",\n            )\n            .execute(&mut *transaction)\n            .await\n            .context(\"failed to mark execution payload rewrap complete\")?;\n            transaction\n                .commit()\n                .await\n                .context(\"failed to commit execution payload rewrap completion\")?;\n            return Ok(true);\n        }\n\n        for hash in rows {\n            let envelope = hash.sealed_transaction.as_deref().ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Execution payload {} has no envelope during rewrap\",\n                    hash.id\n                )\n            })?;\n            anyhow::ensure!(\n                hash.raw_transaction.is_none(),\n                \"Execution payload {} contains plaintext during rewrap\",\n                hash.id\n            );\n            let intent = load_execution_intent(&mut transaction, hash.intent_id).await?;\n            let context = payload_context(&intent, &hash, keys.deployment_id())?;\n            let raw_transaction = keys.unseal(envelope, &context)?;\n            authenticate_retained_payload(&raw_transaction, &intent, &hash, keys.deployment_id())?;\n            reserve_execution_payload_seal(&mut transaction, keys.active_key_id()).await?;\n            let rewrapped = keys.seal(&raw_transaction, &context)?;\n            let verified = keys.unseal(&rewrapped, &context)?;\n            authenticate_retained_payload(&verified, &intent, &hash, keys.deployment_id())?;\n            anyhow::ensure!(","sourceCodeStart":5472,"sourceCodeEnd":5508,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L5472-L5508","documentation":"While rewrapping, each row selected for rewrap must have a sealed envelope in `sealed_transaction` to unseal and re-seal under the new key. This error fires when a row in the batch has `payload_expected=true` but `sealed_transaction IS NULL`, so there is no envelope to rewrap. The library treats this as unrecoverable data corruption rather than silently skipping the payload.","triggerScenarios":"A row matched the batch query but has a NULL `sealed_transaction` — possible when the row is mutated between the batch SELECT and processing, or when data was written by a path that marked `payload_expected` without storing a sealed envelope; also when the verification SELECT (with its OR `sealed_transaction IS NULL` clause) and the batch SELECT disagree on NULL-envelope rows due to concurrent modification.","commonSituations":"A crashed writer inserted rows with `payload_expected=true` but never populated `sealed_transaction`; a restore/ETL backfill left envelopes NULL; concurrent transactions cleared `sealed_transaction` while the rewrap loop held the batch rows FOR UPDATE but the row was updated in a window not covered by the lock.","solutions":["Locate the corrupt row by id (included in the message) and inspect its `sealed_transaction`, `raw_transaction`, and `payload_expected` values.","Restore the envelope from a backup or source of truth, or re-create the payload: fetch the plaintext transaction and seal it under the active key before re-running the rewrap.","If the row should not have a payload at all, set `payload_expected=false` so it is excluded from rewrap batches.","Fix the writer path that produced payload_expected rows without envelopes, then retry the rewrap."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let bad: Vec<i64> = sqlx::query_scalar(\"SELECT id FROM execution_transaction_hash WHERE payload_expected AND sealed_transaction IS NULL\")\n    .fetch_all(&pool).await?;\nif !bad.is_empty() {\n    // remediate (re-seal or set payload_expected=false) before starting a rewrap\n}","typeGuard":null,"tryCatchPattern":"match rewrap_result {\n    Err(e) if e.to_string().contains(\"has no envelope during rewrap\") => {\n        // parse row id from message, restore/re-seal or clear payload_expected, then retry\n    },\n    other => other?,\n}","preventionTips":["Enforce a DB CHECK/NOT NULL constraint pattern: rows with payload_expected=true must have sealed_transaction (via trigger or application invariant).","Backfill/restores must seal envelopes under the active key before committing payload_expected rows.","Run the NULL-envelope pre-check above before every rewrap window.","Watch for crashed writers: alert on rows that have payload_expected but NULL envelope older than a threshold."],"tags":["database","data-integrity","encryption","null-value","rust"],"backgroundTag":"empty-required-field","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"}