{"record":{"id":"a97324fed9c88296","repo":"tonhowtf/omniget","slug":"o-modelo-baixado-n-o-confere-esperava-sha256-expected-veio","errorCode":null,"errorMessage":"o modelo baixado não confere: esperava sha256 {expected}, veio {got}","messagePattern":"o modelo baixado não confere: esperava sha256 (.+?), veio (.+?)","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/onnx.rs","lineNumber":227,"sourceCode":"\n    let expected = spec.sha256.to_string();\n    let tmp2 = tmp.clone();\n    let dest2 = dest.clone();\n    let p = progress.clone();\n    let pid2 = pid.clone();\n    tokio::task::spawn_blocking(move || -> anyhow::Result<()> {\n        super::report(\n            &p,\n            &pid2,\n            \"verify\",\n            0,\n            None,\n            Some(\"conferindo sha256\".into()),\n        );\n        let got = sha256_of(&tmp2)?;\n        if got != expected {\n            let _ = std::fs::remove_file(&tmp2);\n            return Err(anyhow!(\n                \"o modelo baixado não confere: esperava sha256 {expected}, veio {got}\"\n            ));\n        }\n        if dest2.exists() {\n            let _ = std::fs::remove_file(&dest2);\n        }\n        std::fs::rename(&tmp2, &dest2)\n            .with_context(|| format!(\"movendo para {}\", dest2.display()))?;\n        Ok(())\n    })\n    .await\n    .map_err(|e| anyhow!(\"tarefa de verificação falhou: {e}\"))??;\n\n    super::report(progress, &pid, \"done\", 1, Some(1), None);\n    Ok(dest)\n}\n\n/// Apaga um modelo baixado.","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/onnx.rs#L209-L245","documentation":"After downloading to a temp file, `ensure_model` computes the file's sha256 and compares it with the CATALOG's expected hash; a mismatch deletes the temp file and returns 'o modelo baixado não confere: esperava sha256 {expected}, veio {got}'. This integrity gate prevents corrupted or tampered model weights from being installed.","triggerScenarios":"Calling `ensure_model` when the downloaded bytes do not match the catalog sha256: truncated/interrupted download, corrupted CDN/mirror response, an HTML error page saved instead of the model, or the upstream file was updated while the catalog still pins the old hash.","commonSituations":"Flaky network with silent truncation; a proxy/captive portal injecting a block page; upstream release replaced the onnx file without the app catalog being updated; disk corruption.","solutions":["Simply retry the download (the bad temp file is already removed) — transient truncation is the most common cause.","Download the URL manually and run `sha256sum` to see if the upstream file changed; if it did, update the catalog's sha256 (and bytes) entry.","Check whether a proxy/antivirus is intercepting the download and bypass it; ensure enough disk space so the file isn't truncated."],"exampleFix":"// before\nlet path = onnx::ensure_model(id, &progress).await?;\n// after\nlet path = match onnx::ensure_model(id, &progress).await {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"sha256\") => {\n        // checksum mismatch: retry once; if it persists, upstream changed\n        onnx::ensure_model(id, &progress).await?\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"// nothing to check beforehand; instead ensure reliable transfer conditions\nlet free = fs2::available_space(models_dir)\n    .unwrap_or(0);\nassert!(free > spec_bytes * 2, \"espaco insuficiente para baixar e verificar o modelo\");","typeGuard":null,"tryCatchPattern":"match onnx::ensure_model(id, &progress).await {\n    Err(e) if e.to_string().contains(\"sha256\") => {\n        tokio::time::sleep(Duration::from_secs(5)).await;\n        onnx::ensure_model(id, &progress).await // one clean retry; temp file was already removed\n    }\n    other => other,\n}","preventionTips":["Retry once on checksum errors — transient truncation is the usual cause.","If it persists, verify the upstream file's sha256 manually; update the catalog hash when the vendor rotates the artifact.","Bypass caching proxies/antivirus that can corrupt or substitute binary downloads; ensure adequate disk space."],"tags":["onnx","checksum","sha256","download"],"backgroundTag":"checksum-mismatch","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}