fix(download): 已入库任务不被 qB 中间态改回(H2)

importing / imported 只由整理侧推进:checkingResumeData / queuedDL / checkingUP / moving 等中间态只更新原始字段,不改回 queued / downloading / completed,completed_at 不重写;这期间也不做无进展判定。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-03 21:20:08 +08:00
1 parent 3904abc472
commit 2159765949
3 files changed
+11 -3

No files matched your search

@@ -771,7 +771,8 @@ async function observeLocked(
let noProgressSince = row.no_progress_since;
let lastProgressAt = row.last_progress_at;
let stalledNow = false;
if (obs.status === "downloading") {
// importing / imported 期间(qB 重新校验 / 移动等中间态)不做无进展判定
if (obs.status === "downloading" && (merged.status === "downloading" || merged.status === "stalled")) {
if (downloaded > row.downloaded_bytes || !lastProgressAt) {
lastProgressAt = now;
noProgressSince = null;
+4 -2
View File
@@ -62,7 +62,9 @@ export function toDomainDownloadStatus(status: DownloadStatus, pauseReason: Paus
/**
* 同步轮询时合并"下载器观察"与"当前业务状态":
* - 业务叠加态在其底层下载状态不变时保留(importing/imported 遇 completed、stalled 遇 downloading、submitting 遇 queued);
* - importing / imported 只由整理侧推进:下载器的任何中间态(checkingResumeData / queuedDL / checkingUP / moving,
* 乃至出错 / 缺文件)都不把它改回下载阶段,同步只更新原始字段;只有 removed(调用方确认移除)例外;
* - 其余业务叠加态在其底层下载状态不变时保留(stalled 遇 downloading、submitting 遇 queued);
* - 暂停原因为 policy/agent 且下载器仍是暂停时保留原因,不被改写成 user;
* - 其余以观察为准。
*/
@@ -72,7 +74,7 @@ export function mergeObservedDownloadState(
): ContractDownloadState {
const next = TO_CONTRACT[observed];
const keep =
((current.status === "importing" || current.status === "imported") && observed === "completed") ||
((current.status === "importing" || current.status === "imported") && observed !== "removed") ||
(current.status === "stalled" && observed === "downloading") ||
(current.status === "submitting" && observed === "queued");
if (keep) return { ...current };
+5
View File
@@ -57,6 +57,11 @@ describe("下载状态", () => {
st("paused", "threshold"),
);
expect(M.mergeObservedDownloadState(st("imported"), "removed")).toEqual(st("removed"));
// 已进入整理侧:qB 重启 / 重新校验 / 移动的中间态不把状态改回下载阶段
for (const o of ["queued", "downloading", "paused_by_user", "error", "missing_files"] as const) {
expect(M.mergeObservedDownloadState(st("imported"), o), o).toEqual(st("imported"));
expect(M.mergeObservedDownloadState(st("importing"), o), o).toEqual(st("importing"));
}
});
});