{"record":{"id":"a65d7fd08296c1c9","repo":"libnyanpasu/clash-nyanpasu","slug":"staged-file-hash-mismatch","errorCode":null,"errorMessage":"staged file hash mismatch","messagePattern":"staged file hash mismatch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/service/profile_file.rs","lineNumber":784,"sourceCode":"            Err(error) => {\n                return Err(error).with_context(|| {\n                    format!(\n                        \"inspect staged symlink specification {}\",\n                        link_path.display()\n                    )\n                });\n            }\n        };\n        if file_metadata.is_some() && link_metadata.is_some() {\n            bail!(\"materialization has multiple staged resources\");\n        }\n        if let Some(metadata) = file_metadata {\n            if is_symlink_or_reparse(&metadata) || !metadata.is_file() {\n                bail!(\"staged file is not a regular file\");\n            }\n            let content = std::fs::read(&file_path)?;\n            if hash_tagged(b\"file\", &content) != expected_hash {\n                bail!(\"staged file hash mismatch\");\n            }\n            return Ok(Some(StoredResource::File { path: file_path }));\n        }\n        if let Some(metadata) = link_metadata {\n            if is_symlink_or_reparse(&metadata) || !metadata.is_file() {\n                bail!(\"staged symlink specification is not a regular file\");\n            }\n            let target = std::fs::read_to_string(&link_path)?;\n            if hash_tagged(b\"symlink\", target.as_bytes()) != expected_hash {\n                bail!(\"staged symlink hash mismatch\");\n            }\n            return Ok(Some(StoredResource::Symlink {\n                target: ExternalProfilePath::new(target)?,\n            }));\n        }\n        Ok(None)\n    }\n","sourceCodeStart":766,"sourceCodeEnd":802,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/service/profile_file.rs#L766-L802","documentation":"After reading the staged file blob, read_staged_resource verifies its content against the expected tagged hash (hash_tagged(b\"file\", content)). The hash does not match, meaning the staged content changed since it was hashed (or the expected hash belongs to a different resource). This is an integrity check to detect truncated, edited, or mismatched staged data before promotion.","triggerScenarios":"std::fs::read of stage_file_path succeeded but hash_tagged(b\"file\", &content) != expected_hash — the staged file was modified/truncated after staging, the write was not fully flushed (crash/power loss), or the expected_hash passed to read_staged_resource corresponds to a different resource/version than what was staged.","commonSituations":"Disk full or crash during write_private_file_new leaving a partial blob; reusing an old expected hash after re-generating profile content; concurrent edits to the staging directory; restoring an older staging snapshot from backup.","solutions":["Re-run the materialization from scratch so the staged blob is rewritten and re-hashed.","Verify the expected_hash passed to read_staged_resource was computed from the same content that was staged in this operation.","Check for concurrent writers/readers of the staging directory and serialize access to one operation_id.","Check disk space and filesystem health; run fsck/chkdsk if corruption is suspected."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"staged file hash mismatch\") => {\n        remove_stale_staging(root, op_id)?;\n        retry_materialization() // restage content and recompute hash\n    }\n    other => other,\n}","preventionTips":["Never reuse an expected_hash across different staged contents.","Ensure only one process stages/reads a given operation_id.","Verify adequate disk space; partial writes from ENOSPC cause mismatches.","Recompute the hash immediately after staging if you need to assert integrity yourself."],"tags":["hash","integrity","profile-materialization","rust"],"backgroundTag":"checksum-mismatch","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}