Skip to content

feat(download): 统一下载中心记录跨脚本更新包诊断信息 - #2030

Merged
youngslin merged 20 commits into
AUTO-MAS-Project:devfrom
youngslin:feat/common-download-diagnostics
Nov 23, 2026
Merged

youngslin merged 20 commits into
AUTO-MAS-Project:devfrom
youngslin:feat/common-download-diagnostics

Conversation

@youngslin

Copy link
Copy Markdown

背景

CNB #305 三月七更新包安装后出现嵌套 March7thAssistant 目录且版本未变;更新包安装后自动删除,无法复盘归档结构。将通用包诊断放到公共下载入口,而非每个脚本单独记录。

改动

  • 公共下载入口 app/core/update.py 在下载完成、原包仍存在时记录诊断摘要,适用于经公共下载入口的不同脚本及内置 httpx/FluxDown;不会改变下载是否成功的判定。
  • ZIP 仅只读中央目录并提取受限摘要:文件数量、总展开字节、根目录个数、白名单发行目录名称、小尺寸版本标记及版本值。不读取任意内容、不保留原始文件路径清单;7z、EXE 标记格式与字节数,不进行安装级解析。
  • 历史模型增加 diagnostic,下载历史提供 JSON 导出;诊断 URL 仅保留协议和域名,不含路径、签名参数与凭据。
  • 诊断检查失败不影响原下载;新增核心隐私与 ZIP 结构测试。

范围

这是统一下载层的第一步:所有经过公共 download_file 的脚本均获得包下载诊断;对未接入公共入口的安装器和安装后版本/健康诊断需后续对接适配器。不会将仅下载成功当作安装成功。需等待 CI 验证。

@github-actions github-actions Bot added 模块: 更新 按更新日志碎片自动设置 类型: 新增 按更新日志碎片自动设置 labels Nov 16, 2026
Comment thread app/core/update.py Outdated
Comment on lines 164 to 172
except Exception as exc:
await _write_package_diagnostic(
destination, url, source=source, downloader=downloader,
failure=type(exc).__name__,
)
raise
await _write_package_diagnostic(
destination, url, source=source, downloader=downloader
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Task cancellation during _write_package_diagnostic inside download_file's exception handler can mask critical exceptions like FluxdownCancelUnconfirmed with CancelledError.
Severity: MEDIUM

Suggested Fix

Shield the diagnostic write with asyncio.shield or guard cancellation around _write_package_diagnostic, ensuring that any CancelledError does not mask or overwrite the original in-flight exception.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: app/core/update.py#L164-L172

Potential issue: In `download_file`, `_write_package_diagnostic` is awaited inside an
`except Exception` handler before re-raising the original exception.
`_write_package_diagnostic` acquires `config_manager.transaction()` and waits on the
global `execution_gate()`. If a task cancellation occurs while waiting for the gate, an
uncaught `asyncio.CancelledError` is raised, replacing the original exception. When
handling `FluxdownWriterUnconfirmed` or `FluxdownCancelUnconfirmed`, this masks the
writer unconfirmed error as a normal task cancellation, which can lead callers like
`script_update_queue.py` to proceed before writer ownership is resolved.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment thread app/core/update.py Outdated
Comment on lines +79 to +88
await _write_history(
_utils_fluxdown_cli.FluxdownDownloadRecord(
url=safe_origin(url),
destination=str(destination),
size=int(details.get("bytes") or 0),
status="diagnostic" if failure is None else "failed",
error=failure,
diagnostic=details,
)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Writing extra diagnostic records halves download history retention and causes successful diagnostic records to render as red failure entries in the UI.
Severity: LOW

Suggested Fix

Instead of creating a standalone history record, attach diagnostic metadata to the existing terminal download record or update the UI timeline logic to recognize and color "diagnostic" records appropriately.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: app/core/update.py#L79-L88

Potential issue: Every download attempt writes an additional record with status
`"diagnostic"` on success or `"failed"` on error via `_write_package_diagnostic`.
Because `_write_history` retains only the last 50 entries, this redundant record halves
the effective history capacity. Furthermore, the frontend timeline component in
`DownloadHistorySettings.vue` defaults all non-success/non-fallback statuses to red,
causing successful diagnostic records to display as red failure indicators.

Did we get this right? 👍 / 👎 to inform future reviews.

@youngslin

Copy link
Copy Markdown
Author

@jinghero review

Copy link
Copy Markdown
Contributor

总体结论:修改后合并

取消时保留原始下载异常、把诊断附到终态记录的方向是对的。不过现在会把两次下载尝试拼成一条,排错时反而容易被带偏,喵。

[逻辑 · P2] 不要用一分钟内的同路径记录代替本次下载身份

_merge_download_diagnostic:69–97 只按目标路径、来源域名和 60 秒窗口查找历史,找到后只替换 diagnostic、url,保留旧的状态、错误、大小和时间。

真实入口是 HSR 的下载重试:同一个 .part 文件失败后,间隔 1 或 2 秒就会重试。内置 httpx 分支本身不追加终态记录,因此第一次失败由本次新增逻辑留下 failed;第二次成功会匹配到这条失败记录,把成功包的诊断塞进去,却仍显示失败、旧错误和零字节。成功后再次失败也可能反过来保留绿色成功状态。配置事务只能防止并发丢写,不能区分这两次尝试。

请只合并本次调用实际产生的 FluxDown 终态记录;内置 httpx 每次尝试应单独追加,或沿下载调用传递明确的记录关联。不要仅把匹配记录的状态改成最新值,那仍会抹掉上一次尝试。补一条同目标短间隔“失败后重试成功”的入口回归,确认历史和导出保留各自的状态与诊断。现有四条测试只验证摘要 helper,抓不到这个错配;以上为源码时序核验,未声称运行复现。

dot酱 🐾

同步上游 dev,将诊断接到现有下载中心,保留 FluxDown 终态及停写异常。

Copy link
Copy Markdown
Contributor

总体结论:修改后合并

0ca1fc4 修了上轮的串记录问题:同一路径先失败再成功,历史会分别留两笔,成功的包摘要不会再挂到上一条失败记录上。

[P2] 大归档的检查限额生效太晚。 先打开 ZIP、读完整目录并统计,再判断条目有没有超限。版本标记的上限也只数成功识别的条目,不限制实际打开多少次。下载已经结束时,诊断还会占着目标文件的锁。建议在解析前先限制目录读取量,再单独限制版本标记的尝试次数;超出就只记格式和大小。

[P2] 新的成功记录也能导出,但导出会把本机路径一并带走。 设置页直接写出整条记录,其中包含本机下载路径和代理信息。这些信息留在本机排查没问题,发给别人时用不着。建议导出时只选必要字段,旧历史也经过同一个出口,不影响本机继续看完整记录。

让诊断少读一点、分享少带一点的 dot酱

Copy link
Copy Markdown
Contributor

总体结论:可以合并

be9ed68 这版把上轮两处都收住了,喵。ZIP 读取最多用 4 MiB 预算,大目录不会先读进内存再检查;版本标记读空、读不出版本也照样占一次额度。超额只保留包类型和大小,不耽误下载结果。

分享用的 JSON也只挑需要的字段:失败时能带上 HTTP 状态码和来源主机,不带本地保存路径、代理地址或签名链接。原来的同路径重试仍会留下两条独立记录。

把下载记录收拾干净的 dot酱

@youngslin
youngslin merged commit 5ab4df2 into AUTO-MAS-Project:dev Nov 23, 2026
8 checks passed
github-actions Bot added a commit that referenced this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

模块: 更新 按更新日志碎片自动设置 类型: 新增 按更新日志碎片自动设置

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants