Skip to content

fix(worker): 修复重启重连后 queuedActivationPending 永久卡死并补齐跨后端结算 - #3846

Merged
deepcoldy merged 14 commits into
masterfrom
fix/restore-queued-activation-ack
Nov 26, 2026
Merged

deepcoldy merged 14 commits into
masterfrom
fix/restore-queued-activation-ack

Conversation

@deepcoldy

@deepcoldy deepcoldy commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

问题与根因

线上实测在 daemon 重启并 reattach 到已存在的 tmux 会话后,若持久会话行仍残留 queuedActivationPending=true,即使原激活回合已经在 CLI 内运行并最终回到空闲提示符(Prompt detected (idle) / ready for input),daemon 也永不清掉 queuedActivationPending / initialStartPending,导致后续所有发往该会话的飞书消息全部被永久扣留在 queuedActivationTail(日志持续输出 buffered same-anchor turn ... behind queued activation submission ACK),同时阻断 /restart、/cd、/repo、idle-worker 回收、auto-compact 等会话变更路径。

全链路审计定位到主根因与关联边界缺陷:

  1. 主根因(SessionContract 防重门禁与 queuedActivationToken 结算断链):
    • Gen-1 在写边界执行 markTurnExecutionStart 将 SessionContractStore 中的执行相位从 queued 推至 submitting,在 queued_activation_submitted 落盘前遇到 daemon 重启,SessionController.workerLost 将该执行标记为 reconciling。
    • 重启恢复时 restoreActiveSessions 置 ds.initialStartPending=true 并向 Gen-2 下发带 prompt=queuedActivationInput、turnId、queuedActivationToken 与 sessionContract.executions(phase='reconciling')的 init。
    • Gen-2 的 spawnCli 命中 !workerSessionEventScope.canSubmit(...),发出 turn_input_rejected(reason='execution_reconciliation_required') 并将 cfg.prompt='' 清空,但直接丢弃 cfg.queuedActivationToken;后续 case 'init' 见 msg.prompt 为空,既不入队也不挂载收据观察器,永远不再发送 queued_activation_submitted。同时 rejectOrdinaryImDelivery 对 execution_reconciliation_required 触发无意义的 attempt=2 重试,被 Gen-2 的重复 init 去重吞掉并在 pendingOrdinaryImDeliveries 中留下孤儿记录。
    • 相同死锁在非持久后端(PTY)或持久 pane 缺失的冷恢复路径,以及 flushPending 命中 !canSubmit 时同样存在。
  2. 传输层静默丢包:queued_activation_submitted 缺失于 SessionEventGateway.workerEvents、SessionController.ingest 非延迟白名单及 worker.ts:sessionEventMetadata 的 worker-scoped 剥离列表,在无运行态绑定(pre-spawn RPC、post-spawn argv、raw_input)或进程内 publishRuntimeContract 重绑后会被网关静默按 runtime_scope_missing / stale_runtime_scope 拒绝,而 claimOnce(token) 已消耗重试机会。同理,Gen-2 发出的跨运行时 turn_input_rejected 需剥离 runtime/bindingId 避免误判 execution_scope_unproven。
  3. 跨后端与跨 CLI 对称缺口:
    • Codex App:热重连在 state='prepared' 下完成结算时(historical 观察授权作用域),原路径未清理匹配的 queuedActivationPending;两步写拆分在 SQLite 瞬断后还会留下「账本已空但激活门禁永卡」状态。
    • RemoteRunner:onTurnRecovered 恢复远端在飞回合时未去重 pendingMessages / 结算匹配 token,且二次重启遇未启动的 init 预留会误杀活远端后端。
    • OpenCode / MiMoCode:durableInitialPromptViaArgs 在进程诞生阶段即推进执行相位会绕过 DB 提交确认;持久化重连探查 DB 时缺少 !msg.resume 与会话归属校验会误清同名短提示词的未提交回合。
    • Pi:持久化重连仍调用 prepareInitialPromptArg 将正文改写为 /botmux-initial-prompt。
    • Hybrid Codex / TraeX RPC:ambiguous 首轮与 flush 路径未追踪 queuedActivationToken;stopCodexRpcEngine 拆除时若不先清追踪表会被同步 'stopped' 终态误 ACK。

