Skip to content

fix(dispatch): 派单子话题的代发最终回复不再 @ 派单 bot - #2001

Merged
deepcoldy merged 2 commits into
deepcoldy:masterfrom
wutonga1990:fix/dispatch-footer-no-dispatcher-at
Oct 19, 2026
Merged

deepcoldy merged 2 commits into
deepcoldy:masterfrom
wutonga1990:fix/dispatch-footer-no-dispatcher-at

Conversation

@wutonga1990

Copy link
Copy Markdown
Contributor

botmux dispatch 开出的子话题里,stdout-runner 类 CLI(mira / mir / dsh)由 daemon 代发的最终回复卡片,页脚会 @ 派单的主 bot(daemonCardFooterRecipientOpenId 为这几种 CLI 把收件人设成 creatorOpenId,/repo 预置的派单则是 bot owner)。而 dispatch 追加给执行 bot 的「完成回报」协议要求用 botmux report --dispatch-root 把结果交回主编排会话,并明确说不要在子话题里 @ 主 bot:主 bot 的会话不在这个话题,这个 @ 只会在子话题里另起一个没有派单上下文的新会话。

本次改动:子话题根消息在 orchestrate-dispatch.json 里有验签通过的 report 绑定时,上面两条分支都不再把派单 bot 作为页脚收件人。判定复用 resolveVerifiedDispatchReportTarget,和 report --dispatch-root 走同一份绑定;绑定不存在、验签失败或读取出错时维持原行为。代发卡片的失败兜底照旧:没有真人收件人时仍 @ bot 管理员。其它 CLI、zero-prompt 路径、botmux send 的页脚逻辑都不变。

验证

  • 新增 test/bridge-final-output-retry.test.ts 的「in a topic opened by botmux dispatch」一组:mira / mir / dsh 不再 @ 派单 bot;/repo 预置的 bot owner 同样不 @;失败轮次仍 @ 管理员;绑定验签不过时仍 @ 派单 bot。去掉源码改动时前 5 条失败。
  • bunx vitest run test/bridge-final-output-retry.test.ts:194/194 通过
  • bunx vitest run test/zero-prompt-terminal.test.ts test/zero-prompt-relay-integration.test.ts test/dispatch-report-binding.test.ts test/durable-lark-final-output.test.ts test/turn-terminal-receipt-card.test.ts:26/26 通过
  • bunx tsc --noEmit -p tsconfig.json:通过

Fixes #1887

— Claude

🤖 Generated with Claude Code

…ack final card

The stdout-runner CLIs (mira/mir/dsh) address their daemon fallback card back
to the dispatching bot so orchestration resumes. In a topic opened by
`botmux dispatch` the brief already asks the worker to `botmux report
--dispatch-root`, which reaches the dispatcher's own session; the extra @ only
starts a fresh dispatcher session in the sub-topic without the dispatch
context. Skip it when the topic carries a verified report binding.

Fixes deepcoldy#1887
@deepcoldy

Copy link
Copy Markdown
Owner

你好,这个 PR 的自动评审群已建,麻烦点击链接加入群聊、查看评审意见并跟进后续修改:
https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=2e5mdd2a-1691-4d7a-ae6d-356b58cfbdc4

另外你暂时不在自动拉群名单里,也可以把 GitHub 账号和飞书信息补进名单文档,补好后后续评审会自动拉你进群:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe

(本条为自动流程发出的提示消息)

@deepcoldy

Copy link
Copy Markdown
Owner

自动评审初步意见(最终以维护者复审为准)

改动方向正确:mira/mir/dsh 两条 footer 分支复用 resolveVerifiedDispatchReportTarget 判定、失败时维持原行为、失败轮次回退 @ 管理员,这部分我本地验证通过(194 测试全绿;删掉两处守卫后新增 5 条断言全红、tamper 条仍绿,变异有效)。

但有一个 issue 里明确报告、本 PR 未覆盖的路径:

P2:zero-injection 的 structured-bridge / transcript CLI(issue 里点名的 antigravity 就在此类)仍会 @ 派单 bot

#1887 原文除 dsh 外还写了「antigravity 也观察到同样现象」。antigravity / cursor 在 promptInjection: 'none' 下走的是 worker-pool.ts 里 zeroPromptFinalInitiator 这条收件人路径,不经过本 PR 修改的 daemonCardFooterRecipientOpenId:

  • final 投递处(src/core/worker-pool.ts 约 19154-19157 行):recipientOpenId = imOrigin?.replyTargetSenderOpenId ?? (zeroPromptReply ? initiator?.openId : daemonCardFooterRecipientOpenId(...))
  • 出生回合并没有区分派单:src/daemon.ts 约 23696 行 beginReplyTargetTurn(..., { senderOpenId, ... }) 的 senderOpenId 就是种子消息发送者(派单 bot)
  • zeroPromptFinalInitiator 只排除了 bot 自身,不排除其它 bot,于是 zero-prompt 会话的 final 卡片页脚仍然渲染「发送给:@派单 bot」

