Repository navigation
fix(dashboard): SSE 建连回放本进程关闭的会话,修 restore 期 zombie row 看板丢失/残留 stale-active - #281
Merged
Merged
Conversation
…ctive #277 的 follow-up(Codex 二审第三轮发现)。 #277 让 /api/events 建连先 subscribe 再回放当前活跃会话,确定性修住了「恢复后仍 active」的行;但只遍历 active Map。restore 期间的 zombie(backing pane 单独死掉) 是「先 announceSessionRow 再立刻 closeSession 从 Map 删除」,这俩事件都早于一个正 在 descriptor→restore 窗口里重连的 dashboard 的 SSE 订阅 → 全丢;等 SSE 连上时 zombie 已不在 active Map,active-only 回放补不到它(它此刻是 closed row)。新建 aggregator 永远看不到它;若 dashboard 原本缓存它为 active,hydrateSessions 只 upsert 不删 absent → 残留 stale active(已死会话显示成活的)。 修:snapshot-on-connect 在回放活跃会话后,再回放「closedAt ≥ 进程启动时刻」的已关 会话(composeRowFromClosed 作 session.spawned)。按进程启动时刻过滤 = 只补本 run 的关闭(含 restore 期 zombie),不回放整个 closed 历史(那本就由 GET /api/sessions hydrate 提供)。用 session.spawned 因目标行可能未知,两端按 sessionId upsert,closed 行的 status 覆盖任何 stale active 条目。补回归测试。
deepcoldy
added a commit
to xiaoxueSunn/botmux
that referenced
this pull request
Jul 26, 2026
采纳 codex 二次复审的两个 P2: 1) worker upload fail-safe 失效:lark-upload.ts 用 named import `defaultHttpInstance`,SDK/mock 缺该 export 时在 fail-safe 判断前就抛 (vitest 对缺失 named binding 的访问直接 throw)。改成 `import * as Lark` + 防御式 namespace 访问(try/catch,mirror bot-registry),缺失时得 undefined→回退共享实例而非 brick。test/lark-upload.test.ts 原 3 失败转绿。 2) restore quarantine 不自愈:promotion 首次失败后 initialStartPending 恒 true,tryAcquireInitialStartClaim 因此拒绝认领冷 owner,后续消息只 admitQueuedActivationTail 追加+return,promote 永不重试→session 卡到 /close。修:quarantine 时强制 initialStartPending=false,使下次入站能 claim→fork→forkReservedInitialSession 重新 derive gate 并 releaseQueuedActivationReservation→promoteQueuedActivationTail 排空 tail (新消息按 reservation 排在其后,不错序);持久后端 restore 亦经 toReattach 重 fork。promote 成功路径不受影响(gate 该留则留)。 测试(均变异验证对实现敏感): - lark-upload:补 defaultHttpInstance mock 镜像真实 SDK + 上传实例 120s 断言; ⭐并保留独立的 missing-export 用例(vi.doMock 去掉 export)断言回退到普通 Client 且不抛——不让修 mock 抹掉本 bug 的触发条件(codex 要求) - session-resume:quarantine 用例加断言 initialStartPending===false(自愈 enabler);新增 promote 成功时 initialStartPending 仍 true 的反向用例(防 自愈修法过度反应) - promote 的 retry(false→true)+ FIFO ordering + tokened journal 由既有 session-lifecycle-start 用例覆盖 - build 绿;P2 相关 8 套件 233 用例全绿 注:PR 当前对最新 master(24226c8)CONFLICTING,但冲突文件(cli/daemon/ worker/types/trigger-session/dashboard-ipc/worker-pool)与本次 P2 修复文件 (bot-registry/client/lark-upload/session-manager)不重叠——是 deepcoldy#597 原本 vs deepcoldy#583/deepcoldy#281 的既有撞车,需单独 rebase,与这两个 fix 无关。 Co-Authored-By: Riff
deepcoldy
added a commit
to xiaoxueSunn/botmux
that referenced
this pull request
Jul 26, 2026
上一版"清 initialStartPending gate"是错的(codex 三审指出+我核实):
- toReattach 空 fork 不 promote → 事后 live worker+未提升 tail,入站看到 live
worker 跳过 claim、只追加 tail,promote 永不重试;
- 冷路径清 gate 后新消息作普通 refork prompt 先发 → 越过老 tail,FIFO 反转。
采纳 codex 硬约束:任何 blank/current-turn fork 前,tail-only quarantine 必须
先 retry 老 head 的 promotion;失败就保持占 owner/gate、跳过 fork,绝不让当前
turn 越过、也绝不留 live-worker + 未提升 tail。
实现:
- 新增运行时标记 DaemonSession.quarantinedActivationTailPromotion(restore 时
promote 失败置位,不再清 gate,initialStartPending 保持 true)。
- 抽 `retryQuarantinedActivationTailPromotion(ds)` 共享 helper:非 quarantine→
true(no-op);promote 成功→清标记返 true(可 fork 已提升的 tokened head);
promote 仍失败→返 false(调用方跳过 fork,保持 worker:null 占位)。幂等
(promoteQueuedActivationTail 对已 pending 短路 true)。
- 两个 fork 边界前置调用:
1) restore toReattach 空 fork 回调:helper 返 false 则 return 跳过 forkWorker;
2) daemon 入站冷路径:当前 turn 已按 reservation 追加到老 tail 之后,再 retry;
成功→forkReservedInitialSession 冷 fork 已提升的老 head(非当前 turn);
失败→当前 turn 留 tail 等下次,保持 quarantine。
测试(session-resume.test.ts):
- restore quarantine 用例改断新契约:initialStartPending 仍 true(gate held)+
quarantinedActivationTailPromotion=true(待 fork 边界 retry),不再断错误的
gate=false;反向用例(promote 成功 gate 仍 true)保留。
- 新增 helper 三用例:成功→true+清标记+promote 以 send:false 调用;失败→false+
保留标记(调用方必跳 fork);非 quarantine→true 且不碰 promote。⭐失败路径变异
测试验证对实现敏感(fail→true 变异使用例 FAIL)。
- retry(false→true)+FIFO ordering+tokened journal 由既有 lifecycle 用例覆盖。
- build 绿;P2 相关 8 套件 236 用例全绿。
CONFLICTING(master→24226c87,与 deepcoldy#583/deepcoldy#281 既有撞车,不涉本次文件)待 rebase。
Co-Authored-By: Riff
deepcoldy
added a commit
that referenced
this pull request
Aug 8, 2026
* fix(codex-app): make turn ownership and recovery durable * test(codex-app): cover same-admission cap sweep * fix(codex-app): 修首审 2 个 P2(Lark upload 超时 + restore 孤儿行) P2-1 Lark upload 超时:#597 给全 bot/全 API 加的 15s SDK 超时对文件/视频 上传过窄(uploadImage/uploadFile 走同一 client 且无重试,~19MB@10Mbps 就 会被截断)。官方 SDK 的 httpInstance 是模块级共享单例、typed 上传方法无 per-request 超时钩子,故给上传单独一个 http 实例(defaultHttpInstance.create + 复制 UA/response-unwrap 拦截器)+ 120s 超时;交互调用仍保持 15s。worker 侧 lark-upload.ts 同款处理。SDK 不再导出 defaultHttpInstance 时 fail-safe 回退到 共享实例(上传退回 15s,不 brick)。 P2-2 restore 孤儿行:restoreActiveSessions 里 activation-tail 提升失败时原本 throw → 落进 per-row 隔离 catch 但未注册 → 该行盘上 active 却不在 activeSessions (IM /close 够不到 + 同 anchor 再来消息会建第二条 active 行,老 tail 永久悬挂)。 改为不 throw:注册成可见的 quarantined owner(未提升 tail 保持 protected 占住 anchor、可 /close、下次激活自然重试提升)。提升失败仅在 send:false 的瞬时持久化 错误时发生,故 quarantine + 重试是自愈的。 测试: - bot-registry:新增上传专用 http 实例断言(交互 15s vs 上传 120s、独立实例、 共享 default 未被污染);FakeClient/mock 补 defaultHttpInstance 镜像真实 SDK - session-resume:新增 restore 瞬时提升失败注册 quarantined owner 回归用例 (变异测试验证:改回 throw 则该用例 FAIL,证明对实现敏感) - pnpm build 绿;P2 相关 8 套件 264 用例全绿;7 个 SDK-mock 套件 147 用例全绿 (defensive 回退生效) Co-Authored-By: Riff * fix(codex-app): 收口 codex 复审两点(upload fail-safe 真回退 + quarantine 自愈) 采纳 codex 二次复审的两个 P2: 1) worker upload fail-safe 失效:lark-upload.ts 用 named import `defaultHttpInstance`,SDK/mock 缺该 export 时在 fail-safe 判断前就抛 (vitest 对缺失 named binding 的访问直接 throw)。改成 `import * as Lark` + 防御式 namespace 访问(try/catch,mirror bot-registry),缺失时得 undefined→回退共享实例而非 brick。test/lark-upload.test.ts 原 3 失败转绿。 2) restore quarantine 不自愈:promotion 首次失败后 initialStartPending 恒 true,tryAcquireInitialStartClaim 因此拒绝认领冷 owner,后续消息只 admitQueuedActivationTail 追加+return,promote 永不重试→session 卡到 /close。修:quarantine 时强制 initialStartPending=false,使下次入站能 claim→fork→forkReservedInitialSession 重新 derive gate 并 releaseQueuedActivationReservation→promoteQueuedActivationTail 排空 tail (新消息按 reservation 排在其后,不错序);持久后端 restore 亦经 toReattach 重 fork。promote 成功路径不受影响(gate 该留则留)。 测试(均变异验证对实现敏感): - lark-upload:补 defaultHttpInstance mock 镜像真实 SDK + 上传实例 120s 断言; ⭐并保留独立的 missing-export 用例(vi.doMock 去掉 export)断言回退到普通 Client 且不抛——不让修 mock 抹掉本 bug 的触发条件(codex 要求) - session-resume:quarantine 用例加断言 initialStartPending===false(自愈 enabler);新增 promote 成功时 initialStartPending 仍 true 的反向用例(防 自愈修法过度反应) - promote 的 retry(false→true)+ FIFO ordering + tokened journal 由既有 session-lifecycle-start 用例覆盖 - build 绿;P2 相关 8 套件 233 用例全绿 注:PR 当前对最新 master(24226c8)CONFLICTING,但冲突文件(cli/daemon/ worker/types/trigger-session/dashboard-ipc/worker-pool)与本次 P2 修复文件 (bot-registry/client/lark-upload/session-manager)不重叠——是 #597 原本 vs #583/#281 的既有撞车,需单独 rebase,与这两个 fix 无关。 Co-Authored-By: Riff * fix(codex-app): quarantine 自愈改为 fork 边界前置 promote-retry(采纳 codex 三审) 上一版"清 initialStartPending gate"是错的(codex 三审指出+我核实): - toReattach 空 fork 不 promote → 事后 live worker+未提升 tail,入站看到 live worker 跳过 claim、只追加 tail,promote 永不重试; - 冷路径清 gate 后新消息作普通 refork prompt 先发 → 越过老 tail,FIFO 反转。 采纳 codex 硬约束:任何 blank/current-turn fork 前,tail-only quarantine 必须 先 retry 老 head 的 promotion;失败就保持占 owner/gate、跳过 fork,绝不让当前 turn 越过、也绝不留 live-worker + 未提升 tail。 实现: - 新增运行时标记 DaemonSession.quarantinedActivationTailPromotion(restore 时 promote 失败置位,不再清 gate,initialStartPending 保持 true)。 - 抽 `retryQuarantinedActivationTailPromotion(ds)` 共享 helper:非 quarantine→ true(no-op);promote 成功→清标记返 true(可 fork 已提升的 tokened head); promote 仍失败→返 false(调用方跳过 fork,保持 worker:null 占位)。幂等 (promoteQueuedActivationTail 对已 pending 短路 true)。 - 两个 fork 边界前置调用: 1) restore toReattach 空 fork 回调:helper 返 false 则 return 跳过 forkWorker; 2) daemon 入站冷路径:当前 turn 已按 reservation 追加到老 tail 之后,再 retry; 成功→forkReservedInitialSession 冷 fork 已提升的老 head(非当前 turn); 失败→当前 turn 留 tail 等下次,保持 quarantine。 测试(session-resume.test.ts): - restore quarantine 用例改断新契约:initialStartPending 仍 true(gate held)+ quarantinedActivationTailPromotion=true(待 fork 边界 retry),不再断错误的 gate=false;反向用例(promote 成功 gate 仍 true)保留。 - 新增 helper 三用例:成功→true+清标记+promote 以 send:false 调用;失败→false+ 保留标记(调用方必跳 fork);非 quarantine→true 且不碰 promote。⭐失败路径变异 测试验证对实现敏感(fail→true 变异使用例 FAIL)。 - retry(false→true)+FIFO ordering+tokened journal 由既有 lifecycle 用例覆盖。 - build 绿;P2 相关 8 套件 236 用例全绿。 CONFLICTING(master→24226c87,与 #583/#281 既有撞车,不涉本次文件)待 rebase。 Co-Authored-By: Riff * fix(codex-app): sink quarantine tail-recovery into forkWorker central guard 采纳 codex 四审:把「tail-only quarantine 恢复」不变量从逐 fork 入口 补丁下沉到 forkWorker 一处中央守卫 resolveQuarantinedForkPlan,收口 P2-A 与 P2-B。 - 中央守卫(forkWorker 顶部,早于任何 prompt 派生/session 变更): · 非 quarantine → 原样放行 · quarantine + 非空 prompt → 拒绝(返回 false),调用方须先把该 turn durable-admit 进 tail 再空 prompt 恢复,杜绝越过老 head · quarantine + 空 prompt → fork 前 retry promoteQueuedActivationTail; 失败则保持 flag/gate/worker:null 并拒绝(绝不留 live worker + 未提升 tail);成功则清 flag 并按 CLI 改写为「恢复老 head」的精确参数 (Codex App 走 ledger + 空 prompt;非 Codex 重发 queuedActivationInput + resume/turn/attempt) - forkWorker 返回 boolean(此前 void;无调用方读取返回值,纯向后兼容) - P2-A:daemon 入站分支不再调 forkReservedInitialSession(会用空 pendingPrompt 造 synthetic opening envelope 被当新 dispatch 越过老 head), 改为经中央守卫的空 recovery fork - P2-B:ensureTerminalWorkerPort 懒唤醒检查守卫返回值,拒绝时返回 unavailable 而非空挂 10s(此前完全未加守卫的第三个 blank-fork 入口) - 删除旧的逐入口 helper retryQuarantinedActivationTailPromotion(三处调用 统一收敛到中央守卫),toReattach/restore 注释同步更新 测试(真实 forkWorker + 真实 promoteQueuedActivationTail,仅 mock 子进程 fork/session store,覆盖本次 wiring 而非仅 helper 返回值): - 新增 session-lifecycle-start「quarantined tail-only owner recovery at the fork boundary」:拒绝非空 / retry 失败 0 fork 保 gate / retry 成功恢复老 head(Codex App 走 ledger 空 prompt + 非 Codex 发 queuedActivationInput, 断言不含 <user_message> envelope)/ 非 quarantine 纯放行 - session-resume 旧 helper 单测下沉说明,restore 侧仍守 flag 契约 Co-Authored-By: Claude <[email protected]> * feat(codex-app): runner ordered pre-final steer driver (Blocking 1, runner 侧) 在 runner 内实现「一个 native turn 携带有序 accepted 组、完成时展开成 N 条签名 final」 的插话驱动器,恢复 master #588 的 ordered-steer 语义并迁到签名 socket,且不破坏 #597 的 Goal/reconcile/response-last 机制: - finalizeAcceptedGroup:accepted 组展开成 N 条 final,前 N−1 条 steer_superseded (空内容/无 usage/仅推进 worker FIFO),末条真回复+usage;N=1 时与旧单-final 契约字节等价。 - tryAdmitSteer + canSteer:普通 Lark inbound(codexAppSteerable===true)在 root native turn 打开后机会式 turn/steer 插入同一 native turn;queue head 只在 steer 被接受后 shift。 - 完成栅栏:见 canonical turn/completed 先关 steering,若 steer RPC 在飞则 buffer (completion_race)等其结算后再展开;startResponsePending 与 steerInFlight 分离字段。 - fenceUnknown:未知 turn/start|turn/steer 结果发签名 unknown_outcome+fatal 并 phase=fenced, 零 final(worker 收 fatal 调 failCodexAppControlGeneration);definite rejection 不 shift/不 append。 - 补齐 runner 的 signed lifecycle 发射(steer_attempt/steer_accepted),接回 worker 既有 但此前是死路径的消费端。 测试:新增贯穿用例——input#2/#3 在 final#1 前到达并被 ordered steer 接受,断言 turn/start+2×turn/steer、3 条 final(2 superseded+1 real)、2 对 steer lifecycle。 runner 集成 32/32 绿(原 31 零回归),tsc + build 绿。 worker superseded 分支 + 防御性 re-check + 剩余验收测试待续(下一 commit)。 Blocking 2(usage 透传)已在同分支修复。 * fix(codex-app): 修 codex delta 复审的 5 blocking + 2 nit(runner 侧) 按 codex delta(head dc0142f)复审逐条修复,红先行 + 变异测试证敏感: - B3 Goal gate:drainQueue 取 head 前判 codexAppSteerable;native Goal 活跃时 仅 flag===true 的 head 可作 Goal-steer 进入,missing/false 原地等 Goal 完成后 独立 turn/start;Goal completion 的 no-active-turn 分支 re-kick drainQueue 防 false head 永睡。既有 Goal-steer 测试补显式 flag,新增 goal-autocomplete fixture + "非 steerable 不进 Goal、Goal 完成后独立 start" 用例(变异 gate→用例 FAIL 证敏感)。 - B2 fence 真停:drainQueue 见 generationFenced 立即 break、不 shift、不 idle/prompt; runTurn catch 见 fenced 不再合成 failure final;turn/start 的 UNKNOWN(timeout/ transport,非显式 RPC 拒绝)走 fenceUnknown 而非 throw→failure final(-32000 等显式 服务端拒绝仍走原 failure final 路径,不误 fence)。worker lifecycle 分支补 authenticated fatal → failCodexAppControlGeneration(此前当 informational 吞掉)。 - B1 start-response-last:发 root start 前置 startResponsePending;exact turn/started 在 start 响应前即绑 canonicalNativeTurnId + identityProof='exact_started' + phase=open 并 kick,使 follow-up 可在 start 响应 pending 期间 steer;late start response 先核 canonical id(不符→fence),再清 pending、重放 buffered completion;pending 未清或 steer 在飞不得 settle。新增 steer-started-first fixture + 贯穿用例。 - B4 replay-before-kick:runTurn root response 后顺序改为 验证/bind → 重放 buffered started/completed(先置 completionSeen/关门)→ 仅 open 时才 kick;补 late-response 对多成员组的 settle(buffered completion_race 在 startResponsePending 清后结算)。 - B5 group identity:settleSteeredCompletion 在 itemsView:'full' 时校验每个实际发送 clientId 的成员各恰一次且 index 严格递增,从最后成员 index rebuild;缺/重/乱序 → reportIdentityConflict fail closed(不再只查最后一个 + 静默回落 streamed text)。 新增 steer-group-mismatch fixture + "缺成员 fail closed" 用例(变异防御→用例 FAIL)。 - nit1: definite steer rejection 复用 controller 口径(新 isDefiniteRpcRejection,认 -32600/-32601/-32602 + 显式短语),不再只认 isExplicitExpectedTurnInactive。 - nit2: tryAdmitSteer 里 queue[0]!==head 改 protocol fence(不再静默 append 错成员)。 测试:runner 集成 35/35(原 32 + B3 serial/B1 started-first/B5 mismatch 三新用例)、 worker routing 6/6、protocol+dispatch-ledger 40/40、tsc + build 全绿。B3/B5 变异测试 证对实现敏感。 worker 侧 disposition:'steer_superseded' 消费分支(codex 5 步落法)待下一 commit。 * fix(codex-app): 收口 codex R3 三个组模式基数 blocking + worker superseded 消费 codex delta(head 46dde5c)对 4-way 竞态矩阵复审又抓 3 个 blocking,共享根因=只 canonical completion 路径做了 group-aware,其余 completion/失败路径仍落单-turn 逻辑, 而 finalizeAcceptedGroup 照 accepted[] 展开 N-final → 基数错配。统一修法:引入 inGroupMode(turn) 谓词,组模式下所有 completion/失败路径必须 group-aware。 - R3-B1(组模式失败必 fence):runTurn start-RPC 失败时,只要有 positive evidence (serverStarted / identityProof / canonical / accepted>1)一律 fenceUnknown 0 final, 绝不 outer synthetic single final(否则已 shift 的 follow-up 永久留在 worker FIFO=poison)。 非 RPC 失败(timeout/transport)无 evidence 也 fence;仅显式 RPC 拒绝且无 evidence 才走 原 throw→failure final。红测 steer-then-drop(exact-started→steer accepted→start RPC 显式拒绝)。 - R3-B2(exact-completion 原子升级 proof):start response 前到达的 exact-client 完成对 steerable root 原子升级=绑 canonicalNativeTurnId + identityProof='exact_started' + 存 candidateCompletions + 要求晚 response 同 id,升级前只 buffer 不 settle;nativeTurnId 不再可被晚 response 无条件覆盖(不符即 fenceUnknown protocol 0 final)。红测 completion-before-response-mismatch(A 先到→response B→protocol fence 0 final)。 - R3-B3(组模式全路径 group-aware):inGroupMode 下 canonical 走带 barrier 的 settleSteeredCompletion,非 canonical/history 走新 reconcileSteeredGroupFromHistory—— 全历史仅唯一"含整组 exact 有序子序列"的 terminal turn 才结算,0/多/仅root match 一律 fail closed(identity-error 末条绝不携带 foreign model text)。提取 verifyGroupSubsequence 复用。红测 steer-noncanonical(非 canonical 完成 + history 仅 root-match → 不展开 follower)。 worker disposition:'steer_superseded' 消费(codex 5 步落法):严格校验 disposition (unknown 拒绝;superseded 必须 content===''&&usage===undefined&&awaitingFinal===true); durable 与 fallback 两分支都转发带 disposition 的 final_output(空内容+suppressDelivery, daemon 持久化不 deliver);liveness 移到 commit 后且 disposition-aware(superseded 退 1 逻辑 slot 但保持 awaitingFinal=true 不 publish ready;末条真 final 才清 awaiting;失败不退 slot 不清 awaiting)。types.ts final_output 加 disposition 字段。 另修一个真实缺陷:init 首轮 prompt 的 sendToPty 漏传 codexAppSteerable → codex-app 会话第一轮永远不能吸收 follow-up steer(canSteer 要 accepted[0] steerable)。已补线。 测试:runner 集成 38/38、worker routing 7/7(新增 worker superseded N-final 贯穿)、 其余 codex-app 单元 6 套件 112/112,tsc+build 全绿。R3-B1/B3 + worker superseded 变异测试 证对实现敏感。 * fix(codex-app): 收口 codex R4 四个 blocking(canonical不变性/history权威/首轮steer透传/superseded双重校验)+2 nit codex delta R4(head be95ab3)复审 4-way 竞态 + 生产贯穿又抓 4 blocking,其中 2 条是 "测试绕过生产接线=假绿"(B1/B4)。逐条独立核实成立,红先行 + 变异测试: - R4-B1(假绿:首轮 steer flag 只修 worker 半跳):生产 daemon 从不给 init/queued-tail 填 codexAppSteerable,原 worker.ts 复制的是恒缺字段。修:flag 进 CliTurnPayload frozen payload;daemon 在 live/null 分叉前算一次(原来只 live 分支算);COPY 到 tail admit / promote / repark / fork accept-ledger / initMsg / worker-null 冷 refork opening; 系统/queued-dashboard/durable-tail 开场保持 false,不从 sink 反推。生产贯穿测试(不手工 塞 flag)断言 live sendWorkerInput opts + worker-null forkWorker payload 都带 flag。 - R4-B2(canonical 非 first-proof-wins):exact completion A 绑 canonical 后,后到 exact turn/started/completed B 无条件覆盖成 B→A 正文标 B id。修:新 proveCanonicalExact first-proof-wins(proof 拆 exact_started|exact_completed,后续不同 id 立即 fence、相同 幂等),settle 前复核 terminal.id===canonical。红测 completion A→started B 与 started A→completion B 两条 0 final+fence。 - R4-B3(history 唯一 match 不切 native 权威):reconcileSteeredGroupFromHistory 重建正文却没 设 nativeTurnId/canonical=matched.id→final 标旧 id、usage drain 错、nativeActiveTurnId 残留。修:唯一 full-group match 成功以 matched.id 作 final/native/usage 权威,CAS 清旧 canonical(有更新 Goal C 不清 C)。红测 unique success(权威来自 B + Goal C 存活)。 - R4-B4(假绿:superseded 无双重校验):daemon durable settlement 不读 disposition,任意 suppressDelivery:true 直接 commit;worker reservation 无 steerable 无法复核 head。修: worker reservation COPY steerable + settleFinal 暴露 steerable/remaining,superseded 要求 head steerable 且 remaining>0(否则 reject,reservation/slot/awaiting 全不动);daemon preview 后任何 commit/deliver 前复核 entry.codexAppSteerable===true+sink=lark+无 VC/ receiver/origin,否则 ACK false 不 pop。红测 daemon 真实 ledger:非 steerable/非 lark head 拒(ACK false 不 pop)+ steerable lark head with successor 提交(ACK true pop 不 deliver)。 - nit1: candidateCompletions 只写不读→删(first-proof-wins 后 terminalCompletion+canonical 已是单一权威);nit2: Goal-root steer unknown 的 fence operation 按实际 RPC 标 turn/steer。 测试:runner 集成 41/41、worker routing 7/7、initial-user-turn-opening/bridge-final-output- retry/dispatch/ledger/protocol 126/126,tsc+build 全绿。R4-B1(冷fork COPY神经化)/B2(fence)/ B3(identity切换神经化)/B4(daemon recheck神经化)变异测试证敏感。 * fix(codex-app): 收口 codex R5 四个 blocking(首轮授权全 admission 分支/COPY链剥离/prepared恢复/daemon双防线) codex delta R5(head be51997)复审生产贯穿又抓 4 blocking,B1 两条是"授权判定位置错 + COPY 链主动剥离",B4 两条是"prepared 恢复丢标记 + daemon 防线 fail-open"。逐条独立核实: - R5-B1-1(授权判定晚于早期 admission 分支):codexAppSteerable 原在 live/null 分叉前算,但 仍晚于 initialStartPending follower / pending-repo follower / 新建话题 auto-create 等多个 更早的 admit/fork return。修:判定上移到所有 admit/fork 分支之前(handleThreadReplyAdmitted claim 边界后一次算);新建话题首轮冻进 pendingCodexAppSteerable,buildReservedInitialInput COPY 到 opening payload——forkReservedInitialSession(bot-added/scheduler/系统 bootstrap 共用) 只 COPY 显式 true 不推断。早期 tail-admit(initialStart/pending-repo)也冻 flag。 - R5-B1-2(COPY 链主动剥离):admitQueuedActivationTail/promoteQueuedActivationTail exactInput/ forkWorker durable-owner admit 重建 cliInput 时只挑 content+codexAppInput,剥掉 steerable。 修:每个重建点 COPY codexAppSteerable(只 === true;codexAppInput 仍 structuredClone 深拷贝 不共享可变 sidecar)。真实 admit→promote→accept-ledger 贯穿测试断言四处都 true、missing 保持 serial(变异 admit COPY→FAIL)。 - R5-B4-1(prepared 恢复丢标记):CodexAppTurnDispatchQueue.restore/reserve entry type 不接 codexAppSteerable + worker prepared prefix restore(worker.ts:13335)没映射→replacement 后 daemon head=true 但 worker reservation=false→合法 superseded 被 worker:6731 拒→崩溃重放卡死。 修:restore/reserve/settleFinal 全程透传 codexAppSteerable。单测证 restore 保留+settle 暴露 (变异透传→FAIL)。 - R5-B4-2(daemon 防线 fail-open 两处):durable settlement 接受 sink===undefined(应强制 ==='lark',legacy undefined 不当安全 Lark)+ 没复核 successor(preview.ledger.length===0 单头 forged superseded 仍 commit)。修:sink==='lark' 严格 + 要求 preview.ledger.length>0。补 真实 3-entry ledger ACK 的 sink-undefined + single-head 两个 ACK=false/no-mutation 负例。 测试口径纠偏(codex 指出):B3 Goal C 断言改"结算后最新 state busy"(原 some(busy=true) 命中 final 前状态);补 grown-group multiple-full-history match fail-closed 负例;补 restore→settle 真实透传单测(现有 worker N-final 走 fallback、daemon bridge 直接 emit,两半没贯穿 prepared 恢复)。 测试:runner 集成 42/42、worker routing 7/7、unit/daemon(opening/bridge/dispatch/ledger/ lifecycle/resume/protocol)262/262,tsc+build 全绿。R5-B1-2/B4-1/B4-2 变异测试证敏感。 * fix(codex-app): 收口 codex R6 三个 B1 生产入口/最后一跳 steer 透传断点 + 完整往返测试 codex delta R6(head 91bad0c)抓 3 个 B1 blocking——都是"授权源/最后一跳"漏 flag, 而非 cliInput payload 重建点(那些 R5 已堵)。逐条独立核实并修: - R6-B1(主新话题入口 + bare/repo 漏冻结):pendingCodexAppSteerable 全仓唯一赋值原在 handleThreadReplyAdmitted 的 !ds safety-net(18296),**主入口 handleNewTopicAdmitted 的 ds 构造从没写**→普通新话题首轮 forced-serial;bare /repo 接管重写 pendingPrompt 时也漏。 修:抽只基于入站 source facts 的 computeCodexAppSteerable helper(adopt/foreign-bot/ bot-sender/substitute/grill/listener/vc-receiver/vc-origin),两 twin(handleNewTopicAdmitted + handleThreadReplyAdmitted)都调;主 new-topic ds + bare-/repo takeover 只 COPY 显式 true; forkReservedInitialSession 共用函数(bot-added/scheduler/系统 bootstrap)仍只 COPY 不推断。 - R6-B2(promote→live worker 最后 IPC 丢 flag):promoteQueuedActivationTail 的 exactInput/ accept-ledger 已带(R5),但真正 ds.worker.send 的 message(4335)漏→live worker 立即接 promoted N+1 时 daemon head=true 但 worker reservation=false,合法 superseded 被拒。修:IPC message COPY exactInput.codexAppSteerable===true。 - R6-B3(forkWorker direct-route opts 丢 flag):protected ownership 无 activation gate(仅 unsettled ledger)走 sendWorkerInput(ds, promptPayload,...,{dispatchAttempt})(4655),而 sendWorkerInput 授权源是 **opts 不是 payload**→true 变 false。gate 分支(R5)已修,direct 分支漏。修:initCodexAppSteerable 传进 opts。 ⭐coalesced 缓冲(releaseQueuedActivationReservation 折叠多条为 1 turn)——codex 裁定**保持 serial 是本 PR 明确 fail-closed 语义,非漏传**(N 条折成 1 prompt/1 ledger/1 final,per-message 身份基数已丢,单 flag 无法安全表达整批;pendingCodexAppFollowUpGateAccepted 是 clean-input feature gate 非 steer 授权,绝不复用)。本轮不改,遵此语义。 测试:①新话题主入口生产贯穿(daemon-rename-route 真跑 handleNewTopic 不 seed owner):plain-human codex-app 新话题 opening fork payload 带 flag、bot-sender 保持 serial(变异新话题冻结→FAIL); ②完整 durable 往返(worker-routing):root+2 follow 各带真实 dispatchId→worker persist→daemon ACK→commit,3 durable final_output(2 superseded+1 real)、turn/start+2×turn/steer、无 wedge—— 补上此前 worker-fallback + daemon-fake-emit 两半之间的 hop。runner 集成 42/42、worker routing 8/8、unit/daemon 275/275,tsc+build 全绿。顺手把 R4-B3 两个 history-reconcile 用例 waitFor 从 10s 抬到 25s(bounded round-trip 在 CI 负载下偶发超时)。 * fix(codex-app): 补 forkWorker transfer-gate 分支的 steer 授权透传(R6-B3 同类自查) 自查 R6 教训"授权源通道"(sendWorkerInput 授权读 opts 非 payload)时,枚举全部 5 个 sendWorkerInput 调用点,发现 forkWorker 的 transfer-gate 分支(worker-pool.ts:4546,路由 transfer 在途时把 opening/refork 的 promptInput 经 sendWorkerInput 改道)与已修的 direct-route 分支(4660,R6-B3)同源漏传:opts 只带 dispatchAttempt,steerable 从 true 静默降级 false。 修:gatedPrompt.codexAppSteerable===true 时传进 opts。 其余授权源点复核干净:daemon 4239(doc-watch warmup=系统轮,serial✓)、18517(live admission, opts 已带✓)、19156(doc-comment sink,serial✓);message IPC 4193(sendWorkerInput live,opts✓)、 4336(promote,R6-B2 已修✓)。 tsc+build 全绿;worker-pool 消费方(lifecycle/resume/dispatch/bridge)204/204 回归绿。 * fix(codex-app): R7 收紧 steer 授权源(正向 humanSender fail-closed)+补两测试闸门 Blocking 1 — computeCodexAppSteerable 从"排除已知非人类源"改为"正向要求真人": - 新增 humanSender 参数(senderType==='user' 且非 known-peer-bot),排除清单永远不完备,任一未枚举的非 user 源在旧写法下 fail-open;正向门使默认 deny。 - 修 new-topic 侧两处 fail-open:threadGrill 硬编码 false → controlRewrite:!!newTopicGrill(被改写的 /workflow 提示不再可 steer);isForeignBot 折入 isKnownPeerBot 交叉兜底(与 thread 孪生定义对齐)。 - thread 侧同步补 humanSender 正向门。 Blocking 2 — round-trip 拆成两半各自走真实路径: - worker 半(worker-codex-app-turn-routing):每个成员带 codexAppDispatchId → 真调 waitForCodexAppDaemonPersistence,仅在 ACK 后 commit;断言 3 个 completed terminal 证明 FIFO/liveness 未卡死。 - daemon 半(bridge-final-output-retry):真实 settlement handler 的 ledger preview/store/ACK。 Gate 1 — transfer-gate steer 行为测试(新文件):真实撑开 transfer gate,把 codex-app opening fork 穿过去,断言 buffered→replay 的 worker IPC 与 accepted ledger 同带/同不带 steer 标志。mutation 掐掉 R6-B3 透传 → steerable 用例翻红。 Gate 2 — coalesced-serial 锁定测试 + 注释:pendingCodexAppFollowUpGateAccepted 全 true 时 release 后 tail/ledger/IPC 仍无 steerable(codex ruling:合并 N 条已丢失 per-message 身份,构造上强制串行)。mutation 注入 fail-open 派生 → 翻红。修 bot-sender nit:强制 fork=1,断言不再 vacuous。 验证:pnpm build 通过;R7 相关 8 套隔离全绿(transfer-gate 2/daemon-rename-route 38/bridge-final-output-retry 66/initial-user-turn-opening 28/session-lifecycle-start 94/codex-app-turn-dispatch 6/codex-app-runner.integration 42/worker-codex-app-turn-routing.integration 8);两 gate 均 mutation 验证有牙。 * test(codex-app): R7 delta 收紧 steer 测试闸门(worker awaiting 清除+gate2 三层+known-peer 接线+末 final ACK) 回应 codex R7 delta 复审的 1 blocking + 2 gate + 1 minor,均纯测试硬化(不动源码): Blocking — worker B2 证明"末 final 清 awaiting + 恢复 ready": - 原测试只等 3 个 turn_terminal:completed,而 terminal 在 post-commit 无条件发,对 awaiting 清除不敏感(掐掉 codexAppCompletionAwaitingFinal=false 仍全绿)。 - 改为断言 group 真 final 之后出现新的 prompt_ready(awaiting 未清则 signed idle 会 fence "published idle before the required final transaction",永不再 ready),并进一步真送一个 SECOND cycle(新 turn/start om_rt_4 + 一次 steer 关闭 om_rt_5)完成,证明 runner 确实能重新开工。请求日志验第二条 turn/start。 - mutation 掐 worker.ts:6895 的 awaiting 清除 → 测试翻红于该 fence,有牙。 Gate 2 — coalesced-serial 三层×一条与多条: - 改 it.each([1,2]),release 后同时断三层无 steerable:promoted queuedActivationInput / 对应 codexAppDispatchLedger entry / 实际 worker IPC。 - 两个 mutation 各自有牙:release 派生 fail-open(全 true→steerable)两例全红;仅 ledger 侧强推 true 被 layer-2 断言独立抓红(对应 codex 说的"仅 ledger 误推/replacement restore 后授权")。 Gate 3 — known-peer 生产接线红测(非 helper 真值表): - seed 真实 bot-openid cross-ref 文件后跑 handleNewTopic:sender_type=user 但 open_id 是已知 peer bot(伪装人类)→强制 fork=1 断 opening 无 steerable;正对照(同 cross-ref 下真人不在表内)断 opening 有 steerable,证明判别器就是 cross-ref。 - mutation 删 daemon.ts:16811/16814 两处 isKnownPeerBot → known-peer 用例翻红、正对照仍绿(证两者独立)。 Minor — daemon 半末 final ACK: - 补断真实末 final codex_app_dispatch_persisted(ok:true, requestId=settle-grp-2),否则 daemon 漏回末 ACK 时 ledger 仍空+Lark 仍投,但真实 worker 会卡 persistence wait。mutation 掐末 final ACK → 翻红。 验证:pnpm build 通过;R7 相关 8 套隔离全绿(transfer-gate 2/daemon-rename-route 41/bridge-final-output-retry 66/initial-user-turn-opening 28/session-lifecycle-start 94/codex-app-turn-dispatch 6/codex-app-runner.integration 42/worker-codex-app-turn-routing.integration 8),我改的三套各 mutation 验有牙;worker-routing 连跑 2 次 8/8 稳定。codex-app-runner 两个 history-reconcile 用例在 baseline(改动 stash 掉)同样 ~1-2/42 间歇超时=既有 bounded-history round-trip flake,与本改动无关(runner/fixture 均未碰)。 * test(codex-app): 修 R7-B2 请求日志断言竞态(改前缀+末尾断完整序列) codex R7-delta 复审发现的真实测试时序竞态:加入第二 cycle 后,前半段对 request log 的 `turn/start`+`turn/steer` 做**恰好 3 条 exact-equals** 即时断言,但 post-group prompt_ready 回调会立刻投第二 cycle,其 turn/start+turn/steer 会 race 进同一 log——20ms polling 返回后再读可能已 4~5 条→间歇翻红。 修: - 前半段改**前缀断言** `groupTurnMethods.slice(0,3)`——group 的有序 steer 确定是日志最前 3 条(root start→steer om_rt_2→steer om_rt_3),与第二 cycle 时序无关; - 末尾第二 cycle 完整 settle 后(其 final 已到,无竞态),补断**完整确定序列** `[start, steer, steer, start, steer]`(group 3 条 + 第二 cycle:fixture 全局 steerCount≥2 故 held turn 一次 steer 即完成);先 waitFor >=5 再读消除读时序。 - 文字 nit:前缀断言注释「complete final sequence is asserted below」改为准确的 「asserted at the end of the test」。 验证:worker-routing 全套 8/8;R7-B2 连跑 3×pass=1 fail=0(7 为 -t 过滤 skip); mutation 掐 worker.ts:6895 awaiting 清除仍翻红在 fence,teeth 不变。 * fix(cli): #750 exact-turn sender 不被 #597 legacy fallback 打穿(codex 二轮扫尾 blocking) 合并二轮时我把 replyTargetSenderOpenId 回退链写成无条件 `?? s.quoteTargetSenderOpenId`,重新打穿了 #750 的 exact-turn 契约: 有 currentTurnId 时,若精确轮 A 的 replyTargets 已淘汰/缺项(turnReplyTarget undefined),而全局 quote sender 已推进到 B,最后一跳会把 B 当作 A 的 --mention-back 目标,重新引入 #750 刚修的串轮 bug。 修:legacy 全局 slot 仅在**无 currentTurnId**(真正 legacy/no-turn 发送)时 才可回退;有 turnId 的 map miss/eviction 必须解析为无 sender、绝不借全局 slot (它可能指向不同的轮 B)。pickTurnReplyTarget 自身命中已强制 quoteTargetId===currentTurnId。 测试:cli-send-hook-context 加精确 source guard——断言 gated 形式 `?? (currentTurnId ? undefined : s.quoteTargetSenderOpenId)` 且**禁止**任何 无条件 `?? s.quoteTargetSenderOpenId;`。mutation 复原无条件回退 → 翻红。 cli-send-hook-context 15/0、send-policy 46/0、reply-target-fallback 41/0、 daemon-turn-reply-sender-wiring 7/0;build✅。 * fix(daemon): registration-race loser 重路由传完整 prepared,保住 forward-seed 结构化 @mentions(codex 二轮扫尾 blocking #2) 二轮合并时我只补了 forward-seed 的 post 富文本 @(collectPostAtMentions), 但 registration-race loser 改走 handleThreadReplyAdmitted(data, {...ctx}) 裸重路由 后,seed 的**结构化 message.mentions[]** 仍丢:该函数重新 parseEventMessage(data) 只得到 follow-up 的 structured mentions,new-topic 主路径已 merge 进 parsed 的 forwardSeedMentions 被丢弃 → turn-window under-count → --mention-back 可能错误放行。 修(与 #597 admission 锁兼容,不重进 handleThreadReply 外层锁): - 两个 loser 点(new-topic ~17012、auto-create ~18646)改为直接调用 handleThreadReplyAdmitted(data, ctx, prepared),把已合并的 parsed、resources、 attachments、quotaChecked、resolved sender、postParticipantMentions 继续向 canonical owner / 下一次 race 传;第二个 loser 也传同一 prepared,不再降 raw。 - PreparedThreadReply.queueAlreadyAppended 由字面 true 放宽为 boolean,loser 传 false(canonical existing-owner 路径自己 append,不写假事实)。 - 复活了 master 遗留的 PreparedThreadReply 死分支(合并断掉的证据)。 红测(真实双 CAS-loser,structured mention 非 post at):seed @Otherbot + follow-up @self,CAS 失败重路由到 canonical owner 后,其 replyTargets 参与者窗口 仍含 OtherBot;mutation 去掉 prepared 传递 → 翻红(窗口仅 owner/self,漏 OtherBot)。 daemon-rename-route 56/0、daemon-turn-reply-sender-wiring 7/0、command-handler 235/0、 initial-passthrough-ownership 8/0、reply-target-fallback 41/0、cli-send-hook-context 15/0、build✅。 --------- Co-authored-by: 申晗 <[email protected]> Co-authored-by: xiaoxueSunn <[email protected]> Co-authored-by: Claude <[email protected]>
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.
背景
#277(已合并)的 follow-up,处理 Codex 二审第三轮发现的残留时序洞。
#277 让
GET /api/events建连时先 subscribe 再回放当前活跃会话快照,确定性修住了「daemon 重启后仍 active 的恢复会话在看板消失」。但那次回放只遍历 active Map,没覆盖 restore 期间被关闭的 zombie 会话。问题
restore 期间,一个「backing pane 单独死掉」的 zombie 会话会被
restoreActiveSessions():注册进 active Map →announceSessionRow()广播session.spawned→ 立刻 probe 到missing→closeSession()(从 active Map 删除、置 store 行 closed)。如果一个 dashboard 恰好在 daemon「发布发现 descriptor(restore 之前)→ restore 完成」这个窗口里重连:
GET /api/sessionshydrate 在 restore 前发生,拿到的 active 为空、该 zombie 当时还是status=active不在 closed rows 里 → 完全没拿到;DashboardEventBus无 buffer 全丢;结果:新建 aggregator 永远看不到它;若该 dashboard 进程原本缓存它为 active,
hydrateSessions()只 upsert 不删 absent 行 → 残留一条 stale active(已死会话在看板显示成活的)。改动
/api/events的 snapshot-on-connect 在回放活跃会话后,再回放「closedAt ≥ 进程启动时刻的已关会话」(composeRowFromClosed作session.spawned发出):GET /api/sessionshydrate 提供。session.spawned(而非session.update):目标行可能对该客户端未知,update会被当 unknown row 丢;两端(aggregator / 前端 store)均按sessionIdupsert,closed 行的status:'closed'会覆盖任何 stale active 条目,stale-active 一并修掉。activeIds,跳过避免与活跃会话重复。验证
pnpm exec tsc --noEmit绿。/api/events仍收到该会话的session.spawned(status==='closed'、closedAt为数字)。pnpm test:4946 passed,22 failed 全是已知 env 失败(workflow-cli*/whiteboard-cli/preset-export-cli/workflow-c0-isolation,CLI 子进程测试,与本 PR 无关)。