fix(local-asr): 模型下载「已存在即跳过」改为校验大小,拒收截断/损坏文件 (#686)#687
Conversation
run_download 此前仅凭 dest.exists() 跳过已存在文件,不比对 file.size——上次被 中断或外部损坏而残留的截断文件会被当成「已下完」跳过,最终在模型加载时以含糊 错误失败。 抽纯函数 existing_file_is_complete(actual, expected):大小一致才算完整; expected==0(HF 未给大小)退回「存在即信任」;元数据取不到算不完整。run_download 据此判定,大小不符则删除残留文件重新下载。附真值表单测。
|
@claude 请审核:本地模型下载「已存在即跳过」改为校验大小。重点看 (1) expected_size==0(HF 未给大小)退回「存在即信任」是否合理、会不会漏掉真实截断;(2) 删除残留文件后是否能正确回到下载路径重下(不会与多块续传/sentinel 逻辑冲突);(3) 是否还应顺带校验单 GET 退化路径(total_size 未知)的收到字节数。 |
|
Claude finished @appergb's task in 2m 13s —— View job 代码审查:本地模型下载完整性校验
TL;DR整体思路正确,逻辑严谨,单元测试覆盖充分。三个重点问题中,Q1/Q2 基本可接受(有小瑕疵),Q3 存在真实漏洞: Q1:
|
| 问题 | 严重度 | 结论 |
|---|---|---|
Q1: expected_size==0 信任已存在文件 |
低(独立看可接受) | 与 Q3 组合后形成漏洞,见下 |
| Q2: 删除后重下路径 | 无问题 | 功能正确,无冲突;进度多算是小瑕疵 |
Q3: single_stream_download 无字节数校验 |
中(可能静默损坏永久化) | 建议补 Content-Length 校验 |
remove_file 错误静默丢弃 |
低 | 建议加日志 |
建议合并前补上 Q3 的 Content-Length 校验,其余问题可在后续 PR 中处理。
PR Reviewer Guide 🔍(Review updated until commit 4023724)Here are some key observations to aid the review process:
|
审核指出:大小不符的坏文件被删除重下时,already_done_bytes 已按 f.size 把它计入, 重下时 in_flight 又从 0 涨到 f.size,导致进度条短暂双计 / >100%(纯 UI,最终态正确)。 改为只把 existing_file_is_complete 为真的文件计入,与「完整才跳过、否则删重下」一致。
|
Persistent review updated to latest commit 4023724 |
User description
关联 issue
Closes #686
问题
asr/local/download.rs::run_download在目标文件已存在时仅凭dest.exists()跳过,不校验大小:上次被中断 / 外部损坏而残留的截断文件被当成「已下完」跳过,最终在模型加载时以含糊错误失败,用户难自查。(多块路径download_one末尾已有actual != total_size校验,缺口在这个「已存在即跳过」分支。)改动(单一职责)
existing_file_is_complete(actual_size, expected_size):大小一致 → 完整;不符 → 不完整;expected_size == 0(HF 未给大小)→ 退回旧行为「存在即信任」;元数据取不到 → 不完整。run_download在dest.exists()时据此判定:完整才跳过;否则log::warn+ 删除残留文件,回到正常下载路径重下。测试
真值表覆盖:一致 / 截断 / 超大 / 无元数据 / 未知大小。
PR Type
Bug fix, Tests
Description
Added file size verification for existing downloads
Delete and redownload truncated/corrupted files instead of skipping
Fixed progress bar double-counting during redownloads
Unit tests for the integrity check function
Diagram Walkthrough
flowchart LR A[File exists?] -->|Yes| B{Check file size} B -->|Size matches or unknown| C[Skip, count as done] B -->|Size mismatch| D[Delete file, then download] A -->|No| D D --> E[Download normally] E --> F[Download complete] C --> FFile Walkthrough
download.rs
Add integrity check for existing filesopenless-all/app-tauri/src-tauri/src/asr/local/download.rs
existing_file_is_completeto verify file integrityvia size comparison
run_downloadto check file size before skipping; delete andredownload if corrupt
already_done_bytesto only count truly complete files, fixingprogress double-counting
oversized, missing metadata, unknown size)