核心修复

  • 新增纯决策模块 src/services/queued-activation-reconcile.ts(零 I/O,行为可独立单测与变异验证):收敛恢复分类、离线冷恢复判定、Codex App 结算 token 匹配、重连期 promoted tail 排队、PID marker 采纳、OpenCode 归属校验、Pi 重连参数策略、flushPending/raw_input 守卫与 RemoteRunner 队列对账。
  • Worker-scoped ACK 传输修复(src/core/session-event-gateway.ts、src/core/session-controller.ts、src/worker.ts、src/core/worker-pool.ts):
    • 将 queued_activation_submitted 加入 workerEvents 与 SessionController 非延迟白名单,在 sessionEventMetadata 剥离 runtime/execution/operationId/bindingId,并在 worker-pool.ts:logRejected 提升当前 worker 丢包日志至 warn;对 turn_input_rejected 剥离 runtime/operationId/bindingId(保留 execution 校验)。
    • SessionController.command() 过滤已停止/未解析的前代 worker 运行态,避免在 Gen-2 绑定运行态前将前代 activeRuntime 误贴到 promoted tail(stale_runtime_target 静默丢弃),同时不为预封装的 message 补贴 runtime 以保护进程内重启/重绑。
  • 单点恢复前对账 + 规范 ACK 收敛(src/core/session-controller.ts、src/core/worker-pool.ts、src/core/session-manager.ts、src/types.ts、src/worker.ts):
    • 新增只读 readPersistedExecutionContract(不调用 store.ensure()、不修改 ds/SQLite,主契约模式下以 primarySnapshot 为权威源)。
    • 离线冷恢复:在 restoreActiveSessions 中仅针对可证实已死的本地后端(probe==='missing' 或本地非持久 PTY,排除远程后端、Codex App 与 durableInitialPromptViaArgs 未确认状态)同步结算已越过 queued 的激活头并精确回滚,空 tail 直接保留为懒恢复避免无谓冷启,非空 tail 直接推进 Tail1(resume=true)。
    • 统一 forkWorker 入口对账:在 freezeSessionSandboxDecision 与 commitGroupContextDispatch 之前对非 queued 激活头剥离重复 prompt/turnId、保留 queuedActivationToken、下发增量字段 init.reconcileQueuedActivation(对 Cursor/MTR 首轮重连保持 resume=false 避免桥跳至 EOF),消除无意义 turn_input_rejected 与 attempt=2 重试风暴,并在 catch 中完整回滚 pendingRawInput/initialStartPending;worker 在 spawnCli 与 ready 均成功后经唯一规范通道 queued_activation_submitted -> handleQueuedActivationSubmittedAck 清账并按 (order, id) 顺序排空 queuedActivationTail。
    • 防误清与重连隔离:phase==='queued'(未提交首轮,负向对照)或无契约老会话始终走 'replay_queued',绝不在裸 ready/prompt_ready 或原始 PID marker turnId 上误 ACK;promoteQueuedActivationTail 将 controller.admitInput 纳入 try/catch 杀子进程围栏并附带 sessionCommand.execution;case 'message' 对重连在飞期间到来的同人/跨人 promoted tail 统一转 queueAfterActiveTurn=true 并结合 reattachOpenTurnGate 暂停 type-ahead(豁免 Codex App 签名 steer,且仅在 90s 硬超时非忙碌安静面板释放卡死门禁);PID marker 三处读点统一检查 isExecutionSettled 并在未启动队列头存在时不退役 Tail1。
  • 全后端对齐:
    • Codex App:persistCodexAppRecoverySettlement 与非 durable-replay codex_app_dispatch_transition(cancel) 在同一次 sessionStore.updateSession 事务内原子清理匹配激活日志并在提交后(含已提交重试分支)释放 tail,ownsCodexAppSettlementActivation 严格要求 lifecycle==='active' && !activeOperationId && sameWorker,并对已排空账本的残留激活提供恢复对账兜底。
    • RemoteRunner:onTurnRecovered 支持在未启动 init 预留上接管在飞远端回合、去重队列并将 init 匹配 token 延后至 post-ready 结算。
    • OpenCode / MiMoCode:仅在 finalizeArgvSubmission 经 DB 确认后推进执行相位,持久化重连要求 !msg.resume 且通过会话归属校验,避免跨会话短提示词或续接重名回合误清。
    • Pi:持久化重连跳过 prepareInitialPromptArg 且在 resolveInitialPromptDelivery 中保留原始正文。
    • Hybrid RPC:ambiguous 激活 token 在 spawnCli 后挂载收据观察并仅在正验证终态时 ACK,stopCodexRpcEngine 在调用 engine.stop() 前先清空映射表。
    • Raw-input:prompt_ready 统一按 queuedActivationRawTurnId ?? rawTurnId ?? queuedActivationTurnId 校验并在 onAcceptedInput 中先发随附 followUp 再排 queuedActivationTail。

影响范围与兼容性

  • 平台:纯 TypeScript/Node/Bun 逻辑,Linux 与 macOS 行为一致。
  • CLI 与后端:覆盖 tmux / herdr / hc / zellij / zmx / pty / remote-runner / riff / mojo 以及 Claude、Codex、Codex App、TraeX、Pi、OpenCode/MiMoCode、Antigravity、Cursor、MTR、Grok 等适配器;非 queued 与 queued 负向对照均已隔离验证。
  • PR fix(rename): 改名确认超时后有界放行排队消息 #3777 边界:改动文件仅在 src/worker.ts 与 PR fix(rename): 改名确认超时后有界放行排队消息 #3777 有交集,已通过 git merge-tree 验证零新增合并冲突;所有 hunk 均避开 PR fix(rename): 改名确认超时后有界放行排队消息 #3777 的 untouched / hard-block / rename recovery 区域且严格维持「未写入队列项绝不提前 ACK」语义不变量。
  • 兼容性与提示词:零老用户持久化会话 breakchange(无 sessionContractRevision / 无 token 的老行保持原回放语义),不增加任何常驻系统提示词。

对抗复核问题清单、探针证据与变异复验

