{"record":{"id":"bc2a1267a85408ce","repo":"spacedriveapp/spacedrive","slug":"byte-count-mismatch-expected-got","errorCode":null,"errorMessage":"Byte count mismatch: expected {}, got {}","messagePattern":"Byte count mismatch: expected (.+?), got (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/ops/files/copy/strategy.rs","lineNumber":689,"sourceCode":"\t\t\t\t\t\tcb(total_bytes_received, file_size);\n\t\t\t\t\t}\n\n\t\t\t\t\tif chunk_index % 100 == 0 {\n\t\t\t\t\t\tctx.log(format!(\n\t\t\t\t\t\t\t\"PULL progress: chunk {}, {} / {} bytes\",\n\t\t\t\t\t\t\tchunk_index, total_bytes_received, file_size\n\t\t\t\t\t\t));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcrate::service::network::protocol::file_transfer::FileTransferMessage::TransferComplete {\n\t\t\t\t\tfinal_checksum,\n\t\t\t\t\ttotal_bytes,\n\t\t\t\t\t..\n\t\t\t\t} => {\n\t\t\t\t\t// Verify byte count first\n\t\t\t\t\tif total_bytes != total_bytes_received {\n\t\t\t\t\t\tlet _ = fs::remove_file(&final_dest_path).await;\n\t\t\t\t\t\treturn Err(anyhow::anyhow!(\n\t\t\t\t\t\t\t\"Byte count mismatch: expected {}, got {}\",\n\t\t\t\t\t\t\ttotal_bytes,\n\t\t\t\t\t\t\ttotal_bytes_received\n\t\t\t\t\t\t));\n\t\t\t\t\t}\n\n\t\t\t\t\t// Verify final checksum if enabled\n\t\t\t\t\tif verify_checksum {\n\t\t\t\t\t\tif let Some(h) = hasher.take() {\n\t\t\t\t\t\t\tlet calculated = h.finalize();\n\t\t\t\t\t\t\tlet calculated_hex = calculated.to_hex().to_string();\n\n\t\t\t\t\t\t\tif final_checksum.is_empty() {\n\t\t\t\t\t\t\t\t// Warn when checksum verification enabled but no checksum provided\n\t\t\t\t\t\t\t\tctx.log(\"Warning: checksum verification enabled but remote did not provide checksum\".to_string());\n\t\t\t\t\t\t\t} else if calculated_hex != final_checksum {\n\t\t\t\t\t\t\t\terror!(\n\t\t\t\t\t\t\t\t\t\"Final checksum mismatch: expected {}, got {}\",","sourceCodeStart":671,"sourceCodeEnd":707,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/files/copy/strategy.rs#L671-L707","documentation":"The peer's TransferComplete message declared total_bytes, but the sum of received chunk lengths differs (strategy.rs:686-694) — chunks were lost, duplicated, or the accounting desynchronized. The partial destination file is removed and the transfer fails as a unit; nothing partial is kept.","triggerScenarios":"A chunk message skipped or double-processed after a stream hiccup; sender and receiver computing byte totals differently (version mismatch); loop exiting early on a misdetected EOF ('finish'/'closed') before a late TransferComplete arrives.","commonSituations":"Mixed daemon versions during upgrade; flaky connections producing partial reads; large multi-chunk transfers where one stream event desyncs the count.","solutions":["Retry the full pull — the mismatch is fatal to this attempt and cleanup already ran","Confirm identical versions on both devices so byte accounting matches","If it recurs, log received chunk indices vs expected to find where the count diverges","Check whether an EOF-like stream error (containing 'finish'/'closed') interleaved before completion"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match remote_strategy.execute_pull(ctx, &src, &dst).await {\n    Ok(n) => Ok(n),\n    Err(e) if e.to_string().starts_with(\"Byte count mismatch\") => {\n        // partial file already removed; a fresh retry re-establishes clean accounting\n        remote_strategy.execute_pull(ctx, &src, &dst).await\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Retry the whole pull on byte-count mismatch — desync is usually transient","Keep daemon versions identical so total_bytes accounting matches","Log chunk indices received when mismatches recur to locate the divergence"],"tags":["rust","spacedrive","pull","byte-count","integrity","file-transfer"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}