Skip to content

fix(engine): up --wait 只按本次运行确认就绪 - #278

Merged
SheathedSharp merged 4 commits into
mainfrom
fix/engine-ready-run-identity
Nov 11, 2026
Merged

SheathedSharp merged 4 commits into
mainfrom
fix/engine-ready-run-identity

Conversation

@SheathedSharp

Copy link
Copy Markdown
Owner

问题

A 用 up --wait 启动 R1 并在客户端等待时,B 把同一 worktree 的同一服务重启为 R2。waitForStartReady 在确认运行身份之前就用服务行的健康状态判定成功:R2 健康后,A 会把 R2 的结果算到 R1 头上并输出就绪。上一步的误停问题(超时清理按 run_id 授权)已关闭,这里是同一类结果归属错误。

改动

  • 就绪判定先认运行身份(engine/internal/cmd/up_ready.go):状态行指名另一个运行即为 run_replaced,立即以 failed 结束并不停止任何运行(替换运行不是本次调用启动的)。
  • 状态行无法指名本次运行(包括未归属到该运行的监听)时不算就绪,继续等待到超时。
  • chunk 完全没有 run_id 的旧 daemon 没有可比对的身份,保持原来的服务行判定。
  • docs/cli.md / docs/cli.zh.md 同步说明;JSON 的 state 仍是 failed,新增 reason 值,不改 schema。

验证(实际执行)

  • go build ./...、go vet ./...、go test -count=1 -timeout=8m ./...(engine,已合并 origin/main bba30941):通过
  • go test -race ./internal/cmd/ -count=1:通过
  • python3 scripts/check_docs.py:6 pair(s) consistent
  • python3 -m unittest discover -s scripts -p '*_test.py':267 tests OK(skipped=1)
  • 新回归测试 TestWaitForStartReadyCreditsOnlyTheRunItIsAbout 在修复前失败(run run-r1 was reported ready on run run-r2's evidence),修复后通过;TestWaitForStartReadyConfirmsItsOwnRun、TestWaitForStartReadyKeepsLegacyChunksUsable 防止规则过度收紧。

真实场景与未覆盖

在隔离 HOME/BERTH_HOME 的丢弃项目里用 restart 跑了 4 次:修复前后二进制都先观察到 R1 的停止退出(reason=stopped),本地没有命中“R2 先于 R1 退出记录登记、旧退出被 generation 守卫丢弃”的竞态窗口,R2 先登记的时间窗口在本地不可控。该状态由回归测试直接构造(状态行指名 R2 且健康、无 R1 退出记录)。完整 race 门槛与真实服务清单按每日/发版路径执行,本 PR 未跑。

🤖 Generated with Claude Code

SheathedSharp and others added 4 commits November 11, 2026 18:15
waitForStartReady 直接调用 groupRowsObserved,就绪规则只能靠真实扫描或超时来观察。收成包级变量
startRows(生产仍读 status 的同一快照),让规则可以在指定的状态行上验证。

Co-Authored-By: Claude Code <noreply@anthropic.com>
A 启动 R1 并等待时,B 把同一服务重启为 R2;R2 健康后,等待会把 R2 的健康算到 R1 头上并报告就绪。
就绪判定现在先认运行身份:状态行指名另一个运行即为 run_replaced,立即失败且不停任何运行;
状态行无法指名本次运行时(包括未归属到该运行的监听)不算就绪,继续等待;
完全没有 run_id 的旧 daemon 没有可比对的身份,保持原来的服务行判定。

Co-Authored-By: Claude Code <noreply@anthropic.com>
补充 --wait 的归属规则:状态行指名另一运行即 run_replaced 且不停任何运行;无法指名本次运行不算就绪;
没有 run_id 的 chunk 保持旧行为。中英文同步。

Co-Authored-By: Claude Code <noreply@anthropic.com>
@SheathedSharp
SheathedSharp merged commit c620942 into main Nov 11, 2026
13 checks passed
@SheathedSharp
SheathedSharp deleted the fix/engine-ready-run-identity branch November 11, 2026 10:27
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