提交前围绕三类持久化状态交叠攻击面(①人工中途干预、②半程落盘失败、③周期/超时/重连窗口交叠)执行了多轮真实组件探针与隔离变异复验,发现并当场修复以下问题:

  1. [P0] SessionController.command() 跨代/重绑运行态污染:
    • 探针证据:真实 SessionController + admitSessionCommand 复现两处静默丢包:① Gen-1 runtime_lost 后 Gen-2 绑定前下发 promoted tail,command() 贴上已失联的 Gen-1 activeRuntime 导致 stale_runtime_target 丢弃;② 进程内重启/重绑期间为预封装 message 补贴 runtime 或为 raw_input 贴上已停止的前代 execution.runtime 同样触发 stale_runtime_target。
    • 修法与回归:过滤非当前活 worker 运行态,不为预封装 message 补贴 runtime,raw_input 仅绑定当前活运行态;已补单测覆盖三种场景。
  2. [P0] releaseFirstPromptTimeout 软超时误释放与硬超时死锁平衡:
    • 探针证据:真实 probeBusyPatternIdle + decideHardTimeoutAction + flushPending 探针复现两面问题:纯用原始 supportsTypeAhead 在 readyPattern 滚出视口的重连静默面板上会卡死 reattachOpenTurnGate;若直接喂给 15s 软超时则会把被 reattachOpenTurnGate/durable/跨人阻断的回合在 15s 强行 markPromptReady()。
    • 修法:保留 15s 软超时与 durable/跨人路径原语义,仅在 forced===true(90s 硬超时)且 deferPromptReadyWhileBusy 已证实面板非忙碌、!activeTurnBlocks 时释放卡死的 reattachOpenTurnGate。
  3. [P0/P1] Codex App 两步写拆分及后置回执异常导致激活门禁永久卡死:
    • 探针证据:真实 setupWorkerHandlers 注入 SQLite 故障复现:先落空账本再写激活清理失败并退 worker 后,恢复 fork 既无 ledger 也无 reconcileQueuedActivation 导致永久卡死;若 sessionStore.updateSession 已提交清除但随后的 reconcileOrdinaryTurnRecoveryTerminalReceipt 抛错,重试走已提交分支跳过 tail 释放也会永久滞留 initialStartPending。
    • 修法与回归:合并至同一次 sessionStore.updateSession 原子提交(失败双回滚),通过 onCommitted + finally 及已提交重试分支确保已清除的激活必定释放 tail;ownsCodexAppSettlementActivation 补齐 lifecycle==='active' && !activeOperationId && sameWorker(探针曾复现 suspending 下误推 tail);排除 durable-replay cancel 与身份不匹配/即时 queuedActivationRawInput 误清。
  4. [P1] promoteQueuedActivationTail 丢弃 ExecutionRef 且 admitInput 位于异常围栏外:
    • 探针证据:真实 promoteQueuedActivationTail + SessionController.ingest 复现两缺陷:① 未附带 sessionCommand.execution 导致 turn_input_received/turn_input_committed 等 5 类事件全被 execution_scope_missing 拒绝;② admitInput 抛 SQLite 错时未杀活 worker 致永久卡死。
    • 修法与回归:将 admitInput 移入 try/catch 杀子进程围栏并附带 sessionCommand.execution,sendWorkerSessionInput 同步支持 raw_input。
  5. [P1] prompt_ready 原始命令对账顺序反转、忽略 ACK 失败与 turnId 优先级错位:
    • 探针证据:真实 setupWorkerHandlers prompt_ready 复现:① 先 ACK 后发 followUp 导致后到的 queuedActivationTail[0] 抢在 followUp 之前发出;② SQLite ACK 失败仍发出 followUp;③ 先读 queuedActivationTurnId 误丢未提交的 queuedActivationRawTurnId。
    • 修法与回归:统一 queuedActivationRawTurnId ?? rawTurnId ?? queuedActivationTurnId,并将 followUp 移入 handleQueuedActivationSubmittedAck.onAcceptedInput(严格位于 SQLite 提交后、tail 提升前)。
  6. [P1] forkWorkerPrepared 预初始化回滚与沙盒冻结顺序:
    • 探针证据:真实 forkWorkerPrepared 探针复现:freezeSessionSandboxDecision 先于 reconcileQueuedActivation 置 resume=true 导致老行误冻结 sandbox=true;预初始化抛错后未恢复 pendingRawInput 且遗留 initialStartPending=true 与 worker=null。
    • 修法与回归:将对账分类前置到 freezeSessionSandboxDecision 之前,并在 catch 中完整恢复/清理运行时标记。
  7. [P1] OpenCode/MiMoCode #3817 提前推进相位与续接重名提示词误清:
    • 探针证据:真实 OpenCode 适配器 + SQLite DB 探针复现:① 进程诞生即发 turn_execution_started 使重连跳过 DB 校验、冷恢复误丢未落库首轮;② 未守 !msg.resume 使续接的未提交 Case-C 回合(如 "continue")撞上 Turn 1 旧行被误 ACK。
    • 修法与回归:仅在 finalizeArgvSubmission 经 DB 确认后推进相位,重连探针增加 !msg.resume 与会话归属校验。
  8. [P1] PID marker writeCliPidMarker 复活终态 Turn 1、RemoteRunner 二次重启误杀、跨运行时 turn_input_rejected 被拒及 spawnCli 兜底:
    • 探针证据:真实 bindCliPidMarker -> writeCliPidMarker 复现 Case B 终态 Turn 1 被二次复活及异步 PID 退役未启动 Tail1;真实 onTurnRecovered 复现二次重启误杀远端后端;真实 SessionEventGateway 复现跨运行时 turn_input_rejected 报 execution_scope_unproven;readPersistedExecutionContract 复现主契约空快照回落本地旧 SQLite。
    • 修法与回归:全部在对应模块闭环修复并固化为回归用例。
  9. 变异复验:在隔离临时目录执行 13 项核心守卫变异(M1–M12)+ 9 项生产接线变异(W1–W9),22/22 全部咬红(覆盖网关白名单、metadata 剥离、Case C 负向对照、Codex App / 远程后端排除、reattachOpenTurnGate type-ahead 守卫、PID marker 采纳/终态跳过、OpenCode 归属与 !msg.resume、Pi 重连参数、local_submission 隔离、forkWorkerPrepared / restoreActiveSessions / setupWorkerHandlers / rejectOrdinaryImDelivery / prompt_ready / promoteQueuedActivationTail / SessionController.command / stopCodexRpcEngine 全接线点)。

