Skip to content

fix(core): cache clear --web 保留运行中的 serve 显示的网页版本 - #1145

Merged
334456777 merged 1 commit into
mainfrom
fix/core-cache-clear-held-web
Nov 24, 2026
Merged

334456777 merged 1 commit into
mainfrom
fix/core-cache-clear-held-web

Conversation

@334456777

Copy link
Copy Markdown
Owner

问题

weflow cache clear --web(以及 --all、WebUI「设置 → 缓存的文件 → 网页版本 → 清理」)把整个 cache/web/ 删掉,连运行中的 weflow serve 用 WebStore::hold 持有的版本也删了,/ui/ 立即变成 404「网页中没有这个文件」。web prune 和 serve-files(#815)都有这层保护,只有这里漏了。

做了什么

  • 新增 crates/weflow-core/src/webui/clear.rs(webui 的子模块):
    • WebStore::clear:先逐个版本调用 WebStore::remove(在独占锁下删除),返回 in_use 的版本保留,并在 warnings 里写「WebUI X is shown by a running weflow serve; it was kept」(中文:「网页 X 正由运行中的 weflow serve 显示,已保留」);再清理版本以外的条目:进程已不在的 .download-* 和 .current-<pid>、没有对应版本且没人持有的 .lock-* / .install-*、不指向保留版本的 current、其他早期遗留的文件。被保留的版本是 current 时,current 也保留。
    • WebStore::clearable:不加锁地列出 clear 会删的条目;WebStore::is_held:版本是否被运行中的 serve 显示。
  • services/cleanup.rs:cache_part_paths(CachePart::Web) 改为 clearable(),所以 cache list 和 cache clear --dry-run(WebUI 确认框用的 RemovalPlan)的 web 部分只列出会删掉的条目、大小也只算这些;cache_clear 对 web 部分调用 WebStore::clear,freedBytes 按清理前后的实际差值计算。
  • --web 的帮助文字、CachePart::Web 的文档注释(契约快照 web/contract/openapi.json 随之重写;生成的 contract.gen.ts 没有变化)、中文帮助和报错目录(help_zh.rs、messages_zh.rs 各一行)。
  • WebUI:设置里「网页版本」的说明改为「下载过的网页版本;正在显示的版本会保留。」,补了英文。示例服务端不区分正在显示的版本,没有改。

用户可见的变化

  • 有 serve 在运行时,清理网页版本不再删掉它正在显示的版本(和它的选定),结果里多一条警告说明保留了哪个版本;/ui/ 照常可用。没有 serve 运行时,所有版本照旧全部删除。
  • cache list 的 web 部分不再是 cache/web 这一个路径,而是会被清理的各个条目;正在显示的版本不计入大小,只剩它时 WebUI 的「清理」按钮不可点。
  • API 版本不变:没有改路由、参数和响应的结构。

验证

  • 单元测试 webui::clear::tests:条目按名字分类;hold 一个版本后 clearable/clear 保留它和 current,删掉其他版本、陈旧的下载和锁、遗留文件,警告正确;放开后全部删除;正在运行的进程写的下载、.current-<pid> 和正在安装时持有的 .install-* 保留。
  • 端到端测试 native_e2e::cache_clear_leaves_the_webui_version_a_server_shows:hold 之后 cache_list 只列出另一个版本,cache_clear(&[Web]) 的 removedPaths、freedBytes、warnings 正确。
  • serve 测试 web_versions::cache_clear_leaves_the_version_a_server_shows:对运行中的 serve 发 DELETE /cache/clear?web=true&dry-run=true 和 …&yes=true,确认框不列出正在显示的版本,清理后 /ui/ 仍是 200、选定仍在;停掉 serve 后 cache clear --web 全部删除。
  • 本地(Windows):cargo fmt --all -- --check、cargo clippy -p weflow-core -p weflow-cli --all-targets -- -D warnings、cargo test -p weflow-core、cargo test -p weflow-cli、WEFLOW_UPDATE_CONTRACT=1 cargo test -p weflow-cli --bin weflow contract_、web/ 下 bun run check 全部通过。只用合成数据,未碰真实账号。

fixed #1139

🤖 Generated with Claude Code

cache clear --web(以及 --all、WebUI 设置里清理「网页版本」)原来整个删除 cache/web,
连运行中的 serve 用 hold() 持有的版本也删掉,/ui/ 立即变成 404。现在逐个版本经
WebStore::remove 删除:被持有的版本连同它的锁文件和指向它的 current 保留,并在
warnings 里说明;进程已不在的下载目录、没有版本的锁文件、指向已删版本的 current
一并清掉。cache list 和 --dry-run 的 web 部分只列出会删掉的条目。

fixed #1139

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@334456777 334456777 added the bug 好像出了点问题 label Nov 24, 2026
@334456777 334456777 added this to WeFlow Nov 24, 2026
@334456777 334456777 moved this to In Review in WeFlow Nov 24, 2026
@334456777
334456777 enabled auto-merge November 24, 2026 01:56
@334456777
334456777 merged commit 1a3ff57 into main Nov 24, 2026
13 checks passed
@334456777
334456777 deleted the fix/core-cache-clear-held-web branch November 24, 2026 02:02
@334456777 334456777 moved this from In Review to Done in WeFlow Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 好像出了点问题

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

cache clear --web 删掉正在运行的 serve 显示的网页版本,/ui/ 立即变成 404(web prune 会保留它)

1 participant