Repository navigation
fix(traex): 修复输入隔离与异步问答状态持续阻塞 - #3956
Conversation
Co-authored-by: TRAE CLI <[email protected]>
codexBridgeIngest 新增的 traexTurnCompletion 模块级单例未纳入 worker-function-harness 的默认作用域,导致既有的 worker-bridge-final-idle-signal 四個用例以 undefined.observe 失败。 按同类单例(TraexFirstPromptReadinessPoller)的模式补惰性注入, 并新增 bridge queue 仍有未终结 turn 时不记录 transcript terminal 的 接线用例,覆盖此前无测试能咬红的队列守卫。 Co-Authored-By: Claude Fable 5 <[email protected]>
|
自动评审补充:首审发现一处会让既有测试变红的接线遗漏,已在本分支直接追加一个测试侧修复 commit(eb758eeb0c,未改动原提交、未 force-push)。 问题: 修复内容(仅测试文件):
本地验证(基于最新 origin/master rebase 后的树): 以上为自动评审的初步意见,最终以维护者审阅为准。 |
deepcoldy
left a comment
There was a problem hiding this comment.
复审结论(head eb758eeb0c)
发现 1 个 P1 生产路径缺口,建议修复后再合并。代修的 harness 注入本身未发现问题。
P1:queue 守卫会永久丢掉已完成证据,逆序 final 后 stale question 仍持续阻塞
位置:src/worker.ts:20990-20995,相关状态机在 src/services/traex-turn-completion.ts:23-37。
TraexTurnCompletionTracker 只在“最新 native turn 的 final 当次到达”时返回 completed=true;worker 又在 bridge queue 仍有 open turn 时丢弃这次 noteTranscriptTerminal()。这里没有 pending/latch,后续 queue 排空本身不会补记。
仓库已经明确支持多 type-ahead turn 的逆序完成:test/traex-transcript.test.ts:2065-2132 覆盖三个 turn 按 2 → 3 → 1 完成。把同一真实事件序列接到本次新增的 completion 逻辑后:
- turn 3 的 final 到达时,tracker 返回
completed=true,但 turn 1 仍 open,queue 守卫阻止记录; - turn 1 的 final 最后到达并排空前,tracker 的 latest 仍是已经关闭的 turn 3,因此本次返回
completed=false; - queue 最终为
[],再做空 drain 也没有新事件,noteTranscriptTerminal()永远不会调用,releaseStaleQuestionStatus()持续为false,后续输入仍被 question 状态挡住。
新增接线用例 test/worker-bridge-final-idle-signal.test.ts:137-147 在 queue 排空后又喂入了 turn 2 的 user + final,所以靠的是下一轮完成重新产生证据,没有覆盖“最后一个 open turn 已终结、之后没有新 turn”的收口序列,现有测试全部通过也咬不住这个缺口。
真实组件探针结果(drainTraexRollout + CodexBridgeQueue + 从 worker 提取执行的真实 codexBridgeIngest + IdleDetector,经 fenced-run 隔离):
after newest final: noteTerminal=0, queue=[[d1,false],[d2,true],[d3,true]]
after delayed oldest final and empty drain:
noteTerminal=0, released=false, block={kind:"question"}, queue=[]
REPRODUCED: queue empty, stale question still holds
建议让被 queue 守卫暂缓的完成证据能在最后一个 open turn 终结时结算,或让 tracker 跟踪所有 open native turns;同时保留新 native user、输入周期及 working/blocked 报告使旧证据失效的约束。回归用例应直接复用上述 2 → 3 → 1 顺序,并在最后只做空 drain,不能再靠额外新 turn 完成来补足证据。
其余复核与验证
test/helpers/worker-function-harness.ts的traexTurnCompletion惰性注入与同类单例模式一致,既有 4 个 bridge final 用例恢复通过。- 直接复核了
releaseStaleQuestionStatus()的新输入、working/blocked、活跃子任务、evicted busy 与非 question 阻塞失效路径;除上述跨 drain 收口缺口外,未发现新的误判释放路径。 - 本地相关 9 个测试文件:355 通过、1 个既有跳过;包括
worker-bridge-final-idle-signal、stale-program-status、question/quarantine,以及traex-transcript、codex-bridge-lifecycle-overlap、traex-shared-adopt-flow。 git diff --check ac56aaf7f4..eb758eeb0c通过。
deepcoldy
left a comment
There was a problem hiding this comment.
补充复审:另外 4 个问题均经真实组件探针确认
更正上一条 review 中“除跨 drain 收口缺口外,未发现新的误判释放路径”一句:继续攻击 PTY 渲染与窄视口交叠后,另确认两处可能错误释放保护的路径。以下探针均经 bun scripts/fenced-run.ts 隔离执行。
1. P1:PTY 会凭尚未绘入 question 的 renderer 旧帧释放真实阻塞
位置:src/worker.ts:26062-26070、src/worker.ts:35024-35029。
PtyBackend 没有 captureViewport/captureCurrentScreen,因此这里走 renderer.rawSnapshot()。但 TerminalRenderer.write() 明确是异步解析,只有 writeAndFlush() 才是读取屏障(src/utils/terminal-renderer.ts:82-99);本次释放路径没有像 traexQuestionCapture() 那样先 settle。
真实 TerminalRenderer + PtyBackend + worker traexQuestionBlockReported + IdleDetector 探针:先绘入空 composer,再把真实 question fixture 交给 renderer.write(),在 xterm flush 前调用释放检查:
beforeFlushShowsQuestion=false
releasedBeforeQuestionParsed=true
afterFlushShowsQuestion=true
blockAfterRelease=null
即 question 字节已经到达 renderer、但尚未解析时,旧空屏会删掉真实 kind=question 状态;随后屏幕实际绘出的仍是提问页。tmux 的原生 capture 不受这一条影响。PTY 释放前应使用带 renderer settle 和 backend/lifetime 复验的采集路径;在同步调用改造成异步之前,宁可禁止该 fallback 回收 question 状态。
2. P1:Send after tool call 头在窄终端折行后,待执行输入被判为空屏
位置:src/adapters/cli/traex.ts:308-322。
面板头只接受完整单行,向上扫描遇到无法识别的折行碎片又会 break 后返回 true。同一个真实 pending-input 面板分别经 160 列与 40 列 TerminalRenderer 渲染:
cols=160: headerRows=["Send after tool call · esc to interrupt and send · ↑ to edit"]
judgedNoPendingInput=false
cols=40: headerRows=["Send after tool call · esc to interrupt ", "and send · ↑ to edit"]
judgedNoPendingInput=true
40 列下旧草稿与 Send after tool call 面板仍在,连续两次 poll 却可解除 quarantine。需要对折行/截断面板失败关闭,并增加真实窄视口回归,不能把无法识别的面板碎片当作安全放行证据。
3. P1:legacy id-less user 经 turn_bind 收口后,tracker 仍永远没有完成证据
位置:src/services/traex-turn-completion.ts:17-37。
首个无 sourceTurnId 的 user 会把 latest 置为 undefined。TRAE parser 随后可产生 turn_bind,真实 queue 据此能把同一输入与 final 正确关联;tracker 却完全忽略 turn_bind,所以最终 assistant_final 没有可匹配的 latest turn。
真实 drainTraexRollout + queue + worker ingest + detector 探针,按三次 drain 输入:无 turn id 的 user_message → 带 turn id 的 item_completed(UserMessage) → 同 turn 的 task_complete:
noteTerminal=0
queue=[]
released=false
block={kind:"question"}
这是单 turn 即可到达的正常 legacy 形态,不需要逆序 final。tracker 需要消费 parser 的绑定结果,或自行绑定最近的 id-less 原生输入;回归应验证 queue 收口的同时 completion 也能收口。
4. P2:额外强制可见 Context 文本排除了已支持的有效空 composer
位置:src/adapters/cli/traex.ts:313-315。
共享的 traexRestoredComposerReady(..., { requireThreadReady: true }) 已能识别严格初始化条件,包括长 cwd 在 Context 前以 U+2026 截断、以及有初始化内容佐证的 hint-only footer;本函数随后又强制要求 Context 文本,使这些有效会话永远无法走空屏恢复。
两种屏幕的探针结果均为:
restoredReady=true
threadReady=true
noPendingInput=false
长 cwd 变体直接取自现有 test/traex-startup-readiness.test.ts:387-397,508-526 已支持的形态。建议复用严格共享判定,而不是再加一个与既有初始化协议不一致的 Context 必要条件;provisional shortcut-only 页面仍应继续拒绝。
除上述探针外,本地又补跑 test/worker-traex-question-page.integration.test.ts 与 test/traex-quarantine-late-receipt.repro.integration.test.ts:16 个真实 worker 集成用例全部通过;bun run build 通过。说明现有集成覆盖同样没有触到这些边界。
跟踪所有 open native turn 并消费 turn_bind,覆盖逆序 final 与 id-less user;question 回收禁用未 settle 的 PTY renderer fallback;空屏判定复用严格初始化条件并对折行面板 fail closed。 Co-Authored-By: Claude Code <[email protected]>
PTY 同步热路径继续 fail-closed,异步 capture 在 writeAndFlush 后复验 backend、lifetime、generation 与 hold revision 再回收 stale question;收窄折行面板片段匹配,避免普通英文行误阻塞。 Co-Authored-By: Claude Code <[email protected]>
已粘贴 draft 的 submit guard 在 PTY 上也执行 settled capture,重算 question 阻塞并在 await 后复验 current,避免仅依赖其它 capture 路径介入。 Co-Authored-By: Claude Code <[email protected]>
|
已推送复审修复,当前 head: 修复内容
提交:
验证
扩展扫描与环境对照(不计为通过项)
CI 已在新 head 上排队。 |
两个真实 TerminalRenderer 用例在 bun:test 单进程内,xterm-headless 的异步解析与 fixture 的 fake timer 交错,污染同文件后续 fake-timer 用例(bun-test 3/4 红 16 项,master 同文件 bun 全绿证明为本 PR 引入的引擎兼容问题,非生产逻辑回归)。渲染保真断言仍由 vitest 的 Node worker 完整覆盖,按仓库既有 it.skipIf(process.versions.bun) 模式限定这两个用例 Node-only,bun:test 下其余 40 项全部通过。 Co-Authored-By: Claude Fable 5 <[email protected]>
|
补充一个测试引擎兼容修复(commit a007898,仅测试文件,未改生产代码、未改任何断言): 上一轮 head 在 bun-test (3/4) 首跑红 16 项,全部集中在 test/traex-parked-submit-recovery.test.ts。我用双引擎对照定位:
按仓库既有先例(program-status-relay、feedback-pg 等的 本地双引擎验证:bun:test 该文件及两个姊妹 quarantine 文件共 81 项 0 失败(2 个引擎跳过);vitest 42/42;typecheck 通过。合并树(master 64ada8a)上 cherry-pick 后同样 bun 0 失败、vitest 42/42。 以上为自动评审的初步意见,最终以维护者审阅为准。 |
deepcoldy
left a comment
There was a problem hiding this comment.
a007898e8a 测试兼容增量复审
未发现新的阻断或待改项;这两处 Bun 引擎跳过可以接受,最终仍以新 head 的 CI 全绿为准。
- 增量仅修改
test/traex-parked-submit-recovery.test.ts,只给两个真实TerminalRenderer用例添加it.skipIf(!!process.versions.bun)与原因注释;没有生产代码或断言变化。 - skip 条件与仓库已有的
program-status-relay/feedback-pg先例一致,作用域仅这两个用例,不扩散到同文件其他 fake-timer 回归。 - 本地 Node/Vitest:42 通过、0 跳过,证明 PTY 列间距和 40 列折行两条渲染保真用例仍实际执行,没有丢失 Node 覆盖。
- 本地 Bun:40 通过、2 跳过、0 失败;后续 fake-timer 用例恢复稳定。两个邻近 quarantine 套件 Bun 分别 27、12 通过,Node 合计 39 通过。
bun run typecheck与git diff --check 4a1531cd34..a007898e8a通过;增量文件清单只有上述一个测试文件。
复审时的 CI 状态:build、network-boundary 已绿,其余 test / bun-test / binary 仍在排队或运行,尚未把 CI 结果计为通过。
|
G7 合并树复核无异议,可以合码。
未修改 PR、未执行合码、未发版或部署。 |
|
已合并,感谢 @fangyeqing 的贡献。 这个 PR 为 TRAE 本地终端会话补齐了两类输入保护的恢复路径(遗留 question 状态回收、未确认提交的输入隔离解除),并让后台巡检能正确识别未注册 bot 的纯合约库;全程保持 fail-closed,不自动重放去向不明的输入、不替用户答题。 评审中一起打磨的点:原生 turn 收口覆盖了逆序 final 与 legacy id-less 输入、PTY 渲染屏障后的异步回收与身份围栏、窄视口折行面板的 fail-closed 判定,以及 bun:test 引擎下两个 xterm 渲染用例的 Node-only 兼容处理。无遗留 follow-up;评审中发现的 CI 高负载启动竞态由独立 issue #3957 跟踪。 欢迎继续贡献。 |
master #3956 在 worker-bridge-final-idle-signal 新增的 TRAE native turn completion describe 使用极简 idleDetector stub,缺少本 PR 引入的 programStatusHeldWorking 依赖(codexBridgeIngest 经 traexNativeContinuationActive 读取)。合并后该用例 TypeError,补 programStatusHeldWorking: () => false 与同文件首个 describe 一致; 该用例场景无原生续跑,false 符合设定,不改变其 reversed finals 断言。 Co-Authored-By: Claude Fable 5 <[email protected]>
|
🚀 Released in v3.59.37 |
TRAE 已结束当前轮次、终端也恢复普通输入框时,遗留 question 状态或未确认输入的隔离仍可能持续挡住后续消息;未注册的纯合约库缺少 sessions 表,还会让后台巡检整轮跳过。
本改动为这两条输入保护补齐恢复条件,并识别完整的纯合约库。恢复仍要求精确完成或输入消失的证据,不自动重放结果未知的原消息。
改动
验证
影响范围
question 状态回收仅接入 TRAE 的本地终端路径,不包含 RPC、adopt 与远端。空输入恢复继续遵守既有隔离流程的 backend、代次、身份和屏幕权威性守卫。屏幕采集新增 opt-in 格式保留参数,其他调用方默认行为相同。跨库格式识别用于后台清理的完整保护清单,不改写或删除遗留数据库。