我在本 PR 树上加了一条临时探针测试(antigravity ds + promptInjection:'none' + 按出生回合形状盖 reply target + 验签通过的 binding)实证:卡片仍包含 <at id=ou_dispatcher_bot></at>,探针随后已删除。同一原因下,这些 CLI 的失败轮次也会因为 recipientOpenId 是 bot 而拿不到 failureNoticeFallbackMentionOpenId 的管理员兜底。

建议修法(与 runner 分支同一口径):在 zero-prompt 选择 initiator 时,若 initiator.isBot === true 且 topicReportsToDispatcher(ds) 验签通过,则不把它作为收件人(失败轮次自然回退到管理员),并补 antigravity/cursor 类 zero-prompt CLI 的用例。任一支持 zero-prompt 的 transcript CLI 在 none 模式下被 dispatch 时同理,建议用不针对具体 CLI 的断言覆盖。

P3(不阻断)

  1. topicReportsToDispatcher 每次 final 都同步读+解析整个 orchestrate-dispatch.json 并重新加锁读密钥;该 registry 目前没有任何清理(dispatch-registry.ts 只增不删)。与现有 zeroPromptTaskContent 的模式一致,短期可接受,后续可按 rootMessageId 做会话级 memo。
  2. 新用例把 orchestrate-dispatch.json 写进整个测试文件共享的临时 dataDir 且无 afterEach 清理,目前恰好文件内后续没有 runner CLI 用例才不互相影响;建议补清理,避免后续用例顺序变化时踩坑。
  3. buildSessionTurnFailedCard(recovery/终态兜底失败卡)共享了新门控但没有对应用例,可补一条「派单话题内失败卡收件人=管理员」的断言。

已验证

  • bunx tsc --noEmit:通过
  • vitest run test/bridge-final-output-retry.test.ts:194/194;PR 列出的 5 个相关文件:26/26;失败卡/失败通知相关 5 个回归文件:132/132
  • 基线为最新 master(merge-base 即 origin/master tip),无需 rebase

@deepcoldy

Copy link
Copy Markdown
Owner

复审补充(双审已收敛:建议修改)

维护者复审已完成,与初审结论一致(0 P1 / 1 P2),并对 P2 补充了一个我初审时只点到、未展开的硬后果,请一并处理:

P2 补充:只抑制 @ 会让 zero-prompt CLI 的结果彻底静默,修法必须同时处理回报通道

src/core/worker-pool.ts:19470-19486:zero-prompt 会话的自动回报 onZeroPromptFinal(→ reportZeroPromptFinal,经 session relay 把结果送回主编排会话)在 initiator?.isBot && !explicit 时被刻意抑制,代码注释写明的假设是「real @ already returns this result to the initiating bot」。

而 antigravity/cursor 这类 zero-prompt CLI:

  • 收不到简报末尾的「完成回报」协议——zeroPromptTaskContent(src/daemon.ts:4193-4201)在绑定验签通过后会把该协议段 strip 掉,它们也不会自己去跑 botmux report;
  • 自动回报又因 bot initiator 被上面这条抑制掉;
  • 现状唯一的结果外送通道就是这张 @ 派单 bot 的卡片。

所以如果只按初审建议在 initiator 路径抑制 @,结果会变成:子话题里一张没人被 @ 的卡片 + 主编排什么都收不到。修法需要二选一或组合:

  1. (推荐,语义对称) 在「绑定验签通过的派单子会话」里放开 onZeroPromptFinal:@ 卡片被刻意去掉后,自动 report(prepareAutomaticDispatchReport → deliverReportSessionRelay)本就是 zero-prompt runner 把结果交回主编排会话的正式通道;:19471 的抑制条件应在 topicReportsToDispatcher(ds) 为真时不再适用。失败轮次仍走管理员兜底。
  2. (保守选项)卡片不 @ 派单 bot,但改 @ 真人 owner/管理员——结果有人可见,但主编排 bot 仍收不到结构化回报,dispatch 编排链还是断的,只算止血。

对修法锚定信号的说明

复审建议过「在 registry entry 上落 childSessionId、不做严格验签」的方向。这里说明一下:现有 resolveVerifiedDispatchReportTarget 执行方并不需要持有 targetLarkAppId——它读的是共享 dataDir 里的 registry entry(payload 自带 targetLarkAppId)+ fleet 共享签名密钥(<dataDir>/../.dashboard-secret.report-binding),入站侧既有的 zeroPromptTaskContent 已经在生产里走这条验签链路。所以直接复用 topicReportsToDispatcher 不会 fail closed。childSessionId 锚定可以把匹配从「话题 root」收窄到「具体子会话」,但需要执行会话创建后跨进程回写 registry,属可选加固,不是本次修复的必要条件。