验证结果

  • bun run build(含 tsc、typecheck、audit:domains、dashboard:bundle、audit-dist、audit-embedded-assets):通过。
  • 新增回归套件 test/queued-activation-reattach-reconciliation.test.ts:
    • npx vitest run test/queued-activation-reattach-reconciliation.test.ts:19/19 通过。
    • bun test test/cli-startup-activation-adversarial.test.ts test/queued-activation-reattach-reconciliation.test.ts(含跨文件共享进程顺序验证):40/40 通过。
  • 相关回归套件(vitest):
    • queued-activation-reattach-reconciliation + queued-activation-deferred-settlement + session-contract-gateway + session-lifecycle-start + test-hygiene:746/746 通过。
    • session-contract-reattach-live-cli + session-contract-recovery + ordinary-im-contract-delivery + restart-worker-null-reattach:115/115 通过。
    • session-contract + session-contract-primary-successor + session-contract-repo-switch + worker-codex-app-input-proof + queued-activation-raw-journal + worker-opening-input-settle:83/83 通过。
    • worker-argv-reaction-status.integration.test.ts(Grok 首轮回归):通过。
  • 未合码、未发版、未部署或重启 live fleet;全量回归交由 CI。

2026-11-26 追加修复与复核(当前 head 124f482db5)

本节覆盖前述恢复策略中“凡越过 queued 即可对账”的表述:现在只有强执行相位或后端权威证据才能直接结算。

追加提交:

  • dafde90e95:收紧重连激活证据并修复生命周期回归。
  • 124f482db5:补齐激活恢复排空与人工重放出口。

首轮复核发现的 6 项问题及修法

  1. submitting/reconciling 被误当成已写入证据:markTurnExecutionStart() 位于 init/writeInput 之前,崩溃时可能只有 intent-to-write。现仅允许 accepted/running/terminal 或 transcript、native turn、adapter recheck 等权威证据直接 ACK;弱相位保留原文与 token,只读观察,不再清账丢消息。OpenCode/MiMoCode 持续 recheck 同样保留 !resume 和会话归属门禁。
  2. stopped runtime 被全局过滤导致自动 restart 失败:仅 restart 可保留同代 stopped runtime,前代/unresolved 仍拒绝;普通 replacement input 不继承 stopped ref。
  3. ambiguous RPC 的 aborted 终态删 token 但不 ACK:aborted 作为已证明 native turn 启动的正终态纳入 ACK;engine-dead/stopped 等 teardown-only 状态继续不 ACK。
  4. spawner 模块求值快照绕过既有 transport mock:默认改为调用时解析 (workerSpawnerImpl ?? spawnWorker),恢复既有 vi.spyOn seam,不再在测试里误起真实 worker。
  5. restore mock 缺新导出:补 settleOfflineReconciledQueuedActivation 行为保持 mock。
  6. Codex handoff sliced harness 缺新闭包:注册真实 owns/match/settleCodexApp...Activation 闭包及纯决策依赖,不再由缺失 raiseDaemonAttention 掩盖错误。

