zread_cli icon indicating copy to clipboard operation
zread_cli copied to clipboard

Bug: `zread generate --draft resume` token 耗尽后从头开始生成

Open hothand opened this issue 3 months ago • 0 comments

问题描述

执行 zread generate --draft resume --skip-failed 生成文档时,如果 token 耗尽或中途失败,再次执行会:

  • ❌ 创建新的 draft 版本(新 wiki.json,页面大纲重置)
  • ❌ 从第 1 页开始重新生成
  • ✅ 期望:继续从上次中断的页面生成

复现步骤

  1. zread generate --draft resume --skip-failed 开始生成
  2. 中途 token 耗尽或强制中断
  3. 再次执行 zread generate --draft resume --skip-failed
  4. 观察到从第 1 页重新开始,之前生成的 23 页丢失

根因分析

zread 检测到异常退出后,没有继续使用当前 drafts/ 目录,而是:

  • 创建了新的 draft id(如 2026-08-04-151741)
  • 重新生成 wiki.json 页面大纲(结构变差)
  • 从第 1 页开始覆盖

临时解决方案(用户侧)

已编写防护脚本:

  1. 生成前自动备份 drafts/ 目录
  2. 生成后检测页面数是否异常减少
  3. 异常时自动恢复备份

建议修复方向

  1. ✅ resume 时优先使用 drafts/ 现有的 wiki.json,不要创建新 draft
  2. ✅ 通过检测 md 文件是否存在来判断生成进度
  3. ✅ 异常退出后保留当前 draft 状态
  4. ✅ 添加 --resume-from <page-number> 参数支持

hothand avatar Aug 04 '26 07:08 hothand