Skip to content

fix(session): 修复普通消息身份登记与 Codex App 启动回复 - #3241

Merged
deepcoldy merged 9 commits into
deepcoldy:masterfrom
uestcwangci:fix/codex-app-startup-dispatch
Nov 9, 2026
Merged

deepcoldy merged 9 commits into
deepcoldy:masterfrom
uestcwangci:fix/codex-app-startup-dispatch

Conversation

@uestcwangci

@uestcwangci uestcwangci commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

普通飞书消息在存活会话中走投递追踪时绕过执行登记:CLI 已收到输入,但 daemon 拒绝该轮的身份凭据发布和投递回执,随后 actor current / auth request 返回 current_actor_unverified。Codex App 另有启动重绑定、恢复期就绪与最终回复归属问题,会使话题停留在启动中或生成完成后没有正文回复。

本 PR 修复执行登记、启动派发及完成结算链路,不放宽当前用户、进程或执行来源校验。

修改与影响面

  • 普通消息身份登记:追踪投递在第一次 IPC 前持久化 execution,并冻结到投递记录;同代重试复用准确 execution。关闭中的会话拒绝新输入。冷启动 init 不在此处登记 execution,沿用原有登记路径;但关闭中拒绝同样作用于走追踪投递的 init,会话关闭中时 init 不再发出。
  • Codex App 启动与恢复:按完整物理进程身份及原生会话绑定 runtime;准确 queued 派发可持久化 prepared,不能提前启动 execution。签名状态使用当前语义绑定,输入等待当前连接完成认证及签名就绪。空闲会话在同一 worker 内重连控制通道时,期间到达的输入被签名屏障暂存;新连接上报签名空闲而提示符早已就绪时补一次派发,不再滞留到下一条输入。
  • 最终回复:从不可变 FIFO 队首恢复准确 turn/attempt;同一物理 runner 下的旧未决执行只能通过持久 observer 结算结果及终态,不取得新输入、身份或运行控制权。持久化 ACK 前不推进账本。
  • 授权诊断:只在 daemon 日志记录拒绝阶段(来源缺失、进程未证实、调用人缺失、查询期间换轮等),不记录身份凭据、令牌或正文,不改变公开错误响应。

普通消息登记属于共享 worker-pool 路径,影响启用 session contract 的各 CLI、话题/群会话及转移后追踪投递;行为回归覆盖 Codex App 与 Claude。Codex 的签名就绪和 observer 入口仅用于 Codex App。保留 PTY/tmux、adopt/remote 的现有边界;没有数据库 schema 或配置格式变更。现场为 Linux;macOS 未做现场验证,无法取得进程证明时仍拒绝。

实际验证

使用 Bun 1.4.4:

  • bun run build:完整编译、类型检查、资源与构建审计通过;保留既有浏览器补丁的单文件部署版本也完成构建。

  • bun run test -- test/ipc-auth-request.test.ts test/current-actor-warm-engine-proof.test.ts test/worker-codex-app-input-proof.test.ts:3 文件、68 项通过。

  • bun run test -- test/session-contract-gateway.test.ts test/session-contract-recovery.test.ts test/worker-input-delivery-redrive.test.ts test/worker-ipc-preload.test.ts test/worker-topic-output.test.ts test/worker-ordinary-im-receipt-wiring.test.ts:6 文件、174 项通过。

  • bun run test -- test/worker-managed-origin-contract.test.ts:9 项通过。执行真实追踪 sender → command → worker scope/publisher → controller/gateway/SQLite → 绑定 HTTP 授权路由;追踪输入夹具不预先手工 admit。外部 OAuth/飞书传输受控。

  • 前期启动/最终回复/observer/身份回归:9 文件248项、4文件87项及10文件249项分别通过;恢复来源、observer、历史正文及签名就绪的守卫变异均被相关行为测试捕获。

  • 合并最新主分支并解决输入循环及 IPC backlog 合并冲突后,bun run build 通过;bun run test -- test/worker-managed-origin-contract.test.ts test/current-actor-warm-engine-proof.test.ts test/worker-codex-app-input-proof.test.ts test/worker-codex-app-final-origin.test.ts test/worker-input-delivery-redrive.test.ts test/worker-topic-output.test.ts test/test-hygiene.test.ts:7 文件、146 项通过。

  • 重连补派发与回归补齐提交后:bun run build 通过;bun run test -- test/worker-codex-app-input-proof.test.ts test/codex-app-execution-observer.test.ts test/codex-app-historical-final-delivery.test.ts test/worker-codex-session-upgrade.test.ts test/test-hygiene.test.ts:5 文件、107 项通过;bun test --timeout=180000 ./test/worker-codex-session-upgrade.test.ts ./test/worker-codex-app-input-proof.test.ts:51 项通过。此前该升级测试自带的求值作用域缺少 flushPending 新依赖的 isCodexAppCliId,vitest 2 例、bun 13 例报 ReferenceError,已一并补上。含 worker 求值夹具、Codex App 与 session contract 的 52 个测试文件:1128 项通过、4 项跳过。合入最新主分支后无冲突,构建与上述用例同样通过。

