Repository navigation
fix(worker): 修正启动卡看门狗时序与降级恢复 - #3607
Merged
Merged
Conversation
Co-Authored-By: Kimi Code <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 19, 2026 09:31
deepcoldy
commented
Nov 19, 2026
deepcoldy
left a comment
Owner
Author
There was a problem hiding this comment.
审查结论(head be1962f64e)
未发现 P1/P2 级执行、投递或账本缺陷,但确认 4 组 P3 显示时序缺口,以及 3 项基线已有的健康归因问题、5 处测试缺口。4 组 P3 都落在本 PR 声明要完成的 starting/stalled 闭环内,建议修复并补回归后再合并;3 项既有问题可单独跟进。
以下生产问题均用真实 worker IPC handler / 发布路径 + 假时钟复现,不是仅读代码推断。
本 PR 范围内的生产问题
P3-1:首次数值 attempt 激活会让看门狗失效(含 restored 同类路径)
src/core/starting-card-health.ts:169:queued POST 建 entry 时dispatchAttempt快照为undefined;commitCaptureIdentity先写入当前 turn 的数值 high-water,activateStartingCardHealth再比较时判定身份不同并关闭 entry。- 探针:A(attempt=4) 持有 capture 时完成 queued B 的 POST,随后
capture_identity(B, attempt=0);45 秒后 PATCH 为[],预期应有stalled。 src/core/worker-pool.ts:21776有同类缺口:restored ready 的 starting PATCH 在途收到首个capture_identity(T, attempt=0),high-water 对象身份变化使ownsRestoredWrite()失败,PATCH 成功后仍跳过 reconcile/arm;45 秒后同样无stalled。- 修法:激活时允许 entry 采纳该 turn 首次获知的 attempt,restored fence 也需区分“首次获知 attempt”与“已知 attempt 的后续切换”,不能给所有身份比较加
undefined豁免。queued 处按此回填后,相关文件含探针 79/79。
P3-2:缺 attempt 的兼容 terminal 后会误报 stalled
src/core/worker-pool.ts:24673-24677:closeStartingCardHealth被放进严格 high-water 等值闸;high-water 为 attempt=1、terminal 省略 attempt 时,闸不成立,兼容 terminal 不再关闭看门狗。- 探针:
noteTurnDispatchAttempt(T, 1)→ arm →turn_terminal(T, completed)(无 attempt),45 秒后实际 PATCHstalled。 - 基线在 high-water 闸外按 turn 关闭健康 entry,因此这是本 PR 引入的回归;
worker-pool.ts:24723-24735也明确保留了缺 attempt terminal 的兼容处理。 - 修法:把 close 移回 high-water 闸外,依靠
entryMatchesTerminal的“缺 attempt 兼容、显式旧 attempt 拒绝”规则。临时验证此修法后,缺 attempt terminal 与旧 attempt retry 两个探针同时通过。
P3-3:晚到 starting 发布的终态 reconcile 不完整
src/core/worker-pool.ts:6780-6781,7155-7164。- completed + cached idle:慢 starting POST 期间 terminal 到达,
lastScreenStatus已是 idle;lastScreenStatus ?? starting取 idle,busy 闸拒绝修正。POST 完成后及 2 秒 settle 窗口均无 idle PATCH,刚交付的 starting 成为最终显示。 - failed/cancelled:restored starting PATCH 在途收到终态后,
reconcilePublishedStartingCardTerminal返回 true 并禁止 arm,却不安排非 starting 结算;两种探针在 45 秒时最终 delivered 均仍为starting。 - 修法:把刚交付的 starting 渲染本身视为忙碌显示证据;对其它已接受终态重断言合适的非 starting 展示,或在完成修正前不要把 publication 当作已 reconciled。
P3-4:截图健康恢复未完成重绘与 usage 恢复
src/core/worker-pool.ts:23243丢弃noteStartingCardHealthFrame的恢复返回值。- stalled 后,working screenshot 在
displayMode已切回 hidden 时到达:degraded 被清掉,但src/core/worker-pool.ts:23297直接 break,PATCH 为[],可见卡片保持 stalled。 - screenshot 模式下同类帧能 PATCH working,但 degradation 停止的
usageRefreshTimer仍为undefined,后续若只有截图帧,usage 不再刷新。 - 修法:在 managed/substitute 等授权闸之后使用 recovery 标记强制恢复 PATCH,并仅对原本符合
usageRefreshShouldRun的会话恢复 timer;保留“普通 screenshot 不随意 arm usage”的现有限制。
基线已有问题(不作为本 PR 新回归计数)
- 旧 attempt 帧可撤销新 retry 看门狗 —
src/core/starting-card-health.ts:72不接收 attempt。attempt=2 已 arm 时送入延迟screen_update(T, attempt=1, working),45 秒后无stalled。基线实现同样缺少 attempt 归因。 - untagged POST 在途健康帧仍丢失 —
src/core/starting-card-health.ts:92在 pending/degraded 尚未建立时把帧记到turnId: ''。legacy untagged working 在 POST 在途到达后,45 秒仍误报stalled;基线行为相同。 - 异 turn 帧会覆盖当前 POST 的健康序号证据 —
src/core/starting-card-health.ts:28每 session 只有一个latestHealthy。A POST 在途依次收到 A/working、尚未beginNewTurn的 B/working 后,A 的健康证据被覆盖,45 秒误报stalled;基线行为相同。
测试缺口复核
identityStillCurrent的 fire 路径 attempt 比较(starting-card-health.ts:41):新增 retry 探针在当前代码下正确不误降级;删除比较后立即误发stalled,原用例未钉住。entryMatchesTerminal的 attempt 匹配(starting-card-health.ts:104):单删内层条件,原文件 77/77 仍绿;再移除外层整个 high-water 条件才咬红。若采用 P3-2 的修法,内层匹配将直接承担保护,必须补测。buildStreamingCardJson默认 stalled fallback(worker-pool.ts:12845)、显式异 turn 隔离(starting-card-health.ts:59)、cachedStreamingCardStatusstalled 投影(worker-pool.ts:4740):当前行为均正确;分别删除守卫后,对应探针分别退回 working 或让异 turn 继承 stalled,现有用例未覆盖。
验证
- 原始 PR 代码:
bun scripts/fenced-run.ts -- bun x vitest run test/post-terminal-status-settle.test.ts test/tmux-pipe-backend.test.ts test/worker-ready-display-mode.test.ts→ 404/404。 - CI run
44497224138已完成,14/14 jobs success。 - 所有临时探针、变异与修法实验均已还原;工作区干净,未改动 PR 内容。
- 允许 queued/restored 发布采纳首次 attempt,保留 retry 身份围栏\n- 兼容缺 attempt terminal,并补齐晚到发布的终态重绘\n- 截图恢复健康时同步恢复卡片状态与 usage 刷新 Co-Authored-By: Kimi <[email protected]>
deepcoldy
commented
Nov 19, 2026
deepcoldy
left a comment
Owner
Author
There was a problem hiding this comment.
G7 合并树复核背书(非相邻豁免)
确认该合并树可合。
独立复核结果:
- live
master:ce0a03a95d2527031dd0c90dd6f92f7af818ed97 - PR head:
43048e1d7e96f413ba6ac140b2bf882272a120c1 - 以共同基线三点 diff 求交集,确为
src/core/worker-pool.ts、src/types.ts、test/tmux-pipe-backend.test.ts三个文件。 - 本地重新执行
git merge-tree --write-tree --messages ce0a03a95d 43048e1d7e,退出码 0;得到同一预测 tree:ef97f2314cc2ed1a63d86dc4916fb2cdc9a1644e。输出仅有上述三个文件的Auto-merging,无CONFLICT。 - G4 run
44583485797经 API 确认为run_attempt=1、status=completed、conclusion=success,主 CI 14/14 jobs success;PR 当前可见 checks 均为 pass。 - 本地仍停在 PR head,工作区干净;本次只重算合并树,未改 PR head,也未保留本地 merge 状态。
本背书绑定上述 master、PR head 与预测 tree。squash 落地后应核验落地提交的 tree 仍为 ef97f2314cc2ed1a63d86dc4916fb2cdc9a1644e;若合入前任一输入继续前移,或落地 tree 不一致,则此背书不再适用,需重新复核。
deepcoldy
pushed a commit
that referenced
this pull request
Nov 19, 2026
This was referenced Nov 19, 2026
|
🚀 Released in v3.59.23 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动说明
修复 #3593 后续确认的启动卡看门狗时序与显示状态问题:
capture_identity激活后才开始 45 秒宽限; queued 期间异 turn、untagged 与 prompt_ready 都不能代为撤防。lastScreenStatus、usage 结算或 turn reaction。usage tick 停止覆写,普通 PATCH / 卡片按钮重绘保留 stalled,首个合格健康帧即使同值 working 也强制恢复。dispatchAttempt纳入 entry 身份,旧 attempt terminal 不能关闭新 retry 看门狗;普通 starting POST 与 worker-ready fresh/restored 发布共用 arm helper;prompt_ready 不再冒充屏幕健康帧。晚于 terminal 完成的发布不会重新 arm,completed terminal 会补做终态显示结算;restored 长 PATCH 后按 status revision 重 assert 最新 working。execFile的code:null + killed:true + SIGKILL形状,保持原 reject 行为。inFlight字段。说明:
screen_update.status的生产类型不含 starting,因此发布路径补测使用真实可达的 worker-ready fresh/restored 边界,不保留合成 starting screen_update 的无效探针。影响面
TmuxPipeBackend错误日志分类,同步空串和异步 reject 语义不变。测试验证
post-terminal-status-settle+tmux-pipe-backend+worker-ready-display-mode404/404。bun run build(含 typecheck)与git diff --check通过。独立对抗复核发现与修复
starting → stalled。已在共享 arm 入口按 turn/attempt 拒绝 terminal 后重建;completed terminal 补做 idle 结算,completed/failed/cancelled 均有回归。working → starting。现 restored 成功后按 status revision reconcile;测试记录 delivered 顺序,删除 reconcile 的变异咬红。undefined !== 1曾导致 terminal 后重新 arm。现无 high-water 时信任已被 handler 接受的 terminal,仅同 turn high-water 用于旧 attempt 否决;missing/matching/newer 三组用例覆盖。File name too long与/tmp/bm0alias 断言(workspace-recycle单跑仍复现同样 2 个路径失败)及并发集成错误,本地全量结果不记为通过,需由 CI 继续核验。卡片状态示意沿用 #3593,无新增视觉样式:
🤖 Generated with Claude Code