追加对抗复核问题清单与探针证据

  1. [P1] 激活头 ACK 后本地 FIFO 后继永久滞留:真实 flushPending + receipt observer + 假时钟复现:20 秒 proof 已 ACK,但 ready 状态下 redriveRejectedStructuredReady() 直接返回,600 秒后 successor 仍 writes=0。修为按捕获的 generation/backend 同时 redrive flushPending();复验 proof 后 successor 自动写入一次,opening 不重放,600 秒后 pending=[],再次 flush 无额外写入。摘掉 holdForUnconfirmedActivation 的 break 后探针立即咬红,证明也能抓住 proof 前抢跑。
  2. [P1] 无证据激活在 /restart 后仍无限 observe-only:真实 observer + failure chain + restart 复现 timeout/restart 后仍 0 ACK、0 写入。新增仅限明确通用人工重启、仅限新 generation、仅一次的原文重放授权;自动 crash restart 不改变决策,陈旧授权不能提交,失败/下一代不继承授权。复验三组对照:显式授权写入+ACK 一次、自动 restart 0 写入、generation-1 授权 0 写入。
  3. [P1] Dashboard 预检让授权入口不可达:真实 dashboard 拒绝函数对 activation-only 返回 409 session_mutation_pending。仅 restart 路由启用 activation replay 过滤,其它 Dashboard 路由保持默认全量保护;复验 activation-only 不再 409。
  4. [P2] 孤立 initialStartPending 被误豁免:现在只有真实 queuedActivationPending 头存在时才允许 activation replay;孤立 initialStartPending 和 tail-only 均继续 409。Codex App ledger、queued、pending repo、principal-lane tail 继续全部阻断。

上述探针使用真实组件、故障注入和可控 timer,均经 fenced-run 隔离执行;未对宿主 fleet、systemd 或真实 HOME 做写操作。

最终实际验证(head 124f482db5)

  • bun run build(含 tsc、typecheck、domain/dist/assets audits):通过。
  • bun run test -- test/queued-activation-reattach-reconciliation.test.ts test/session-mutation-guard.test.ts test/restart-status-card.test.ts:54/54 通过。
  • bun test test/cli-startup-activation-adversarial.test.ts test/queued-activation-reattach-reconciliation.test.ts test/session-mutation-guard.test.ts:54/54 通过。
  • bun run test -- test/restore-zombie-close.test.ts test/session-title-delivery.test.ts test/universal-output-handoff.test.ts:140/140 通过(同命令在原 head 为 8 failed/132 passed,base 对照为 140/140)。
  • 相关 lifecycle/activation 回归 9 文件:844/844 通过;restart/dashboard 相邻回归 6 文件:84/84 通过;合约相邻回归 5 文件:81/81 通过;raw/交付相邻回归 4 文件:90/90 通过。
  • TMPDIR=/tmp bun run test -- test/cli-startup-circuit.integration.test.ts:2/2 通过;worker-argv-reaction-status.integration.test.ts:通过。
  • 追加对抗探针:FIFO、cold-no-evidence、operator-replay、entry-guards 共 4 文件 8/8 通过;入口守卫复验 4/4 通过;mutation-guard 单测 9/9 通过。
  • 未合码、未发版、未部署或重启 live fleet;新 head 的全量 CI 另行核验。

2026-11-26 主干同步与合并复核(当前 head f22ce173f6)

通过 非 force 的 merge commits 同步最新 master,原 dafde90e95、124f482db5 均保留在祖先链中,没有 rebase 或改写已有修复提交:

冲突解与双侧不变量

  • session-controller:白名单同时保留 queued_activation_submitted 与 managed_turn_origin_revoked。
  • worker-function-harness:同时保留激活观察/人工重放函数、isClaudeFamilyCli 以及 Antigravity folded/quota 函数。
  • worker-pool:reconcile 导入与 WorkerOutputJournal 并集;activeInteractiveTurn 更新块无条件保留,reconciliationOnlyRejection 仅限制 discard。
  • 三处 PID marker:backgroundHeld 与 markerSettled 在同一 OR 内,任何一侧都能阻止旧回合复活;存活 tail 仍可恢复。
  • flushPending:effectiveSupportsTypeAhead 与 backgroundAuthorityHold supersede 独立并存。
  • types:antigravityQuotaCursor 与 reconcileQueuedActivation 同时保留。
  • TraeX 仅单行 /rename 使用 bracketed-paste,raw follow-up 仍按 accepted → follow-up → ACK 顺序;插件 proxy/webhook 不绕过 owner env 冻结或 activation/restart 门禁。

独立对抗复核覆盖人工 restart/换代、半程 SQLite/IPC 失败、binding refusal、假时钟与 pending binding/ACK 交叠、后台 wake/revoke、Antigravity folded/quota、raw rename、插件 env/proxy。7 文件 273 用例通过;两个精确叠加探针也通过:同一 marker 同时 backgroundHeld=true 与 markerSettled=true,以及 HELD_WAITING_BG + reattachOpenTurnGate + unconfirmed activation。最终 Antigravity 与 raw/plugin 增量复核均未发现可复现问题。

一次插件测试并发时的 403 peer_unverified 在隔离复跑和原组合复跑中均通过,未形成可复现回归。

合并后实际验证(最终 head f22ce173f6)

  • bun run build 与 bun run typecheck:通过。
  • 激活、mutation-guard、restart-status、restore-zombie、title-delivery、universal-output-handoff 六文件:206/206 通过。
  • 背景权威五文件:144/144 通过;lifecycle/activation 九文件:857/857 通过;fix(session): 修复退出回执失配及休眠会话待办误判 #3847 会话三文件:202/202 通过。
  • Antigravity 限额/轮换五文件:143/143 通过;插件 webhook/proxy/env 八文件:139/139 通过;raw/TraeX 四文件:96/96 通过。
  • 最终 A/B:restore-zombie-close + session-title-delivery + universal-output-handoff 三文件 152/152 通过;cli-startup-circuit 2/2 通过;Bun 激活三文件 54/54 通过。
  • 最终激活/后台组合复跑 66/66 通过;独立叠加探针 2/2 通过。
  • 未合码、未发版、未部署或重启 live fleet。推送时 mergeable=MERGEABLE、mergeStateStatus=BLOCKED,表示内容冲突已消除、仅等待 CI 门禁。