异常场景与探针证据

  • P1,普通消息已投递但身份缺失:恢复旧追踪 sender 后,received、managed origin、committed 均被真实 controller 以 execution_scope_missing 拒绝,真实绑定授权路由返回403。修复后两种 CLI 的人类来源可发布,收据正确清账,授权接口返回200;准确 OAuth 收件人与原输入一致。
  • 投递重试 × 迟到回调:假时钟推进真实2秒超时,重试保留同一 execution;旧回调不干扰当前尝试,receipt 正确结束追踪。移除执行登记守卫使对应回归失败。
  • 多步落盘只完成一半:execution 写入后结果绑定写入抛错,SQLite 原子回滚,没有 IPC 或追踪记录;随后同轮重试正常登记。关闭中拒绝新输入,移除该围栏的变异触发失败。
  • 恢复期间人工干预:挂起、替换 worker、移除准确 prepared 队首、旧物理进程回调、ACK 超时/迟到均保留拒绝边界。observer 与兼容 Session 行写入失败一并回滚,重试幂等。
  • 签名就绪:静态 type-ahead 及终端启动超时不能代替原生引擎证明;入口、等待启动工作之后、循环出队前三处屏障分别移除后均触发行为回归。
  • 控制通道重连:空闲会话的认证连接断开后,待派发输入先被屏障拦住;新连接上报签名空闲后该输入被派发一次。去掉补派发后重连用例失败。
  • observer 与干预边界:执行 observer 授权不扩展到 final_output_offer、turn_interrupt_result、codex_app_dispatch_persisted、restart_result,放开到任意事件类型后这 4 例失败;重启控制进行中历史最终回复投递失败后不重试、不结算,去掉 activeOperationId 检查后该用例以重试次数断言失败(3 次而非 1 次),不依赖用例超时。

现场状态与验证边界

已部署保留现有浏览器修复的单文件版本,仅重启目标机器人的 daemon;其它机器人 daemon PID 未改变,原话题和 native thread 保留。部署后原话题已认证并进入 prompt-ready;随后正常接收新的真人回合。

早先已从飞书读回成功恢复的正文回复。此次授权失败则进一步定位到普通消息缺少 execution,而不是仅凭启动就绪修复就认定授权已恢复。

经明确授权,向原运行时投递了一次只读诊断;该自动输入没有真人发送者,身份及授权仍按边界拒绝,没有伪造 actor 或回退 owner。

2026-11-09 17:56(北京时间),新的真实飞书用户回合已通过身份校验;17:57 修正原请求的表格权限名后,授权请求成功。daemon 于17:57:20记录私聊授权消息投递成功,17:57:33将“授权申请已私聊发送”的正文回复到原话题;通过会话绑定的 lark-cli im +threads-messages-list --no-reactions --as bot --format json 独立读回确认。随后又正常接收用户“已授权”的下一条消息。此处确认身份恢复、授权签发及私聊/话题回复成功,不把用户文字当作后续表格写入成功的证明。

