Repository navigation
feat(traex): recover failed image prompts with safe retry and editing - #3856
Conversation
Co-authored-by: TRAE CLI <[email protected]>
Co-authored-by: TRAE CLI <[email protected]>
Co-authored-by: TRAE CLI <[email protected]>
|
你好,这个 PR 的自动评审群已建。自动拉群暂时没找到你的飞书信息,麻烦把 GitHub 账号和飞书信息补进名单文档,补好后我们会拉你进群:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe (本条为自动流程发出的提示消息) |
|
你好,这个 PR 的自动评审群已建,麻烦点击链接加入群聊、查看评审意见并跟进后续修改: 另外你暂时不在自动拉群名单里,也可以把 GitHub 账号和飞书信息补进名单文档,补好后后续评审会自动拉你进群:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe (本条为自动流程发出的提示消息) |
There was a problem hiding this comment.
复审结论:4 项阻断,不建议当前合入
复审对象是本地 0a8411b5。git range-diff b41c419c~3..b41c419c 1d4dd5bb..0a8411b5 三项均为 =,确认它与远端作者 head b41c419c 纯换基等价;工作树未保留任何探针改动。与评审时最新 origin/master 做 git merge-tree --write-tree 无冲突。
1. [阻断] strict retry 被取代后,已剪掉的失败输入不会恢复
位置:src/worker.ts:45068-45077,后续清理见 src/worker.ts:45225-45232。
cut 已落地后,如果另一 restart 使本次 respawn 变成 superseded,当前分支只执行 report('declined');strict 路径会删除 queued retry 并发送 turn_input_rejected,却没有 putBackFailedTurnCut,也没有把恢复责任移交给获胜 restart。下一次 settleFailedTurnRewindOffQueue(..., false) 只会记录“未恢复”。
**探针证据:**在现有 TRAE checkpoint worker transaction 真实 worker/文件夹具中执行 cutAfterExit → settle('superseded') → offQueue(..., false),重试已出队,但 rollout 仍只剩 prefix,原失败 user/error 后缀缺失。现有 worker-failed-turn-rewind.test.ts:898 只断言出队与 declined,没有断言 transcript 恢复,因而未咬住该数据丢失。
建议在获胜 CLI 已停止且可证明静默后恢复 cut,或把 cut/restore 状态显式移交给获胜 restart;不能只撤销输入。
2. [阻断] final/terminal 时序竞态会让实际失败卡缺少 Retry/Edit
位置:src/core/worker-pool.ts:33263-33269;记录仅在 terminal 回调中创建,见 src/daemon.ts:36449-36458。
失败 final_output 的渲染读取 ds.session.lastFailedTurn,但该记录由稍后的 turn_terminal 写入。final 已完成投递而 terminal 尚在异步 admission/持久化时,appendFailedPromptActions 只能原样返回;terminal 后也没有针对实际 final carrier 的补 patch。
**探针证据:**使用真实 daemon worker-pool 夹具:
- final 先投递、terminal 后到的序列中,terminal 后已确认存在
directFailure + traexPromptCheckpoint的lastFailedTurn,但整个序列只有一张卡,且只有purge_images_continue,没有retry_turn/ Edit。 - final 与 terminal 背靠背到达的对照探针通过,说明这是时序竞态而非卡片构造器本身失效。
建议让失败 final 等 terminal 记录就绪后再渲染,或在 terminal 记录提交后重新读取并 patch 本轮实际 final 卡片。
3. [阻断] 冻结的 trustedCaller 没进入 live-worker IPC
位置:src/im/lark/card-handler.ts:4572-4587;真实丢弃点见 src/core/worker-pool.ts:19423-19450。
卡片处理器把 failedTurn.trustedCaller 放在 retryInput payload 上,但 live-worker 调用没有把它放进 opts.trustedCaller。sendWorkerInput 构造 IPC、准入账本和后续失败记录时只读取后者,不读取 normalized.trustedCaller。TRAE 又明确只支持 live worker,所以这不是 fork 冷门分支,而是新 Retry/Edit/Continue 的必经路径。
**探针证据:**卡片层探针确认 payload 保留 caller 而 opts 为 undefined;再用真实 sendWorkerInput 发送同一形态 payload,最终 worker message 只有 type/content/turnId,trustedCaller 完全缺失。保留文本 envelope 并不等于保留 runtime principal/taskContinuation 绑定。
建议在 resend/edit/continue 的 opts 中传递冻结 caller,或让 sendWorkerInput 显式、规范化地回退到 payload caller,并补最终 IPC 断言。
4. [阻断] 重复或被拒消息会误取消图片修复续跑
位置:src/worker.ts:46491-46494。
activeTranscriptImagePurge.cancel() 位于 ordinary-turn 去重、backpressure 和 cross-principal 拒绝之前。因此 ACK 丢失后的重复投递,或一条随后被准入拒绝的消息,都能撤销合法修复;它们并没有成为“新接受的 successor”。此共用分支同时影响新 TRAE 修复与既有 Claude 图片清理。
**探针证据:**在现有真实 worker handler + 假时钟夹具中,修复等待旧 CLI 退出时注入一条被 activeTurnBlocks 拒绝的消息。该消息自身收到 turn_input_rejected,但旧修复租约也被撤销;推进退出时钟后,retry-1 的最终 writes 仍为空。
建议把撤销移动到重复/准入检查之后,并且只在输入实际被接受为 successor 时执行;补充 committed/inflight duplicate 与 rejected-before-admission 两类回归。
非阻断
test/failed-prompt-edit.test.ts:40,46,54新增了具体英文提示句断言;无害文案调整也会变红,不符合仓库“不钉文案”的测试原则。建议保留动作、turn 绑定、表单提交和状态迁移断言,删除这些句子级断言。test/traex-prompt-checkpoint.test.ts:99的 same-size modification 用例在本机仍复现 mtime 粒度抖动;它涉及本 PR 新增的verifyRead检测;在本机时间粒度下属于测试可靠性问题,未计入上述阻断。建议后续用可控 fstat 或内容级比对消除时间分辨率依赖。
本次验证
bun run build:通过(含 typecheck、dashboard bundle、build audits)。- PR 定向 11 个测试文件:
305 passed / 1 failed,唯一失败为上述本机 mtime flake;另一变更相关 worker 文件10 passed。 - 共享 rewind/recovery 套件另有
258 passed;TRAE 输入/中断套件另有235 passed / 1 skipped。 - 补充集成测试中有 9 个用例因本机 tmux socket 路径
File name too long而在 worker 初始 readiness 前退出;这是环境启动失败,未冒充断言通过,也未据此计为代码缺陷。 - 上述四个阻断均另跑了针对真实组件的临时行为探针;探针已从工作树移除。
严格重试在 restart 被取代时恢复已剪切记录,并按实际 final carrier 补齐恢复控件。trustedCaller 通过 live-worker opts 保留,图片修复只被已接受的后续输入撤销。补充同尺寸内容校验及对应回归。 Co-Authored-By: Claude Code <[email protected]>
superseded 恢复必须等待最新 detached CLI scope 退出,无法证明时保留备份并拒绝写回。旧 strict retry 未结算时工具图片清理直接拒绝,不再先停旧恢复;统一卡片测试使用条件等待。 Co-Authored-By: Claude Code <[email protected]>
|
已在作者分支追加修复,并以 fast-forward 推到新 head 修复内容
实际验证
新 head 的 CI 已触发,目前处于排队/执行中;本条不把尚未完成的 CI 写成通过。 |
master deepcoldy#3846 在 worker message case 内新增 activeTurnAuthority.snapshot(), 本 PR 新增的 worker-image-purge-intervention 函数夹具未注入该状态,合并最新 主干后其中 4 个用例在 harness 提取的 case 里抛 TypeError。补一行 snapshot: () => undefined,与 worker-failed-turn-rewind 既有夹具的注入一致, 仅测试 mock,不改生产代码。 Co-Authored-By: Claude Fable 5 <[email protected]>
deepcoldy
left a comment
There was a problem hiding this comment.
同步增量复审:d677018ba1..291d5740e5
结论:同步增量可合,0 个新增阻断。合码仍须等待 291d5740e5 的 CI 首跑全绿。
- 祖先关系:
d677018ba1仍是当前 head 的祖先;291d5740e5的直接 parent 是 merge commit4de055f617,merge 的两个 parent 分别为修复 headd677018ba1与主干36f11a21e3,原有五个提交均保留。 - merge 无隐藏改码:重新执行
git merge-tree --write-tree d677018ba1 36f11a21e3得到8a64cb9a327e74acaa10852f1c92121e7472a594,与4de055f617^{tree}逐字相同。没有冲突解决引入的额外内容变化。 - mock 提交范围:
291d5740e5仅修改test/worker-image-purge-intervention.test.ts,新增activeTurnAuthority: { snapshot: () => undefined }一行;没有任何src/变化。该默认值只补齐 master 新增读取点的夹具依赖,不替换生产实现。
实际验证:
bun run build:通过(typecheck、dashboard bundle、build audits)。- 原 CI 红文件
worker-image-purge-intervention.test.ts:Node14 passed,Bun14 passed / 0 fail。 - 合并后的原修复交叉路径:
worker-failed-turn-rewind+traex-failed-prompt-card-ordering共68 passed。 git diff --check d677018ba1..HEAD:通过;工作树干净。
CI 状态以服务端为准:本次核验时 network-boundary 已成功,其余 job 仍排队/执行中,本条不把尚未完成的 CI 写成通过,也不替代后续 G4/G7 检查。
保留非 edit 的 replayed hookEnvelope 机制;edit 直接使用 editedInput 且不错误退役旧 sidecar,trustedCaller 继续通过 opts 进入 IPC。保留 strict checkpoint rewind、detached 进程退出证明与 inline sidecar 回滚顺序。 Co-Authored-By: Claude Code <[email protected]>
合入 assistantGroupChat 主干更新,保留前一轮 hook 重放、trustedCaller、strict rewind 与 detached 退出证明融合结果。 Co-Authored-By: Claude Code <[email protected]>
|
已完成 master 语义融合并推送新 head 冲突解决
验证
新 head CI 已触发,目前各 job 正在排队/执行中;本条不把尚未完成的 CI 写成通过,合码仍需首跑全绿。 |
# Conflicts: # src/types.ts
deepcoldy
left a comment
There was a problem hiding this comment.
master 同步轻量复审:4dd1b7d356..04dd9e7cb0
结论:同步增量可合,0 个新增阻断。合码仍需等待本 head 的 CI 首跑全绿。
- Merge parents 为
4dd1b7d356与2bd3b49805,历史关系正确。 src/types.ts的DaemonToWorker.message同一 union 中同时保留nativeQuestionAnswer?: { requestId: string }与purgeToolImages?: true;两个可选字段位置不同、无相互覆盖或逻辑改写。worker.ts的其余大段变化来自 #3888 自身,不是冲突解决夹带;本 PR 新增的恢复文件traex-prompt-checkpoint.ts、traex-tool-image-recovery.ts、failed-prompt-edit.ts、failed-prompt-card.ts与 merge 前逐字相同,其他恢复控制文件也未被改写。
实际验证:
bun run build/ tsc:通过。worker-failed-turn-rewind、worker-image-purge-intervention、card-handler-retry-turn、traex-async-question、traex-native-answer-admission:共184 passed。git diff --check 4dd1b7d356..04dd9e7cb0:通过,工作树干净。
本条仅确认同步增量,不把仍在排队/执行的 CI 写成通过,也不替代最终 G7 tree 校验。
deepcoldy
left a comment
There was a problem hiding this comment.
G7 / #109 复核:当前不能豁免新 head CI
对 756f0499 的既有核验本身成立:merge-tree(756f0499, 04dd9e7) = 797868bb2c8cfbb8865cddb1611142441dcf6707,与本地 merge 98cf0cc 的 tree 一致。
但实际 master 已继续前进到 42f666399d,不能沿用旧 tree 的验证结论:
- 最新 master 整段 delta 与本 PR 的交集为
src/core/failed-turn-recovery.ts、src/core/worker-pool.ts、src/im/lark/card-handler.ts、src/types.ts、src/worker.ts;其中最新提交新增的交集包括失败恢复记录与卡片生命周期共用路径。 git merge-tree --write-tree 42f666399d 04dd9e7cb0虽无冲突,但新预测树为a60af8aeabd69db0ab493334a1a286b034caccc6,与已验证的797868bb不同。- #109 要求本地合并树上的 build/tsc/相关测试对最终预测 tree 有效。当前没有这棵新 tree 的验证证据,因此“零冲突 + 不相邻” alone 不足以背书直接 squash。
建议按原备选方案:merge 最新 master、普通 push 新 head,并在新 head 首跑 CI 全绿后再做 G7。 这不是对 756f0499 既有验证的否定,而是最新 master 变化后不能跨 tree 继承结论。
deepcoldy
left a comment
There was a problem hiding this comment.
最终 head 复审与 #109 豁免结论
1. d8d628450b:明确可合(G1)
- 最终 PR head 为
d8d628450b6600ac31b99493684dee609ce1beb1。 - CI run
45917448598绑定该 head,attempt=1、status=completed、conclusion=success,没有重跑。 - PR 上 15 项检查均为 completed/success(run 内 14 个 job +
network-boundary)。 - 本轮没有新的代码问题;该 head 的明确「可合」表态即为本条结论。
2. master 5e7f413883:背书 #109,可免再次同步和整套 CI 重跑
已逐项复核豁免条件:
- 交集:只有
src/worker.ts。 - 区段不相邻:#3891 仅在
codexBridgeNotifyCliSessionId附近新增 11 行(合并后约19511行);本 PR 最近的 term-action 变更在23940行,核心恢复函数从45868行以后开始,处于完全不同函数和调用区段。 - 三点 tree 一致:
git merge-tree --write-tree 5e7f413883 d8d628450b=2f09e0a5218d4327f64ffc0d568bd06e8dab064f;本地 merge16d5ad0f47的 tree 与此逐字相同,无冲突解决夹带。 - 本地合并树验证:
bun run build/ tsc 通过;nca-adapter、worker-failed-turn-rewind、worker-image-purge-intervention、traex-failed-prompt-card-ordering共103 passed。 - master 即时值:核验时 GitHub
commits/master仍返回5e7f4138834d3381fce843e545779a8d7c5d984a。
因此,可在仍保持首跑 CI 全绿的 d8d628450b 上按 #109 合入,无需仅为该 NCA 提交再制造 merge head 并重跑整套 CI。
合前硬条件仍保留:实际 squash 前重新 fetch;若 master 或预测 tree 再变化,必须针对新 base/tree 重新核验,不能沿用本条;squash 落地后仍须确认 merge commit tree 等于当时 merge-tree(实际 base, d8d628450b)。本条不执行 push、squash、发版或部署。
|
Thanks for this well-structured contribution @Sespeck! It has been squash-merged into master. The two recovery flows (tool-image cleanup with same-session resume, and checkpoint-backed Retry/Edit for prompts that failed before doing any work) fill a real gap where a poisoned Follow-up (non-blocking, tracked on our side):
This is an automated review summary; the final call always rests with the maintainers. Looking forward to more contributions! |
worker.ts/worker-pool.ts 由 git 自动合并;手动解三处: - src/types.ts:message union 字段并集,保留 scheduledRun 并补 deepcoldy#3856 的 purgeToolImages; - test/worker-codex-effort-input.test.ts:保留 Record<string,any> 类型并补 activeTranscriptImagePurge; - test/helpers/worker-function-harness.ts:补 isCriticalInterruptKey 真实函数供给, 供 deepcoldy#3856 后 handleTermAction 提取函数使用,消除测试夹具缺口。 Co-Authored-By: Claude Fable 5 <[email protected]>
|
🚀 Released in v3.59.35 |
Closes #3857
When TRAE fails to resolve an image, retrying the same saved history can fail repeatedly. This candidate adds an explicit tool-image repair and implements Retry / Edit prompt / Continue for a failed prompt, preserving the original conversation and checking whether any work ran before replaying it.
User flow
The illustration uses the candidate's actual English card JSON and a synthetic image, rendered in an isolated headless Microsoft Edge profile. It is not a live Lark screenshot. Runtime text follows the bot's configured locale.
Implementation and review scope
The worker freezes the native session ID, byte offset, and prefix hash at the actual independent input-write boundary. No-work proof requires one exact user request followed by an ordered native error terminal, with no tools, assistant output, compaction, later input, external send marker, or conflicting generation/Web input. Unknown history fails closed.
Reads and cuts share one descriptor inside the pinned native sessions root. The preserved prefix remains byte-identical; cut bytes are backed up outside that root. Retry/Edit reuse operator permission checks, exact session/turn binding, cooldown and rejection rollback, process-exit proof, and exact resume. Editing retains the frozen caller/envelope and keeps the original card carrier for provenance checks.
Stop/new accepted input cancels a held retry. Failed or superseded replacement cannot submit it or leave it in the successor journal. Restoring a cut requires an unchanged native prefix and tail, preventing native response records from being mistaken for Claude metadata. The existing image-repair candidate also fixes Stop/new-input races during tool-image cleanup.
Please review the new Edit callback/form and TRAE transcript-repair policy. The error does not identify which saved tool image is bad, so the repair action removes all saved tool-image blocks after an explicit click, preserving user images, text, tool receipts, and original image files. This candidate is undeployed.
CI correction
The full CI suite exposed 42 failures in four existing worker fixtures. Their isolated scopes lacked the new image-recovery state or the continuation-lease constructor. The harnesses now include the worker's initially empty recovery state and resolve the real
PurgeContinuationLease; the successful purge fixture uses a sandbox mode supported by its execution host.Correction:
b41c419. Expanded local verification on macOS: 892 Node tests passed, 2 existing skips, across 21 files; 177 Bun tests passed across eight isolated per-file processes. This includes every failing CI fixture and the new checkpoint, purge, and interrupt paths. The full CI run passed on this correction: all 15 checks are green, including all eight Node/Bun test shards and all three binary jobs.Validation
bun run build: passed, including typecheck, dashboard bundle, and build audits.bun run test -- <21 worker/recovery/transcript/test-hygiene files>: 892 passed, 2 existing skips on macOS arm64 / Bun 1.4.4. This covers actual native input-write checkpoint capture, the real worker rewind/restart/Stop paths, failed-respawn and successor-journal guards, edited image keep/remove, same-card editor behavior, permission and stale-card rejection, and existing Claude/Codex/TRAE behavior.git diff --check: passed.Native TRAE 0.216.0 in an isolated home accepts rollback of both a first prompt and a follow-up prompt. Native session IDs and transcript prefixes are unchanged; the follow-up retains one earlier completed turn. This uses a synthetic provider and makes no model request.
The English card preview was rendered and exercised in Microsoft Edge with an isolated temporary profile. Live Lark callbacks and the upstream image-upload service were not exercised.
Design details: prompt recovery and tool-image repair.