Skip to content

fix(engine): 已结束运行的 --run 日志止于读取时的文件末尾 - #277

Merged
SheathedSharp merged 2 commits into
mainfrom
fix/engine-run-log-follow-end
Nov 11, 2026
Merged

SheathedSharp merged 2 commits into
mainfrom
fix/engine-run-log-follow-end

Conversation

@SheathedSharp

Copy link
Copy Markdown
Owner

问题

已退出、但还没有下一次运行记录接管位置的运行(最近一次结束的运行),runLogRange 得到
end = -1 的范围,bounded() 为假,于是 --follow 走 tail -c +N -f 一直跟随同一文件。
随后下一次运行写入这个文件,它的字节就出现在这次运行名下——文档承诺的「跟随一次已经结束的
运行会打印它的行然后停止」没有兑现。

改动

  • logRange 增加 ended 状态:这次运行已经退出,不会再有属于它的字节。bounded() 现在
    真正等于注释里的「最后一字节已经写完」。
  • runLogRange 对 status == exited 一律标记 ended;后续运行记录的接管位置仍然给出精确
    终点,没有记录时终点就是读取时的文件末尾。
  • readRunLines 对 ended 且没有记录终点的范围,按打开文件时看到的大小封口,读的过程中
    才开始写入的字节也进不来。
  • docs/cli.md / docs/cli.zh.md 同步该契约。

验证(实际执行)

  • go test -count=1 -timeout=8m ./...(engine):全部通过,无 FAIL。
  • go test -count=1 ./internal/cmd:通过。新增 TestRunLogRangeOfANewestFinishedRunEndsAtTheFile
    与 TestFollowOfAFinishedRunWithoutASuccessorReturns;后者在修复前会卡 5 秒后报「跟随没有返回」,
    修复后立即返回。更新两处既有 runLogRange 期望(exited 运行带 ended)。
  • gofmt -l ./internal/cmd、go vet ./internal/cmd:无输出。
  • python3 scripts/check_docs.py:6 对文档一致。

未跑:核心 race、真实服务场景(每日 Nightly full verification 与发版流程覆盖)、Windows 构建。

🤖 Generated with Claude Code

SheathedSharp and others added 2 commits November 11, 2026 17:52
已退出、但还没有下一次运行记录接管位置的运行(最近一次结束的运行),
原来会得到没有终点的范围:--follow 会一直跟随同一文件,随后下一次运行
写入的字节就挂在了这次运行名下。范围现在带上 ended 状态,表示这次运行
不会再写出新行;读取时按打开文件看到的大小封口,把读的过程中才开始写入
的字节挡在外面。

Co-Authored-By: Claude Code <noreply@anthropic.com>
@SheathedSharp
SheathedSharp merged commit bba3094 into main Nov 11, 2026
13 checks passed
@SheathedSharp
SheathedSharp deleted the fix/engine-run-log-follow-end branch November 11, 2026 09:59
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