{"record":{"id":"929e67c8b133c952","repo":"spacedriveapp/spacedrive","slug":"expected-transferfinalack-got-different-message-t","errorCode":null,"errorMessage":"Expected TransferFinalAck, got different message type","messagePattern":"Expected TransferFinalAck, got different message type","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/ops/files/copy/strategy.rs","lineNumber":1307,"sourceCode":"\tlet mut len_buf = [0u8; 4];\n\trecv_stream.read_exact(&mut len_buf).await?;\n\tlet msg_len = u32::from_be_bytes(len_buf) as usize;\n\n\tlet mut msg_buf = vec![0u8; msg_len];\n\trecv_stream.read_exact(&mut msg_buf).await?;\n\n\tlet ack_message: crate::service::network::protocol::file_transfer::FileTransferMessage =\n\t\trmp_serde::from_slice(&msg_buf)?;\n\n\tmatch ack_message {\n\t\tcrate::service::network::protocol::file_transfer::FileTransferMessage::TransferFinalAck { transfer_id: ack_id } => {\n\t\t\tif ack_id != transfer_id {\n\t\t\t\treturn Err(anyhow::anyhow!(\"Received ack for wrong transfer: expected {}, got {}\", transfer_id, ack_id));\n\t\t\t}\n\t\t\tctx.log(\"Received TransferFinalAck from receiver - transfer confirmed!\".to_string());\n\t\t}\n\t\t_ => {\n\t\t\treturn Err(anyhow::anyhow!(\"Expected TransferFinalAck, got different message type\"));\n\t\t}\n\t}\n\n\t// Only mark completed after receiver confirms to detect network failures.\n\tfile_transfer_protocol.update_session_state(\n\t\t&transfer_id,\n\t\tcrate::service::network::protocol::file_transfer::TransferState::Completed,\n\t)?;\n\n\tctx.log(format!(\n\t\t\"File streaming completed and acknowledged: {} chunks, {} bytes sent to device {}\",\n\t\tchunk_index, bytes_transferred, destination_device_id\n\t));\n\n\t// Signal file completion to aggregator\n\tif let Some(callback) = progress_callback {\n\t\tcallback(bytes_transferred, u64::MAX);\n\t}","sourceCodeStart":1289,"sourceCodeEnd":1325,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/files/copy/strategy.rs#L1289-L1325","documentation":"The acknowledgment decoded successfully but was not TransferFinalAck - most commonly the peer sent TransferError instead, meaning its post-receive verification (size or checksum) failed. A late control message arriving before the ack produces the same error. The job fails after the entire file was already transmitted.","triggerScenarios":"Receiver-side checksum or size verification fails after all chunks arrive, so it answers with TransferError; protocol version differences emit a different final message; an unexpected control message interleaves before the ack.","commonSituations":"Receiver disk truncating writes, receiver running different verification logic after an upgrade, memory pressure causing partial writes on the receiver.","solutions":["If the message is a TransferError, inspect its contents for the receiver-side failure (usually checksum mismatch) and check disk health on the receiver","Check free disk space on the receiving device","Retry the transfer after addressing the receiver-side cause","Align sd-core versions on both devices"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match ack_message {\n    FileTransferMessage::TransferFinalAck { transfer_id } if transfer_id == expected => { /* confirmed */ }\n    FileTransferMessage::TransferError { message, .. } => {\n        // Receiver verified and rejected; retrying blindly repeats the failure.\n        anyhow::bail!(\"Receiver rejected transfer: {}\", message);\n    }\n    other => anyhow::bail!(\"Unexpected final message: {:?}\", other),\n}","preventionTips":["Verify receiver disk space and health before large transfers","Keep verification logic versions aligned across devices","Log the full unexpected message variant for diagnosis"],"tags":["network","file-transfer","verification","acknowledgment"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}