@uestcwangci uestcwangci changed the title fix(codex-app): 修复运行时重绑定与首轮派发超时 fix(codex-app): 修复启动派发与结果恢复 Nov 9, 2026
@uestcwangci uestcwangci changed the title fix(codex-app): 修复启动派发与结果恢复 fix(codex-app): 修复启动派发、回复恢复与身份就绪 Nov 9, 2026
@uestcwangci uestcwangci changed the title fix(codex-app): 修复启动派发、回复恢复与身份就绪 fix(session): 修复普通消息身份登记与 Codex App 启动回复 Nov 9, 2026
空闲会话在同一 worker 内重连控制通道时,期间到达的消息被 flushPending 的签名就绪屏障暂存;新连接上报签名空闲后 markPromptReady() 因提示符早已就绪直接返回,消息会滞留到下一条输入才被带出。签名空闲且提示符已就绪时,若仍有待派发输入则补一次 flushPending。

同时补齐回归覆盖:
- 重连期间暂存的输入在新连接签名空闲后被派发(去掉补派发即红);
- 执行观察者授权不扩展到 final_output_offer、turn_interrupt_result、codex_app_dispatch_persisted、restart_result;
- 重启控制进行中,历史最终回复投递失败后不重试、不结算;先推进假时钟再等待投递,使回归以断言而非用例超时判红;
- worker-codex-session-upgrade 自带求值作用域补上 flushPending 新依赖的 isCodexAppCliId(vitest 2 例、bun 13 例 ReferenceError)。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@deepcoldy
deepcoldy merged commit 157be9c into deepcoldy:master Nov 9, 2026
11 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

已 squash 合入 master(落地提交 157be9c),感谢 @uestcwangci 的贡献。

这组改动把 Codex App 在 worker 重启、warm reattach 和连续消息合并时的 final 归属证明链路补完整了:execution observer 最小授权、FIFO 队首精确结算、进程/rollout 身份证明,以及控制连接重连后被签名屏障暂存输入的补派发,整体保持 fail-closed。相关测试与变异覆盖也比较扎实。

一个留待后续观察的点(PR 描述里也提到了):最初触发 final 被拒收的具体时序目前还没有独立复现,这次主要是恢复加固与诊断增强;建议后续线上再遇到 Dropped final output with unproven execution origin 诊断日志时,结合新增的 origin/current/execution 字段定位根因。

deepcoldy pushed a commit that referenced this pull request Nov 9, 2026
现象:#2854 上线后,长会话里普通 IM 追问轮 `lark-cli --as user` 报
"No current requesting user",`botmux actor current` 返回
current_actor_unverified;休眠时还误报"无法确认是否执行"
(worker_retired_before_commit)。

根因:普通 IM 追踪投递(sendOrdinaryImDeliveryTracked)直接 worker.send,
绕过了 sendWorkerSessionInput 里唯一的 execution 登记。worker 手里没有登记过
的 execution,追问轮的 managed_turn_origin、收据和提交 ACK 都被契约层按
execution_scope_missing 丢掉(只打 debug),daemon 的当前轮身份拿不到这一轮
的发送者,投递追踪也一直结不清。#3241 已在 master 上给追踪投递补了登记;
但登记之后,worker 在提交 ACK 之前发出的 cli_input_backlog 也带上了这个尚未
绑定 runtime 的 execution,被事件网关拒掉,提交 ACK 又清空了投递追踪,队列里
还有输入的 worker 会在下一次 idle 时被延迟休眠收走,排队的消息丢失。

修法:
- cli_input_backlog 不再携带 execution scope(队列观测横跨多轮),
  producer/runtime/binding 校验照留;参考 #3257。
- daemon 丢弃当前 worker 的 managed_turn_origin / managed_turn_origin_revoked
  时打 WARN,带会话、turn 和原因;已被替换的 worker 仍是 debug。
- worker-managed-origin-contract 用例里对应断言从 debug 改为这条 WARN。