CI 首跑失败后的测试侧修正(最终 head 5e85c3d5b2)

CI 45731640723 暴露的是测试 mock 与既有新语义不同步,并非生产回归,已全部修正:

最终验证:

  • 四个相关 Vitest 文件 1233/1233 通过;dashboard-ipc Bun 单文件通过。其余 Bun 文件仅有既有 vi.hoisted/importOriginal shim 限制,与本次修改无关。
  • fleet-supervisor-maintenance 5/5 通过;完整 bun run build、typecheck 通过。
  • 最终独立增量复核无发现:supervisor 在 maintenance 等待期间保持存活,停止路径仍能取消 timer 并自然退出;全部 CI 失败断言点均已覆盖。
  • 未合码、未发版、未部署或重启 live fleet;等待最终 head 的 CI 首跑结果。

#3779 终态通知与 metadata 合并(最终 head 1a530ce78d)

以非 force merge commit 合入 #3779,5e85c3d5b2 与此前全部修复均保留。唯一冲突在 sessionEventMetadata,按互斥语义做纯并集:

  • turn_input_rejected 块继续剥离 runtime/operationId/bindingId,允许 replacement runtime 结算 predecessor execution。
  • isStructuredNoticeProtocolMessage 块继续剥离同三字段,让 structured notice 归属 worker recovery channel。
  • 两块均保留 scope.execution,不会让 rejection 或 notice 借剥离字段伪造执行所有权;网关仍要求真实 execution 与 turn/attempt 完全匹配。
  • restoreMissingFinalNotices 同时接入普通函数加载器与 loadWorkerMessageHandler 专用解析器,避免 init 测试回退为未定义全局值。

最终独立复核无发现:preliminary/primary gateway 的 structured-notice 语义一致,activation ACK、rejection 和恢复/待办路径没有共享字段覆盖。

验证:

  • activation/bridge 六文件 287/287 通过;Bun 激活三文件 54/54 通过。
  • 四个 restart/mock 文件 1233/1233 通过;dashboard-ipc Bun 单文件通过。
  • 完整 bun run build、typecheck 通过。
  • 未合码、未发版、未部署或重启 live fleet;等待本 head 的 CI 首跑。

后台折叠、真实进程识别与 ByteCloud 续期合并(最终 head e03eb0a877)

继续以普通 merge commits 保留完整历史:

独立增量复核确认:

验证:

  • 折叠/背景权威/激活交集七件 135/135;discovery/fold 配置五件 296/296;harness universal-output-handoff 53/53。
  • restart/mock+gateway 1394/1394;activation+fix(reply): 转写终态缺失时有界结束等待并提示 Web 终端 #3779 287/287;Bun 激活与 fold 交集均通过。
  • fix(auth): 同轮续期已过期的平台 ByteCloud 凭据 #3845 ByteCloud 五套件 272/272;叠加激活/网关重跑 548/548;本 head 激活/网关复跑 668/668。
  • 完整 build/typecheck 通过。MainThread 的 /proc comm 断言在纯 master 同环境也失败,已 A/B 排除为容器差异;标准 runner 不复现。
  • 一次 ipc-current-execution-route 组合测试失败在单跑、窄组合和原组合重跑均通过,判定为非确定性测试隔离问题并保留证据;未自行创建公开 issue。
  • 未合码、未发版、未部署或重启 live fleet;等待最终 head CI 首跑。

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论:需修改,当前不可合

复核 head:e407e7f37d7bb3b27f3fea7f80b5087f0be932d5。确认 6 项阻断发现:前 3 项会影响生产状态结算/生命周期,后 3 项是确定性测试回归。此前“可合、仅 P3 观察”的结论不再成立。

1. [P1] submitting/reconciling 不能证明 prompt 已写入 CLI,当前会误 ACK 并丢首条消息

位置:src/services/queued-activation-reconcile.ts:164,相关写入边界 src/worker.ts:42666-42694、src/worker.ts:44355-44360、src/worker.ts:28667-28676。

markTurnExecutionStart() 在 init 阶段、以及普通 writeInput 之前就记录/发送 turn_execution_started;daemon 将其推进为 submitting,重启后又可变为 reconciling。因此“事件已落盘、实际写入尚未发生即崩溃”的窗口真实存在。当前分类却返回 reconcile_already_submitted,后续剥离 prompt、清激活账本并提升 tail;离线结算和 raw-input 抑制也复用了同一个不成立的证据。

真实函数探针在完全没有执行任何写入的情况下得到:

crash-before-write {"event":"turn_execution_started","writeOccurred":false,"plan":{"action":"reconcile_already_submitted", ...}}

