Repository navigation
fix(codex): rollout 晚于 history 行出现时仍能接上 transcript,不再丢本轮回复 - #2401
Merged
Merged
Conversation
Codex 在首条提交时才懒创建 rollout,history.jsonl 那一行与 rollout 由两路独立写入; history 行先可读而 Codex 进程还没打开 rollout 时,writeInput 拿不到属主证明就把 session id 丢掉,新起的会话再没有别的途径找到 rollout,20s 预启动租约到期后放弃 收集并在话题里提示「采集不到本轮回复」(#2363)。 现在这个 id 作为候选返回(不当作 session id、不持久化、不算消费证明);transcript 未接上时 worker 记下它,轮询到 Codex 进程确实持有该 rollout 才接上,并补发原本 就该有的会话 id 持久化与 codex_history_match 消费回执。外来 id 永远不会被本进程 持有,因此不会被绑定;候选只服务于产生它的那一轮,那一轮结束或被放弃后即丢弃。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 27, 2026 01:42
history 行晚于 writeInput 带内轮询时,只有 20s 后的延迟复查能看到它;复查确认会 给这一轮重新起 20s 租约,而 rollout 仍可能没被 Codex 进程打开。之前候选只在带内 路径保留,settleDeferredSubmitConfirmation 与 settleVerifiableSubmissionForJournal 两个结算点都把它丢掉,这一轮照样「采集不到本轮回复」。现在两处都把候选交给与带内 相同的等待属主逻辑。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
自动评审初步意见:1 个 P2 建议修改后再合(最终以维护者审阅为准)首审结论为可合,复审发现一处可达的 P2 竞态缺口,与本 PR 修的是同一类问题,建议一并修掉。 P2:deferred recheck 看到 history 行时,候选 session id 在两条结算路径上被丢掉带内路径(writeInput 的 ~3.4s 轮询)已经通过
为什么这是真丢回复而不只是理论缺口:recheck 成功后 建议改动(4 处代码/测试 + 1 个补充单测)
已验证
本评论为自动评审的初步意见,最终以维护者审阅结论为准。 |
added 3 commits
October 27, 2026 20:39
This was referenced Oct 27, 2026
deepcoldy
pushed a commit
that referenced
this pull request
Oct 28, 2026
#2401 follow-up: - deferred recheck 路径的用例补 cli_session_id IPC 断言(去掉延迟绑定里 的 persistCliSessionId 即红); - 新增「history 行只被 deferred recheck 看到 + 外国 sid」用例:外国 rollout 在磁盘上可按 sid 解析但当前观测进程从不持有,延迟属主候选仍不得绑定 (去掉 fd 属主闸即采集到外国回复,用例变红)。
|
🚀 Released in v3.55.0 |
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.
修 #2363 中 #2381 覆盖不到的那部分。
与 #2381 的关系(同步 master 后)
#2381(已合入)对开了提示注入的 Codex 会话,在首条提交、进程还没持有任何 rollout 时,给输入附一个一次性
botmux_input_id标记,靠它直接证明 history 行属于本窗格。所以默认配置下 #2363 的竞态(含 CI 里那个用例)已由 #2381 修好:证明成立时 adapter 直接返回已证明的cliSessionId,本 PR 的候选路径不会走到。本 PR 仍需要的场景:
promptInjection: 'none'):fix(codex): 沙盒无法读取进程文件时仍能定位回复转录 #2381 不附标记,竞态照旧,只有这里的候选逻辑能接上 transcript。本机 fleet 55 个 bot 中有 9 个 Codex,其中 1 个是零注入。两者不冲突。合并 master 后,集成用例固定在零注入会话上(
promptInjection: 'none'),这样测到的仍是候选路径。现象
Feishu live run 40217853930 里,Codex DM thread 会话
3e938888的首条消息已经写进 Codex,mock LLM 也收到了请求,但 worker 在 20s 预启动租约内一直没接上 transcript,最后放弃收集,并在话题里发「采集不到本轮回复」。根因:找 transcript 时的竞态,不是改接选错进程
和 #2380(剥启动层)无关:同一个 run 里另外 13 个成功的 Codex 会话也都先后被改接两次(session-scope → npm launcher,Codex launcher → native 叶子进程)。失败会话这两次改接也都对,写入消息时
backend.cliPid已经是持有 rollout 的叶子进程 23136。失败会话与成功会话唯一的确定性差别是:成功的在写入后约 0.5s 依次打出Published CLI session id和Codex bridge fresh-empty: <rollout>,失败的这两条都没有。也就是 bridge 从没 attach。(issue 时间线里 mock 收到请求的时间应为 21:20:43.989,即写入后约 0.5s,不是 21:20:49。)机制(用本机 codex-cli 0.164.0 实测,与 CI 同版本):
historyMatchResult(…, requireOwnership=true)只返回{ submitted: true },把 session id 丢掉。引入点:
0623210c2b(#1770,v3.40.0 起)。它为防止共享 history 误绑到别的窗格,改成「证明是本进程的才返回 sid」,结果把codexBridgePendingSessionId注释里本来写明要兜的情形(rollout 在提交后稍晚才出现)也一起堵死了。改法
src/adapters/cli/codex.ts):命中 history 但证明不了属主时,把 id 放进unprovenCliSessionId作为候选返回。它不是cliSessionId,不会被持久化,也不算消费证明;已证明属主的路径不变。src/worker.ts):codex_history_match消费回执和原生会话标题。lsof),由下一条消息自己带证明。settleDeferredSubmitConfirmation(普通延迟复查)和settleVerifiableSubmissionForJournal(ZMX journal)两个结算点也把候选交给同一套等待属主的逻辑,不再丢掉。影响面
影响 Codex TUI(
cliId: codex)在 PTY / tmux / zmx 下的非 adopt、非 RPC、非 codex-app 会话。fix(codex): 沙盒无法读取进程文件时仍能定位回复转录 #2381 合入后各组合的属主证明路径明确如下:promptInjection: 'none')+ fd 不可读,或 history 行先于 fd 打开correlateTranscript只在默认注入(非零注入)会话开启,所以本 PR 的候选路径在 fix(codex): 沙盒无法读取进程文件时仍能定位回复转录 #2381 之后收敛到零注入会话,以及「history 行先于本进程打开 rollout」这一懒创建竞态本身(与注入模式无关)。rollout 先打开时行为逐字不变。adopt 会话不走这里(adopt 的写入分支不读候选,原本就有按 pid 兜底);codex-app 用的是自己的 writeInput;其它 CLI 不设置这个字段,也就不受影响。
老用户零 breakchange:没有配置、命令或持久化格式变化。可见行为变化只有一处:原本会弹「采集不到本轮回复」的这类回合,现在能正常转发回复。修 bug,不加开关。
平台:Linux 上用
/proc/<pid>/fd枚举,开销很小;macOS 上用lsof,只在候选所属那一轮还在等 transcript 时才枚举。验证
bun run build通过,tsc --noEmit无报错。相关测试 9 个文件 857 passed / 1 skipped:
codex-adapter-history-ownership、write-input、cli-adapters、codex-worker-bridge-wiring、codex-transcript、新增的worker-codex-lazy-rollout-ownership.integration、worker-collaborative-oncall.integration、test-hygiene、submit-confirmation。新增集成测试
test/worker-codex-lazy-rollout-ownership.integration.test.ts(真 worker 进程 + 假 Codex):假 Codex 先写 history 行,等 worker 已经在「没有证明」的情况下处理完这次提交后,才懒创建并打开 rollout。三个用例:cli_session_id和codex_history_match消费回执;另用
worker-function-harness直接执行settleVerifiableSubmissionForJournal,确认 ZMX journal 结算会把延迟复查得到的候选交给 flushPending。master 上复现:同一个假 Codex(屏障换成写入后等 3s)在 origin/master 上精确复现 CI 的日志签名:写入后既没有
Published CLI session id也没有Codex bridge fresh-empty,只有Ignoring prompt-ready heuristic…;rollout 在写入后约 3s 就已打开,但 20s 后仍打出同一条Structured bridge could not collect turn …: no transcript start before the pre-start lease expired。同一变体在本分支 2/2 通过。变异(12 处,在 isolate-run 里跑)全部被杀死,且都由对应用例杀死:
未单独覆盖的是两处防御性清理(attach 时清、收到已证明 id 时清):它们的变异不会让现有用例变红。
真 codex 0.164 + 真 worker 对照:在 isolate-run 里限 2 核加 6 个忙循环,master 和本分支各跑 15 轮,都是 15/15 正常收集。真 codex 的竞态窗口太窄,100ms 的轮询很少能撞上,所以这组只证明正常路径没有回归;竞态路径由上面的确定性用例覆盖。
不发版、不部署。
🤖 Generated with Claude Code
补充:deferred recheck 与 ZMX journal 结算路径(第二提交)
若 history.jsonl 行晚于 writeInput 自带的约 3.4 秒带内轮询预算,提交确认改走 20 秒 deferred recheck。复查成功后
confirmPendingTurn会以复查时刻起一个新的 20 秒租约,所以候选 id 在这条链上被丢掉同样会让懒创建的 rollout 无人 attach、本轮回复采集失败。第二提交把未证明候选在这条链上补齐:settleDeferredSubmitConfirmation的 settlement 透传unprovenCliSessionId;scheduleSubmitFailureNotify的 suppress-confirmed 分支在没有已证明cliSessionId时调用codexBridgeNoteUnprovenCliSessionId;runAmbiguousSubmissionTransaction走的settleVerifiableSubmissionForJournal同步把候选拷回 result。候选之后的属主证明、attach、持久化、消费回执条件与带内路径完全一致。新增
historyDelayMs: 6_000的集成用例(只被 deferred recheck 看到 history 行),以及直接驱动真实settleVerifiableSubmissionForJournal的 harness 用例覆盖 ZMX 拷贝。