验证:
- 新增 test/ordinary-im-follow-up-turn-origin.test.ts(真实 daemon handler、
  SQLite 契约 store、worker 事件 scope 与 IPC send、actor current 与 lark-tool
  身份路由,只桩飞书/网络与 tmux 拆除校验)。覆盖:relay 改绑 pid
  (runtime_identity_changed)后的普通追问轮,身份是该轮发送者;休眠不再误报
  未确认;续聊时队列里有一条排队输入,不被提前休眠、伪造 producer 的 backlog
  被拒、队列清空后照常休眠;丢弃身份时打 WARN。
  #3241 之前的 a1f963f 上 5 条全红;当前 master 上排队输入和 WARN 2 条红
  (其余 3 条已由 #3241 修好);加上本改动全绿。只撤回 backlog 那一行时排队
  输入用例变红。
- #3257 的 test/lark-followup-authority.test.ts 拷到本地交叉验证:当前 master
  上排队输入那条红,加上本改动后 2 条全绿(该文件未提交)。
- 相关 vitest 104 个文件 4420 条通过;bun 腿 5 个文件通过;bun run build(含
  typecheck)通过。worker-codex-app-turn-routing.integration 的 12 条超时在
  改动前的源码上同样失败,与本改动无关。
- 其它仍未登记 execution 的回合路径(排队激活提升、只读续跑、带 turnId 的
  raw_input)另开 #3264;botmux list 的 (missing) 另见 #3261。

hotfix:线上 bug 快速通道

Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy pushed a commit to superShen0916/botmux that referenced this pull request Nov 9, 2026
同步 master 后,deepcoldy#3241 引入的 current-actor-warm-engine-proof 在合并树上确定性失败
(vitest shard 与 bun-test 双腿同样两个用例)。它的 worker-pool 闭包 harness 在
hostEnv 里没提供 workerGeneration,而本 PR 的 attestation 代守卫把该自由变量与
ds.workerGeneration 比较:缺失时解析为 undefined,7 !== undefined 导致一条带
enginePid 的合法 attestation 被拦截,断言拿不到 engine 身份。

纯 master 单跑该文件 7/7 绿、合并树 2 红,属本 PR 守卫要求的 harness 补注入,
与上一轮 session-contract-gateway 同类。hostEnv 补 workerGeneration: 7,与
ds.workerGeneration 一致,仅改测试、src 零改动。

验证:current-actor vitest 7/7、bun 7/7;合并树相关 18 文件 469/469;
find-launched bun 85/85;tsc、build 通过

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

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

这次运行覆盖 157be9c…7c0ad137d(4 个提交),同批合入的还有 #3250 #3251,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Claude basic bot flow feishu-core-claude failed waitFor timeout: The current screenshot shows a chat interface. The main content area displays a conversation titled "申晗和Claude的会话". The visible messages are:
OpenCode basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the main content area displays a chat topic titled "申晗和OpenCode的会话". I am examining the messages from "OpenCode" to see if there is an independent text bubbl…
Pi basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area which displays a conversation thread. There is a prominent card (streaming card) located above the text bubble containin…
OhMyPi basic bot flow feishu-core-clis failed waitFor timeout: The screenshot shows a chat interface. The main content area displays a conversation in a topic named "申晗和OhMyPi的会话". The visible content includes a text message from "申晗" and a card…
Kimi basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area which displays a conversation thread. There is a prominent card (streaming card) located above the text bubble containin…
Antigravity basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area on the right. There is a card from "Antigravity" located above the text bubble containing "ACK-e2e-antigravity-179423559…
Grok basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area (right panel) which displays a conversation thread. There is a specific card from "Grok" labeled "Grok Build • e2e-grok-…
Claude DM thread mode gives each message its own topic and session feishu-core-dm-modes-claude failed Reply "ACK-e2e-dmthread-claude-1-1794233721100 RECALL ACK-e2e-dmthread-claude-1-1794233721100" appeared 0 time(s) within 240000ms, expected 1 (clicked 直接开启会话 1×; re-opened 1×; repo card buttons 1 vis…
Claude group reply mode topic answers in topics that share one session feishu-core-group-modes failed Node "feishu.runScenario" timed out after 1800000ms.

deepcoldy pushed a commit that referenced this pull request Nov 9, 2026
现象:本机部署 7c0ad13(含 e95f067、#3251、#3241)后,机器人回复发不到
飞书,卡片一直停在「工作中」,冷启动第一轮和热会话追问轮都丢。worker 日志
"Dropped final output with unproven execution origin":origin 停在上一轮的旧
binding(runtime epoch 1),当前 binding 已换到 epoch 2;daemon 侧
managed_turn_origin 以 runtime_scope_missing / stale_runtime_scope 被丢,
final_output 被拒只打 debug。

根因:#3241(157be9c88)让 worker 在同一个 CLI 的身份变化时(in-pane relay
解析到真实 CLI pid 替换 launcher pid、resume 后 native session id 变化)在进程
内发布新的 runtime binding,契约 runtime epoch 1→2。但 spawn 时注册的回调
(转写桥、pane 退出、hook)仍挂在旧 binding 上,在途轮次的 execution 也绑在
旧 runtime 上:
- daemon 把旧 runtime 上的 final_output / managed_turn_origin 判为历史或
  stale,currentAuthority 不成立,回复被静默丢弃;
- worker 侧 ownsExecutionEvent 只认同一个 binding,转写桥对重绑后提交的轮次
  判为来源不明,本地丢弃;
- resume / restart 已确认后再重绑,新 binding 带着已结束的 operationId,被
  记成 retiring,daemon 回 mayExecute=false,worker 杀掉 CLI;
- launcher→真实 pid 重绑后 CLI 退出,退出事件挂在旧 runtime 上被当成历史
  事件忽略,不会自动重启;
- CLI 自己发起的轮次(定时任务、后台唤醒)重绑后同样被拒。
e95f067 和 #3251 不是根因。

修法:
- worker 重绑时在 runtime_binding 上带 continuesBindingId;daemon 只在前驱
  是同一 worker 的当前活跃 runtime 时记录进程内续接(runtime_continuation)。
- 事件网关和 currentAuthority 接受绑定在被续接 runtime 上的 execution 为当前;
  hook 的 nativeSignal 沿续接链指向当前 runtime。
- worker 事件 scope 把同一物理 CLI(physicalId 相同)的回调认作当前;重新
  spawn 的 CLI 物理 id 不同,旧观察者仍然无权。
- 续接时会话没有进行中的控制操作,就丢掉 spawn 时留下的 operationId。
- claude_exit 结束的 runtime 包括它续接出去的 runtime。
- 没有 execution 的轮次上报若来自续接前驱,归到当前 runtime 再登记 execution。
- daemon 拒绝当前 worker 的 final_output 时打 WARN,并在群里发一次「回复没能
  发出」提示;会话关闭、挂起、控制操作进行中或静默轮次不提示。

验证:
- 新增 test/runtime-rebind-turn-delivery.test.ts(真实 daemon handler、SQLite
  契约 store、worker 事件 scope、IPC send 与 runtime 发布,转写桥用 spawn 时
  留下的回调):冷启动中途 relay 改绑 pid 后两轮送达、resume 后 native id 变化
  两轮送达、热会话追问轮送达、追问轮 actor current verified、spawn 时 hook 指向
  当前 runtime、restart 确认后再重绑不杀 CLI、重绑后 CLI 空闲退出按当前 runtime
  处理、CLI 自发轮次送达,以及真拒绝时 WARN + 群提示、重启中不提示、重新 spawn
  后旧观察者无权。9d202b2ca 上 12 条红 11 条(剩下 1 条是守卫用例),本改动全绿。
- 最终版本:相关 vitest 373 个文件 9264 条通过,仅 mojo-launcher-env-quarantine 2 条
  失败(root 跑权限用例的环境问题,master 上同样失败);typecheck、bun run build 通过。
  前一版的全量 vitest 18 条失败(9 个文件),维护者已对照 91743e6 确认:16 条在
  master 上一样失败(root 跑沙箱/权限类用例),session-preview-proxy 单跑通过(高负载
  超时抖动),turn-idle-version-skew 与 master 失败一致。
  集成用例需 TMPDIR=/tmp:本会话继承的 TMPDIR 让 tmux socket 路径超长,
  master 上同样 16 条失败。
- G9(隔离环境,真 Claude Code 2.1.319 + in-pane relay + 私有 tmux + 本地假
  Anthropic API,未碰线上 fleet)冷启动和 restart 确认后启动两种模式各跑一次:
  CLI 在 launcher 下启动,第一轮进行中 relay 解析到真实 pid,契约 runtime 升到
  epoch 2;三轮回复都发到群里,第一轮、第二轮 Claude 自己跑的 botmux actor
  current --json 都是 verified,发送者和 turnId 与当轮一致;restart 操作为
  confirmed,CLI 没被杀。

hotfix:线上 bug 快速通道

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.0

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.

2 participants