Skip to content

fix(core): 清理已删除日志的 cursor 文件条目 - #321

Open
TUARAN wants to merge 1 commit into
juejin-cn:mainfrom
TUARAN:fix/cli/prune-stale-cursor-files
Open

TUARAN wants to merge 1 commit into
juejin-cn:mainfrom
TUARAN:fix/cli/prune-stale-cursor-files

Conversation

@TUARAN

@TUARAN TUARAN commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

🏷️ 变动类型

  • 🐞 Bug 修复
  • ⚡️ 性能优化

🖥️ 影响范围

  • Desktop
  • CLI
  • Web

🔗 关联 Issue

关联 #266 中“各渠道 files 在日志删除后不清理”的独立子问题;本 PR 不关闭该 Issue 的按渠道拆分和 Claude 状态上限事项。

💡 改动说明

Summary

同步写回 cursors.json 时,删除“绝对路径已不存在、但父目录仍在”的 files 游标;即使本轮没有新的用量行,也会把这次清理持久化。

Root cause

除 TeleAgent 外,各解析器把已删除日志的路径留在 cursor 里。saveCursors 只在内容变化时重写整份 JSON,这些失效条目会随每轮同步一起序列化。

Verification

  • 修复前:父目录仍在的已删除文件,其 cursor 仍被写回。
  • 修复后:同一路径下该条目被移除;仍存在的文件、父目录缺失的路径、以及相对路径键都会保留。
  • focused 测试 12/12 通过(prune-cursor-files / cursors-cache / cursors-atomic-write / cursor-json)。
  • corepack pnpm --filter @juejin-opensource/jusage-core build 通过。
  • git diff --check 通过。

Before / after

  • Before:日志被删除且父目录仍在时,cursors.json 继续保留该文件偏移。
  • After:这类条目在保存前被移除;父目录不存在时不删,避免卸卷/整树暂时不可用后回头双计。

Risk and scope

只清理各渠道 cursor 中的 files 映射。不修改 token 解析、去重集合、Claude seenUsage 上限,也不做 cursors.json 按渠道拆分。新增 core patch changeset。

Not tested

  • 未用真实长期多渠道 cursors.json 做端到端同步。
  • 未运行打包后的 Desktop。
  • 完整 core 测试在本环境有 3 个与本改动无关的既有失败(回到 main 同样失败)和 1 个既有 flaky。

📝 Changelog

包 版本类型 变更描述(面向用户)
@juejin-opensource/jusage-core patch 同步时清理父目录仍在、但日志文件已删除的 cursor 条目,避免 cursors.json 随失效路径持续膨胀。

☑️ 自查清单

  • 分支命名符合 <type>/<end>/<short-desc>:fix/cli/prune-stale-cursor-files
  • 已在受影响的端用 focused 单测与 before/after harness 验证
  • 未改动面板 UI
  • 已加入 changeset
  • core pnpm build 通过

Remove cursors.json file entries when the log file is gone but its
parent directory still exists, and persist that cleanup even when a
sync round produced no new usage rows.
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.

1 participant