现有新测试只手工构造 phase,缺少上述 crash-before-write 负向用例。建议引入真正的“写入已完成/CLI 已接收”持久证据;对只有 submitting/reconciling 的恢复项,必须经后端权威 transcript/存储探针证实后才能 ACK。无法证实时应保留并显式进入可恢复/人工处理路径,不能清账丢弃,也不能简单盲重放造成重复执行。

2. [P1] 全局过滤 stopped runtime 阻断了 CLI 退出后的自动 restart

位置:src/core/session-controller.ts:286-323,拒入门禁 src/services/session-command-gateway.ts:16-19。

SessionController.command() 现在对所有命令过滤 stopped/unresolved runtime。可是 CLI 退出后,自动 restart 的合法目标恰恰是这个已停止 runtime;过滤后下发命令没有 runtime,worker 以 runtime_target_missing 拒绝,无法产生 replacement。

本地定向复现与 CI 一致:

Rejected restart: runtime_target_missing
restart_result failed
Error: timed out waiting for real replacement after startup exit

命令与 base 对照:

TMPDIR=/tmp bun run test -- test/cli-startup-circuit.integration.test.ts -t 'restarts an unstarted Pi once'
  • PR head:失败,自动重启被拒。
  • base 1788c36f:通过,restart_result succeeded,随后 circuit 与 recovery 流程完成。

建议把“不得贴前代 stopped runtime”的限制收窄到换代后的输入交付路径;restart 等生命周期命令仍需保留其显式、同代、已停止的目标 runtime,并补上述集成用例到必跑验证。

3. [P1] ambiguous RPC 回合收到 aborted 终态时删 token 却不 ACK,tail 可再次永久扣留

位置:src/worker.ts:1238-1255、src/worker.ts:18447-18481(另一处同类调用在 src/worker.ts:18341-18363)。

两个 terminal 路径都只在 completed/failed 时设置 acknowledgeActivation: true,但无论终态为何都会删除 ambiguousRpcActivationTokens。aborted 已证明 native turn 存在并曾开始执行;在收据观察器尚未结算、用户中断回合时,当前实现会失去这次清账机会,却没有发出 queued_activation_submitted。

使用真实 settleRpcTurnTerminal / clearRpcLifecycleFailClosedOwner 的对照探针结果:

completed: acknowledgements=[tok-completed], tokenRetained=false
aborted:   acknowledgements=[],             tokenRetained=false

建议将 aborted 与已有明确 native 终态一样纳入 ACK(仍不要把 teardown-only、无法证明提交的 stopped 等状态混入),并补“ambiguous → 用户中断 → aborted → tail 放行”回归。

4. [P1] 新 spawner 默认值绕过既有 mock,导致 6 个标题测试失败并意外启动真实 worker

位置:src/core/worker-pool.ts:13270-13273、src/core/worker-pool.ts:21547。

let workerSpawnerImpl: typeof spawnWorker = spawnWorker 在模块求值时捕获原始 import,绕过既有 vi.spyOn(selfSpawn, 'spawnWorker')。受影响测试实际启动了 worker,fake transport 收不到 init,所以 session-title-delivery 的 sentInit 为 undefined;组合测试还会出现真实子进程退出后的 session_contract_database_replaced 未捕获错误。

同一命令 A/B:

bun run test -- test/restore-zombie-close.test.ts test/session-title-delivery.test.ts test/universal-output-handoff.test.ts
  • PR head:8 failed / 132 passed(其中标题套件 6 个失败)。
  • base 1788c36f:140/140 通过。

建议默认走调用时解析 (workerSpawnerImpl ?? spawnWorker)(...),并把默认实现设为 undefined;或者完整迁移/重置所有既有 spy。不能只让新套件使用新 seam 而让旧套件静默跑到真实进程。

5. [P1] 新增 restore 调用未加入既有 worker-pool mock

位置:src/core/session-manager.ts:3906,失败用例 test/restore-zombie-close.test.ts:1521。

restore-zombie-close 的 mock 没有 settleOfflineReconciledQueuedActivation,在 probe=missing + queuedActivationPending=true 时直接抛错,测试尚未走到原断言。该项与第 4 项都包含在上述 8 个 A/B 失败中。请补行为保持的 mock,并检查其它 restore mock 是否也存在同一缺口。

6. [P1] Codex committed-sequence 新闭包未接入 source-sliced harness

位置:src/core/worker-pool.ts:23507,失败用例 test/universal-output-handoff.test.ts:490。

already-committed native sequence 进入新分支后调用 settleCodexAppQueuedActivationIfMatched,但 processFinalOutput 的 sliced scope 没有该依赖;错误随后被同样缺失的 raiseDaemonAttention 掩盖,预期的成功 dispatch receipt 没有发出。请在 worker-pool-function-harness.ts 注册/加载新闭包及依赖,或在夹具中显式提供等价实现,保留真实结算路径覆盖。

已执行验证

  • bun run build:通过(含 tsc、typecheck、dist/assets audits)。
  • bun run test -- test/queued-activation-reattach-reconciliation.test.ts:19/19 通过。
  • bun test test/cli-startup-activation-adversarial.test.ts test/queued-activation-reattach-reconciliation.test.ts:40/40 通过。
  • 上述 3 个受影响测试文件 A/B:base 140/140;PR head 8 failed / 132 passed。
  • 上述 Pi startup-circuit A/B:base 通过;PR head 复现 runtime_target_missing 并失败。
  • 两个真实函数探针分别复现 crash-before-write 误分类和 aborted 不 ACK。
  • 复核时 GitHub Actions 的 test (1/4)、test (3/4) 已失败,不再是单纯 pending/runner 排队。

本次未代改、未推送、未部署或重启 live daemon;工作树最终保持干净。

DeepCold review and others added 13 commits November 26, 2026 04:59
仅允许强执行相位或后端权威证据结算 queued activation;submitting/reconciling 保留原文并进行只读观察,避免崩溃窗口误清首条消息。补齐 raw 原文跨代持久化与 ACK、follow-up、redrive 顺序。

恢复同代 stopped runtime 的 restart 目标,放行 RPC aborted 正终态结算,并修复 spawner 测试接缝及 restore、Codex handoff 测试依赖。

Co-Authored-By: Claude Code <[email protected]>
权威证据结算后按代际重新驱动 FIFO,避免激活头 ACK 后后继永久滞留;raw 保持 ACK、follow-up、redrive 顺序。

为无提交证据的激活增加仅限明确人工重启、仅限新一代且仅一次的原文重放授权,自动重启和陈旧授权保持只读。同步收窄 slash、卡片和 Dashboard 的激活门禁,孤立 initial_start 与其它持久所有权继续阻断。

Co-Authored-By: Claude Code <[email protected]>
合入 origin/master,组合 queued_activation_submitted/managed_turn_origin_revoked 白名单、后台 backgroundHeld/backgroundAuthorityHold 与激活恢复、人工重放路径。

Co-Authored-By: Claude Code <[email protected]>
合入最新 origin/master,保留既有激活恢复与后台权威组合,并纳入退出回执匹配及休眠会话待办判定修复。

Co-Authored-By: Claude Code <[email protected]>
合入最新 origin/master,保留 antigravityQuotaCursor 与 queued activation 字段,以及 Antigravity folded/quota 与激活观察函数并集。

Co-Authored-By: Claude Code <[email protected]>
合入最新 origin/master,保留激活 raw follow-up 顺序,并纳入 TraeX 单行 rename 的 bracketed-paste 提交修复。

Co-Authored-By: Claude Code <[email protected]>
补齐 dashboard restart 的 allowUnconfirmedActivationReplay 选项断言,避免前一条断言失败后残留 mock 级联影响 startFailure 用例。验证 dashboard-ipc 与 restart-status-card 共 447 通过、3 skipped。

Co-Authored-By: Claude Code <[email protected]>
合入最新 origin/master,保留 activation replay 与 restart 门禁,并纳入触发人凭据来源和 Claude 会话模型/思考强度选择。

Co-Authored-By: Claude Code <[email protected]>
为通用 slash/card restart 调用补上 allowUnconfirmedActivationReplay 参数断言,并为 dashboard-create-session 的 worker-pool mock 补 settleOfflineReconciledQueuedActivation 导出。四个相关 Vitest 文件 1233 通过,dashboard-ipc Bun 单文件通过。

Co-Authored-By: Claude Code <[email protected]>
合入最新 origin/master,保留激活恢复与 restart 测试修复,并纳入维护窗口等待期间 supervisor 保活。

Co-Authored-By: Claude Code <[email protected]>
合入 #3779,保留 turn_input_rejected 与 isStructuredNoticeProtocolMessage 两个互斥的 runtime/operationId/bindingId 剥离块,并在 worker message harness 接入 restoreMissingFinalNotices。

Co-Authored-By: Claude Code <[email protected]>
合入 #3823/#3855/#3862,保留激活恢复、raw 重放与后台 Monitor 折叠两套不变量;worker harness 同时注册双方函数与 message-handler 入口。

Co-Authored-By: Claude Code <[email protected]>
合入最新 origin/master,保留后台折叠与激活恢复守卫,并纳入同轮续期已过期的 ByteCloud 凭据修复。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit 689970b into master Nov 26, 2026
19 checks passed
deepcoldy pushed a commit to darylchen97/botmux that referenced this pull request Nov 26, 2026
master deepcoldy#3846 在 message IPC 分支新增 activeTurnAuthority.snapshot() 调用,
harness 构造的 scope 未提供该依赖,rebase 到含 deepcoldy#3846 的主干后
re-ACK 用例抛 TypeError;补 snapshot 返回 undefined 的最小桩。

Co-Authored-By: Claude Fable 5 <[email protected]>
deepcoldy pushed a commit to Sespeck/botmux that referenced this pull request Nov 26, 2026
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]>
@github-actions

Copy link
Copy Markdown

@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 689970b…36f11a21e(11 个提交),同批合入的还有 #3881 #3870 #3869 #3868 #3877 #3875 #3876 #3886 #3885 #3883,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Sandbox hides home and harness secrets feishu-core-sandbox failed Replanned 20 times, exceeding the limit. Please configure a larger value for replanningCycleLimit (or use MIDSCENE_REPLANNING_CYCLE_LIMIT) to handle more complex tasks.

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant