{"record":{"id":"37720d9e326e9383","repo":"LykosAI/StabilityMatrix","slug":"hash-validation-for-filename-failed-expected","errorCode":null,"errorMessage":"Hash validation for {FileName} failed, expected {ExpectedHashSha256} but got {hash}","messagePattern":"Hash validation for (.+?) failed, expected (.+?) but got (.+?)","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Models/TrackedDownload.cs","lineNumber":157,"sourceCode":"            .ResumeDownloadToFileAsync(\n                SourceUrl.ToString(),\n                DownloadDirectory.JoinFile(TempFileName),\n                resumeFromByte,\n                progress,\n                cancellationToken: cancellationToken\n            )\n            .ConfigureAwait(false);\n\n        // If hash validation is enabled, validate the hash\n        if (ValidateHash)\n        {\n            OnProgressUpdate(new ProgressReport(0, isIndeterminate: true, type: ProgressType.Hashing));\n            var hash = await FileHash\n                .GetSha256Async(DownloadDirectory.JoinFile(TempFileName), progress)\n                .ConfigureAwait(false);\n            if (hash != ExpectedHashSha256?.ToLowerInvariant())\n            {\n                throw new Exception(\n                    $\"Hash validation for {FileName} failed, expected {ExpectedHashSha256} but got {hash}\"\n                );\n            }\n        }\n\n        // Rename the temp file to the final file\n        var tempFile = DownloadDirectory.JoinFile(TempFileName);\n        var finalFile = tempFile.Rename(FileName);\n\n        // If auto-extract is enabled, extract the archive\n        if (AutoExtractArchive)\n        {\n            OnProgressUpdate(new ProgressReport(0, isIndeterminate: true, type: ProgressType.Extract));\n\n            var extractDirectory = string.IsNullOrWhiteSpace(ExtractRelativePath)\n                ? DownloadDirectory\n                : DownloadDirectory.JoinDir(ExtractRelativePath);\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Models/TrackedDownload.cs#L139-L175","documentation":"TrackedDownload verifies the completed download by SHA-256 against ExpectedHashSha256. If the computed hash differs, it throws, aborting the download before the temp file is promoted to its final name. This protects against corrupted or tampered downloads.","triggerScenarios":"Start or Resume leading StartDownloadTask to hash a finished file whose SHA-256 does not match the expected value (case-insensitive compare against lowercased expectation).","commonSituations":"Mirror serving different file versions than the manifest hash, interrupted/truncated downloads that still completed, file updated upstream after hash was recorded, proxy/CDN corruption.","solutions":["Delete the downloaded temp file and restart the download from the original source.","Verify the expected hash matches the file version actually hosted (model may have been updated upstream).","Retry with a different mirror or direct URL.","Check network path for proxies/CDNs that may alter content."],"exampleFix":"// before\nthrow new Exception($\"Hash validation for {FileName} failed, expected {ExpectedHashSha256} but got {hash}\");\n// after\nthrow new HashMismatchException(FileName, ExpectedHashSha256, hash)\n{\n    SuggestedAction = SuggestedAction.RestartDownload\n};","handlingStrategy":"try-catch","validationCode":"// Pre-check the source integrity if the server supports checksums\nvar expected = download.ExpectedHashSha256?.ToLowerInvariant();\nif (string.IsNullOrEmpty(expected))\n    _logger.LogWarning(\"No expected hash for {FileName}; integrity cannot be verified\", download.FileName);","typeGuard":null,"tryCatchPattern":"try { await trackedDownload.Start(); }\ncatch (Exception ex) when (ex.Message.Contains(\"Hash validation\"))\n{\n    _logger.LogError(ex, \"Checksum mismatch for {File}\", trackedDownload.FileName);\n    await trackedDownload.Cancel();\n    await downloads.TryRestartFromAlternateMirror(trackedDownload);\n}","preventionTips":["Always record an expected SHA-256 for downloads","Keep manifest hashes in sync with upstream model releases","Prefer mirrors that serve identical, hash-verified content","Delete and redownload rather than trusting a hash-failed temp file"],"tags":["download","hash","integrity"],"backgroundTag":"checksum-mismatch","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}