Skip to content

fix(knowledge): retry the staged model promotion through transient Windows locks - #79

Merged
1 commit merged into
Soren-ABT:mainfrom
TruthK:fix/windows-staging-promotion-retry
Nov 19, 2026
Merged

1 commit merged into
Soren-ABT:mainfrom
TruthK:fix/windows-staging-promotion-retry

Conversation

@TruthK

@TruthK TruthK commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #78

问题

模型下载完成后,.staging/<model> 提升为最终缓存的 rename 在 Windows 上稳定失败 EPERM(详见 issue):即使 release ack 已返回、进程句柄已释放,Defender/搜索索引器对刚落盘权重仍有短暂扫描锁,而提升路径没有任何重试,扫描窗口内的失败直接作为“下载失败”上抛。

修复

loadLocalModel() 的提升步骤改为 promoteDownload():

  • rm(finalPath) + rename(staging → final) 作为一个单元重试;
  • 仅对 EPERM / EACCES / EBUSY / ENOTEMPTY 重试,退避 [100, 250, 500, 1000, 1000, 2000, 2000, 3000](总量约 10s);
  • 其他错误立即上抛;失败时 staging 保持完整,后续重试从同一份完整下载开始。

不杀 worker、不改变现有“先校验后提升”的原子性:rename 仍是单步原子操作,重试只是重复尝试。

测试

  • tests/local-worker-lifecycle.spec.ts 新增两例(partial mock node:fs/promises 的 rename):
    • 两次 EPERM 后第三次提升成功,最终缓存就位、staging 清空、状态 ready;
    • 非锁类错误(ENOENT)不消耗重试预算直接上抛,staging 完整保留。
  • 全套件对照:除既有的 tool-contract.spec.ts 环境性失败(链接的 DSH 检出 era 不匹配,未修改主干上同样 15 failed)外,其余全部通过,无回归。

实机验证(Windows 11,DSH Desktop 0.2.2-rc.1)

0.5.4 在本机 4/4 确定性失败(两个模型 × C/D 两盘)。同环境安装本分支构建后删除缓存重下 Xenova/bge-small-zh-v1.5:下载 19%→100%,提升成功,状态 ready/loaded,向量检索(hybrid)恢复正常。

…ndows locks

A fully downloaded model is promoted by renaming .staging/<model> into the
final cache immediately after the release ack. On Windows the rename
reliably fails with EPERM even though every process handle is closed:
antivirus or the search indexer still holds the freshly written weights for
a moment. The download then surfaces as failed even though the staging
directory is complete, and the next attempt re-downloads everything.

Retry the promotion rename (rm final + rename) on EPERM/EACCES/EBUSY/
ENOTEMPTY with a ~10s backoff budget; any other error propagates
immediately and the staging directory stays intact for a clean retry.
Verified live on Windows 11: bge-small-zh-v1.5 promotion now succeeds
where 0.5.4 failed deterministically on both C: and D: caches.
@Soren-ABT Soren-ABT closed this pull request by merging all changes into Soren-ABT:main in 5e13845 Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows:本地模型下载完成后 .staging 提升 rename 稳定失败 EPERM(Defender/索引器短暂占用,无重试)

2 participants