fix(brand): 更新后「在跑的任务列表」不再静默变空——桥迟到自动重试、拉取失败不删本地态

现场(用户 2026-10-22):点「立即更新」→ 闸门确认并等待 → 进程被 update.exe 替换、
WebView 整页重载。重载那一刻 pywebview 桥还没注入,getPywebviewApi() 返回的降级桥里
vc_ 方法数为 0,而变体采集页把「桥不在」画成「暂无变体采集任务」:loadTasks 四条出口
全是静默 return(无桥/并发中/无 uid/!success),空 catch 也一样;首拉只发一次,
60 秒轮询又被「列表里有活跃任务」反锁 ⇒ 撞空一次就永久空,除手点刷新没有出路。

另外两页是另一种"没掉":跟价 loadHistory 一次 catch 把列表清空,紧接的
syncPollingIdsWithHistory 把「history 没有 + 无快照」的 id 连 localStorage 快照一起删
(不可恢复);商品风险同型且更狠,连快照豁免都没有。更新的几十秒里进程已退、
新进程未起,任何一次 /history 失败或 401 都踩得到。

改法:新增 shared/bridges/bridge-list-state.ts(失败分类/可见文案/首拉重试驱动,
退避复用 getTaskPollBackoffMs,8 轮约 35 秒);变体采集页桥未就绪→重试到成功或次数
用尽,失败态写进空列表文案并给一次 ElMessage;跟价/商品风险加 historyLoadOk 守卫,
拉取失败不清列表、不结算、不删本地 id。静默 catch 棘轮 83→81(实测;本轮减 1,
另 1 处是此前台账未缩,已一并拉平并逐文件改小)。

门禁:npx vue-tsc --noEmit rc=0;npm test 905/905 全绿(含新增 7 例
tests/bridge-list-first-load-retry.test.ts,改前对旧代码真红)。
This commit is contained in:
2026-10-22 20:53:44 +08:00
parent 96315fe302
commit 58c40b6695
6 changed files with 279 additions and 13 deletions
@@ -776,16 +776,24 @@ async function loadDashboard() {
}
}
/** 上一轮 /history 是真拉到的还是失败的:失败轮没有任何资格判定任务「已不存在」 */
let historyLoadOk = false
async function loadHistory() {
try {
const vo = await getPriceTrackHistory()
historyItems.value = vo.items || []
historyLoadOk = true
} catch {
historyItems.value = []
// 失败保留上一轮列表:清成空会让紧接着的结算把在跑的任务判成「已不存在」,
// 连带删掉 localStorage 里的轮询 id 与快照——一次抖动(或客户端更新的那几十秒)
// 就能把「当前任务」整个抹没,用户看到的就是任务凭空消失。
historyLoadOk = false
}
}
function syncPollingIdsWithHistory() {
if (!historyLoadOk) return
for (const taskId of [...pollingTaskIds.value]) {
const any = historyItems.value.some((r) => r.taskId === taskId)
if (!any && !taskSnapshots.value[taskId]) {