P3 勘误

  • 撤回我上一条的 P3②(测试 dataDir 无清理):该文件外层 afterEach(约 306-313 行)每例后 rmSync(config.session.dataDir, {recursive:true, force:true}),嵌套 describe 同样生效,不存在串扰。
  • P3①(registry 全量读/密钥加锁)影响面比初审措辞更小:topicReportsToDispatcher 仅在 mira/mir/dsh 会话的两个 isRunnerDeliveryCli 短路分支内被调用;仍建议后续按 rootMessageId memo,不阻断。
  • P3③(buildSessionTurnFailedCard 路径缺用例)维持,非阻断。

即:本次需要作者处理的实质项只有 P2 一个——覆盖 zero-prompt initiator 路径,并保证结果回报通道不被一起掐断;其余为非阻断测试/性能建议。

…d of @-ing the dispatcher

Review follow-up: zero-injection CLIs pick the recipient from the turn
initiator, not the runner branch, so they still @-ed the dispatching bot.
When the initiator is a bot and the topic carries a verified report binding,
drop that @ and let the automatic dispatch report (previously suppressed for
bot initiators) return the result. Failed turns fall back to the bot admin.

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

wutonga1990 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

感谢两轮评审。P2 已按推荐方案(选项 1)改完,提交 ffe98a995:

P2:zero-prompt initiator 路径

  • 在 deliverFinalOutput 里:zero-prompt 会话的 initiator 是 bot,并且本轮的 dispatch root 在 topicReportsToDispatcher 验签通过时,页脚不再 @ 这个 initiator。
  • 同一条件下放开 onZeroPromptFinal:原来对 bot initiator 抑制自动回报的前提是「real @ already returns this result」,现在 @ 去掉了,自动 report 就是把结果交回主编排会话的正式通道,避免结果彻底静默。
  • dispatch root 按原来 report input 的口径只算一次(zeroPromptDispatchRoot),验签判定和 report 用的是同一个值;topicReportsToDispatcher 改为接收 root 参数。
  • 失败轮次:recipientOpenId 为空,回落到 failureNoticeFallbackMentionOpenId 的管理员兜底。
  • 绑定不存在或验签失败时行为不变:仍然 @ initiator,也不自动 report。

新增用例(与具体 CLI 无关的断言,用 antigravity 形状的 zero-prompt 会话)

  • 验签通过:卡片不 @ 派单 bot,onZeroPromptFinal 收到 dispatchRoot: 'om_root'。
  • 验签不过:仍 @ 派单 bot,不 report。
  • 失败轮次:@ 管理员,不 @ 派单 bot。
  • P3③:runner 会话的 turn_terminal ambiguous 失败卡,收件人是管理员。为此给文件里的 card-builder mock 补了 buildTurnFailedCard,把 mentionOpenId 透出来做断言。
  • 换回本 PR 之前的 worker-pool.ts 跑一遍:本 PR 新增的 8 条正向断言全部失败,2 条「验签不过」的对照照常通过。

验证

  • bunx vitest run test/bridge-final-output-retry.test.ts:198/198
  • 相关 7 个文件(zero-prompt-terminal、zero-prompt-relay-integration、dispatch-report-binding、durable-lark-final-output、turn-terminal-receipt-card、turn-failure-card、turn-terminal-receipt):102/102
  • bunx tsc --noEmit -p tsconfig.json:通过;git diff --check:通过

P3①(registry 按 rootMessageId 做 memo)这次没有做。现在每张 final 卡片最多读一次,按复审说的影响面不大,想留到后续单独处理;如果希望并进这个 PR,告诉我就补。

— Claude

@deepcoldy

Copy link
Copy Markdown
Owner

你好,这个 PR 的自动评审群已建,麻烦点击链接加入群聊、查看评审意见并跟进后续修改:
https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=cd3g3735-1044-4a0b-ad40-9713223607e7

另外你暂时不在自动拉群名单里,也可以把 GitHub 账号和飞书信息补进名单文档,补好后后续评审会自动拉你进群:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe

(本条为自动流程发出的提示消息)

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.47.0

wutonga1990 added a commit to wutonga1990/botmux that referenced this pull request Nov 7, 2026
deepcoldy#2001 只在 daemon 代发的兜底/零注入卡片上按验签绑定去掉对派单 bot 的 @。
派单话题里执行方模型自己发的最终回复卡走的是 botmux send,页脚仍会把派单
bot 作为 --mention-back / 显式 --mention 的收件人 @ 出去,这个 @ 会在同一
子话题里另起一个没有派单上下文的会话(deepcoldy#1887)。

现在 botmux send 在动手发消息前先解一次本话题的 report 绑定:
- 绑定验签通过,且收件人 open_id 解析到绑定里的 targetLarkAppId → 去掉该 @,
  并在 stderr 说明原因;
- 绑定缺失、损坏、验签不过、或 open_id 解析不出来 → 行为与改动前逐字一致。

人发送者、其它 bot、非派单话题的判断都不受影响:只过滤「绑定证明的派单
bot 本 app 视角 open_id」。

Fixes deepcoldy#1887
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.

dispatch 子话题里代发的最终回复页脚自动 @ 主编排 bot,与「完成回报」协议冲突

2 participants