Skip to content

fix(bridge): 回报唤醒抑制兜底卡、同群跨话题 final 去重并延后排队占位卡 - #3433

Merged
deepcoldy merged 5 commits into
deepcoldy:masterfrom
xushulong-solo:fix/report-turn-final-suppress-card
Nov 19, 2026
Merged

deepcoldy merged 5 commits into
deepcoldy:masterfrom
xushulong-solo:fix/report-turn-final-suppress-card

Conversation

@xushulong-solo

@xushulong-solo xushulong-solo commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

问题与根因

  1. 共享群会话被 botmux report 唤醒后误往旧真人话题补发兜底卡:群级主控(scope=chat)处理子任务 botmux report 唤醒属于合成回合,但会沿用会话上一次真人消息的话题锚点,且 /api/trigger 无 stableTurnId。当模型未调用 botmux send 或仅在终端输出分析时,结构化转写兜底会把终端文字补发到无关的上一个真人话题。
  2. 同群跨话题显式 --response-kind final 后仍在原锚点补发第二张卡:同一回合已通过 botmux send --response-kind final 向同群目标话题完成最终交付时,当前锚点上的终端文字仍被兜底补成重复卡片。
  3. 排队回合(type-ahead)提前发出「正在处理你的请求…」占位卡:当终端捕获身份(capture_identity)仍归属前一回合时,后续排队回合立即发出统一回复占位卡;若该排队输入最终未实际进入捕获,会残留孤儿占位卡。

改动说明

  • src/core/report-session-relay.ts:buildOrchestratorReportTrigger 统一附带 options: { suppressFinalOutput: true },仅抑制回报合成回合的转写兜底卡,不影响模型显式调用的 botmux send 投递。
  • src/services/bridge-fallback-gate.ts、src/core/worker-pool.ts:当同一回合已通过 --response-kind final 成功投递至同群另一话题时抑制当前锚点的重复兜底卡;跨群、dispatch_report、仅发送 progress、本轮未发送 final 以及失败告警通知均保持原行为不变。
  • src/core/worker-pool.ts:新增 unifiedReplyTurnNotCapturing 与 deferredUnifiedReplyTurns,在 capture_identity 仍属其他回合时暂缓发送统一回复占位卡,待 capture_identity 切换到本回合后再补发;从未开跑的排队回合不留残卡。

影响范围评估

  • 跨会话类型:影响 botmux report 唤醒的群级/话题级主控回合、同群跨话题显式 final 投递以及排队输入(type-ahead)统一回复卡时机;普通单话题问答、跨群通知、progress 进度汇报与异常失败兜底不受影响。
  • 跨 CLI / 跨后端:位于 daemon 侧 report-session-relay、bridge-fallback-gate 与 worker-pool 公共收口层,与具体 CLI 适配器及 PTY/Tmux 后端正交。

测试验证

bun run typecheck
bun run build
bun x vitest run --project unit \
  test/report-session-relay.test.ts \
  test/bridge-fallback-gate.test.ts \
  test/trigger-session-turn-idempotency.test.ts \
  test/zero-prompt-relay-integration.test.ts \
  test/recall-frozen-cards.test.ts \
  test/turn-reply-card-runtime.test.ts \
  test/test-hygiene.test.ts
bun test test/bridge-fallback-gate.test.ts test/report-session-relay.test.ts
  • typecheck、build(含 audit:domains、audit-dist、audit-embed)全部通过;
  • vitest 7 个测试文件全部通过(含 test-hygiene);bun test 2 个文件 247 项断言全部通过。

补充修复:延迟占位卡发布顺序

  • 问题:releaseDeferredUnifiedReplyCard 的延迟发布未进入 trackStartingCardPublication,后续原生思考消息可能抢在占位卡 POST 完成前创建。
  • 探针证据:在 test/recall-frozen-cards.test.ts 将占位卡发布保持 pending;旧实现的 pendingStartingCardPublication(ds) 为 undefined,回归断言以 expected undefined to be defined 失败;接入跟踪后同一断言通过,并在发布完成后恢复 undefined。
  • 修法:src/core/worker-pool.ts 复用现有发布跟踪器,不改变“未开跑回合不发卡”的语义。
  • 增量验证:bun run build、bun run typecheck 通过;10 个相关 Vitest 文件共 744 项通过;2 个 Bun 原生测试文件共 247 项通过。

