{"record":{"id":"92c41f0424c1650e","repo":"tursodatabase/turso","slug":"invalid-mvcc-logical-log-frame-magic-at-offset-of","errorCode":null,"errorMessage":"invalid MVCC logical log frame magic at offset {offset}: {frame_magic:#x}","messagePattern":"invalid MVCC logical log frame magic at offset (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cli/sync_server.rs","lineNumber":1154,"sourceCode":"            .try_into()\n            .expect(\"fixed-size salt slice\"),\n    );\n    Ok(crc32c::crc32c(&salt.to_le_bytes()))\n}\n\nfn read_mvcc_frame_boundary(\n    log: &[u8],\n    offset: usize,\n    running_crc: u32,\n) -> Result<Option<(usize, u32)>> {\n    if log.len() - offset < MVCC_TX_HEADER_SIZE + MVCC_TX_TRAILER_SIZE {\n        return Ok(None);\n    }\n    let frame_magic = read_u32_le(log, offset)?;\n    let has_extension_header = frame_magic == MVCC_TX_EXT_FRAME_MAGIC;\n    if frame_magic != MVCC_TX_FRAME_MAGIC && !has_extension_header {\n        return Err(anyhow!(\n            \"invalid MVCC logical log frame magic at offset {offset}: {frame_magic:#x}\"\n        ));\n    }\n    let header_size = if has_extension_header {\n        MVCC_TX_EXT_HEADER_SIZE\n    } else {\n        MVCC_TX_HEADER_SIZE\n    };\n    if log.len() - offset < header_size + MVCC_TX_TRAILER_SIZE {\n        return Ok(None);\n    }\n    let payload_size = usize::try_from(read_u64_le(log, offset + 4)?)\n        .map_err(|_| anyhow!(\"MVCC logical log payload size overflows usize\"))?;\n    let extension_size = if has_extension_header {\n        let extension_size = usize::try_from(read_u64_le(log, offset + 24)?)\n            .map_err(|_| anyhow!(\"MVCC logical log extension size overflows usize\"))?;\n        let extension_record_count = read_u32_le(log, offset + 32)?;\n        let frame_flags = read_u32_le(log, offset + 36)?;\n        if frame_flags & !MVCC_TX_FRAME_FLAG_HAS_EXTENSION_BLOCK != 0 {","sourceCodeStart":1136,"sourceCodeEnd":1172,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/sync_server.rs#L1136-L1172","documentation":"While walking frames, read_mvcc_frame_boundary requires the u32 at the current offset to be either MVCC_TX_FRAME_MAGIC or MVCC_TX_EXT_FRAME_MAGIC. A different value means the walk landed on bytes that are not a frame start. Note the distinction: a torn final frame (not enough bytes for header+trailer) returns Ok(None) and the scan stops cleanly, so this error means the bytes are present but wrong - real mid-log corruption, not truncation.","triggerScenarios":"scan_mvcc_log iterates offsets after the 56-byte header; at some offset the first u32 is neither frame magic - e.g. garbage appended to the log, a frame overwritten mid-way, or a payload-size error in a previous frame that desynced the walk.","commonSituations":"Two processes appending to the same logical log concurrently; a crash mid-append followed by an unrelated write; copying the log with a tool that altered bytes; disk-level corruption.","solutions":["Restore the MVCC log from a known-good backup","Regenerate the log (delete + resync via replace-base fallback)","Ensure exactly one sync-server process owns the log file and writes are atomic (write to temp, fsync, rename/append)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match scan_mvcc_log(&log) {\n    Ok(snapshot) => serve(snapshot),\n    Err(err) if err.to_string().starts_with(\"invalid MVCC logical log frame magic\") => {\n        warn!(\"mid-log corruption at {}: {err}\", err);\n        // truncate to last known-good prefix is NOT safe to improvise:\n        // restore from backup or regenerate the log\n        restore_or_rebuild()?;\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Guarantee single-writer ownership of the log file (one sync-server process)","Append frames atomically and fsync before advertising the new length","Do not copy a log while it is actively being appended"],"tags":["mvcc","sync-server","frame","magic","corruption"],"backgroundTag":"invalid-magic-number","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}