补充修复:queue commit 不得绕过 capture 门控

  • 问题(合前必修):turn_input_committed 只代表 worker 队列已接收,可能早于 capture_identity。原实现经 { kind: "start" } 直接发布统一卡,导致未开跑的 type-ahead 仍留下占位卡。
  • 旧实现证据:旧 capture 下 admission 为 0 次 POST,queue commit 后变为 1 次 POST。新增真实 worker handler 回归也在旧实现上以“预期 0 次更新、实际 1 次 start”失败。
  • 修法:queue commit 与 admission 共用同一 deferred 集;精确 capture 后以 tracked start 释放 working 卡。仅把 release 改回 refresh 时,两项相位断言均失败。
  • 真实持久化复验:queue commit 后 replies: 0、phase: "queued";精确 capture 后 replies: 1、phase: "working",延长等待仍只有一张卡,探针退出码 0、stderr 为空。
  • 最终基线与验证:合入 origin/master 602e7cf56b36dc22e391e2b29e7e614a4c010d48 无冲突;最终树为 ceeb1a4fb273be2c62db6ac3516a392261362ff6。bun run build、bun run typecheck 通过;10 个相关 Vitest 文件共 702 项通过;2 个 Bun 原生测试文件共 247 项通过。

回报唤醒一律带 suppressFinalOutput。共享会话会把上一则真人话题继承到这条合成回合,/api/trigger 没有 stableTurnId,因此只丢掉转录兜底,显式 botmux send 仍会发出。

同一回合已经用 --response-kind final 发到同群另一个话题时,当前锚点上的终端文字不再补成第二张卡。跨群、dispatch_report、只发了 progress、以及本轮没发 final 时,兜底保持原样。失败通知仍要求落到本话题。

统一回复卡的「正在处理你的请求…」在捕获身份还是别的回合时先不发,等 capture_identity 切到本回合再发。从未开跑的 type-ahead 不会留下卡片。

测试:
bun x vitest run --project unit test/report-session-relay.test.ts test/bridge-fallback-gate.test.ts test/trigger-session-turn-idempotency.test.ts test/zero-prompt-relay-integration.test.ts test/recall-frozen-cards.test.ts
412 passed。
node scripts/tsc.mjs -p tsconfig.typecheck.json 通过。
bun run build 通过。
@xushulong-solo

Copy link
Copy Markdown
Contributor Author

礼貌跟进一下本 PR:

  • 这三项抑制与去重(botmux report 回报唤醒默认 suppressFinalOutput、同群跨话题 final 不在原锚点补发兜底卡、占位卡等 capture_identity 切到本回合后再发)在本机多代理日常协作中持续稳定运行。
  • 已在本地将该分支与最新 master(13dc70151)试合并验证:typecheck 与相关 5 个单测套件(423 条用例)全部通过,零冲突。
  • 当前远端分支无合并冲突且 CI 12/12 全绿,烦请维护者有空时安排评审合入,谢谢!

DeepCold review and others added 2 commits November 19, 2026 08:24
capture_identity 释放的统一回复占位卡与准入时发布走同一个跟踪器,避免后续思考消息抢在占位卡前创建。回归用例先控制占位卡发布悬置,验证等待关系存在并在发布后清空;该断言在未接入跟踪器时失败。

Co-Authored-By: Kimi Code <[email protected]>

@deepcoldy deepcoldy left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

自动评审结论:修后可合。原 head 0d07e1240 的 1 个合前必修问题和 1 个同主题 P3 均已修复;当前 head 为 85bfd40df87a485c0861b68eff3123c93dba88c4。本地验证通过,仍需当前 head 的首跑 CI 全绿及维护者复核后再合入。

  • 基线:最终合入 origin/master 602e7cf56b36dc22e391e2b29e7e614a4c010d48,无冲突;最终 tree 为 ceeb1a4fb273be2c62db6ac3516a392261362ff6。
  • 合前必修问题:src/core/worker-pool.ts:21352 附近,turn_input_committed 在旧 capture identity 下通过 { kind: "start" } 提前发布统一占位卡,绕过原 PR 的 deferred 机制。真实组件旧实现复现为 admission 0 次 POST、queue commit 后 1 次 POST;新增 test/recall-frozen-cards.test.ts:857 的真实 worker handler 回归也以“预期 0 次、实际 1 次 start”咬红。现 queue commit 与 admission 共用同一 capture 门控。
  • 相位与顺序:deferred release 改为 tracked start。真实 TurnReplyCardStore 复验为 queue commit 后 0 POST / queued,精确 capture 后 1 POST / working,延长等待仍仅一张卡,探针退出码 0、stderr 为空。仅把 release 改回 refresh 时两项相位断言均失败。发布同时进入 trackStartingCardPublication,避免后续原生思考消息抢在占位卡前创建。
  • 其他变异复验:移除回报 suppressFinalOutput 后 5 项失败;关闭同群跨话题 final 去重后 1 项失败;取消排队占位卡延后后 1 项失败。变异后源码均已还原。
  • 最终验证:bun run build、bun run typecheck 通过;10 个相关 Vitest 文件共 702 项通过;2 个 Bun 原生测试文件共 247 项通过;还原最后一处变异后 recall-frozen-cards 86 项通过。
  • 影响面:未新增配置、prompt 或常驻消息;回报与跨话题 final 属错误投递修复。未显式开启统一回复卡的现有配置不受占位卡时序变化影响。

这是自动评审的初步意见,最终以维护者审阅为准。

DeepCold review and others added 2 commits November 19, 2026 09:07
turn_input_committed 只代表 worker 队列已接收,可能早于 capture_identity 到达。旧路径会用 start 直接发布统一占位卡,使未开跑的 type-ahead 仍留下卡片。现在 queue commit 与 admission 共用同一 deferred 集,精确 capture 后以 start 释放 working 卡,并保留启动卡发布顺序跟踪。

真实 IPC 回归先验证旧 capture 下 queue commit 零更新,再验证精确 capture 后仅一次 start;旧实现在前一步产生一次 start。真实 TurnReplyCardStore 探针确认 commit 后保持 queued、零 POST,capture 后仅一张 working 卡。仅把 release 改回 refresh 时两项相位断言均失败。

Co-Authored-By: Kimi Code <[email protected]>
@deepcoldy
deepcoldy merged commit 57b923f into deepcoldy:master Nov 19, 2026
15 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

已合并,感谢贡献!

三个问题的修复(report 合成回合抑制兜底卡、同群跨话题 final 去重、排队占位卡延后到 capture_identity)连同评审中发现的 turn_input_committed 旁路修复都已随 #3433 落地。

一个非阻断 follow-up 供后续参考:worker-pool 中 deferredUnifiedReplyTurns 是每会话 32 条上限的内存 LRU,极端情况下(同一会话排队超过 32 个回合)最早入队的等待记录会被淘汰,对应回合只少一张中间占位卡,最终答复卡片不受影响;如后续观察到深排队场景再考虑收紧即可。

这是自动评审的初步意见,最终以维护者审阅为准。

deepcoldy pushed a commit to Barrierml/botmux that referenced this pull request Nov 19, 2026
修正上一 merge commit 的手工冲突解决错误(当时用 rebase 树覆盖了
auto-merge 结果,把 deepcoldy#3433/deepcoldy#3587/deepcoldy#3542/deepcoldy#3559 在重叠文件上的主干改动
一并回退,CI recall-frozen-cards/runtime-reservation 等 6 条失败):

1. 恢复主干:deepcoldy#3433 排队占位卡(postUnifiedReplyPlaceholder)、
   deepcoldy#3587 unowned reservation 拒绝(startRefusal/
   RuntimeReservationRefusedError)、deepcoldy#3542 Chrome node service、
   deepcoldy#3559 内存告警 owner 私信的全部代码与测试。
2. boundary_unobserved 改凭 turn.terminalObserved 判定而非
   !terminalOutcome:marker-less 旧 JSONL 靠下一回合 user 记录关单,
   queue 只置 terminalObserved 不写 terminalOutcome,旧条件会误标。
3. recordTerminalFailureStrict 抛错时保留 idempotentAsyncTurns
   收敛标记,仅持久化成功后释放;否则重启后 durable 停留 pending、
   无 worker-exit backstop,触发器永久 running。

测试:集成用例补 marker-less 边界(变异回 !terminalOutcome 咬红);
async-terminal-settle 补 EIO 写入抛错保留收敛标记用例(变异把删除
移回 catch 外咬红);recall-frozen-cards、runtime-reservation 等
主干回归本地全绿。

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

Copy link
Copy Markdown

🚀 Released in v3.59.21

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