Skip to content

fix(bridge): suppress post-final send narration - #2738

Merged
deepcoldy merged 5 commits into
deepcoldy:masterfrom
xgp01:fix/trae-final-output-after-final-marker-pr
Nov 3, 2026
Merged

deepcoldy merged 5 commits into
deepcoldy:masterfrom
xgp01:fix/trae-final-output-after-final-marker-pr

Conversation

@xgp01

@xgp01 xgp01 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • suppress short model final_output narration that only says a botmux final answer was already sent when a recent explicit final marker exists
  • keep ordinary queued-turn answers visible unless they match this narrow completion-narration shape
  • add bridge fallback regression coverage for the queued-turn post-final narration case

Validation

  • bun test test/bridge-fallback-gate.test.ts

Note

The clean upstream-based branch is commit 864fc94 on local origin/master, but this machine token cannot push branches containing upstream workflow commits because it lacks GitHub workflow scope. This PR branch is pushed from the fork baseline so it may need maintainer-side rebase if GitHub marks it conflicted.

@deepcoldy

Copy link
Copy Markdown
Owner

谢谢这个 PR!先同步一下评审情况(自动评审初步意见,最终以维护者审阅为准)。

背景认可

想解决的问题是真实的:type-ahead 排队场景下,模型通过 botmux send --response-kind final 投递前一轮答案后,在同一 native 执行里追加一句"已通过 botmux 发出最终结论…"的自述,transcript 兜底会把它当成后继排队 turn 的 final 再投一次,造成噪声。

但这个分支基于很老的 fork 基线(与当前 master 已无共同祖先,src/services/bridge-fallback-gate.ts 在该基线之上主干已有 +394/-44 的演进),目前 mergeable=CONFLICTING;把本 PR 的净逻辑移植到当前 master 实测后,"按文本形状猜测并静默吞掉后继 turn 投递"会在多个常见场景吞掉用户的真实答复(ghosting)。建议 rebase 后按下面方向重做。

必须处理

1. 分支需要 rebase 到当前 master。 三方合并在 bridge-fallback-gate.ts 有 10 处冲突。本 PR 在老基线上重新加入了主干已经存在的字段与函数(sessionId / deliveryKind / targetChatId / targetRootMessageId / targetSessionId / turnId / isFinalBridgeSendMarker / markerCoversOwnThread 等,与主干现状几乎逐字重复),同时会把主干的 responseKind: TurnSendKind 退化成字面量联合,并丢掉 dispatchRootId / deliveryId / terminalCarrier / contentHash / supersededTurns 等已有字段。rebase 后真正的净增量只有 isBridgeSendCompletionNarration 谓词和 recentPriorFinalMarkerExplainsCompletionNarration 这段短路。

2. 后继 turn 的真实短答复会被静默吞掉(消息丢失)。 在当前 master 上移植净逻辑后,以下后继 turn 的 final(同 chat、10 分钟窗口内存在任一其他 turn 的 final marker)都会被 suppress,但它们都是后继用户问题的真实答复:

  • botmux 的最终超时配置我已经核对过,建议调到 30 秒。
  • I used botmux to check the final result: the query returned 42 rows.
  • I have not sent any final reply through botmux yet.(否定句同样命中)

根因是谓词只要求:≤240 字 + 含 botmux + 命中一个「最终/结论/答复/final/answer/…」词 + 命中一个「已/发送/sent/used/called/…」词。中文集合含单字「已」、英文集合含 used/called,命中面远大于"发送完成自述"。而 worker 在判定 ready 的循环开头已经 journalBridgeTurnClear,suppress 后该 turn 直接按 answered 结算退休——用户永远收不到这条答复,比多一句噪声更糟。

3. 绕过 headless 的 fail-open 设计。 markTimeMs === undefined(Remote Runner 等 headless 后端的恢复 turn)时,当前主干明确规定非空 final 只能被 exact-turn 的 final marker 去重;新逻辑把时间下界退化为 -Infinity,实测一个 30 天前同 chat 的 final marker 也能让当前 turn 的短 final 被吞。

4. 任何其他 turn 的 marker 都能被"借"。 谓词只排除了恰好属于本轮(exact-turn)的 marker,于是 turn B 可以借同 session、同 chat 但与 A/B 都无关的 turn C 的 final marker。跨 turn 信用缺少"属于同一 native 执行"的事实链。

5. transcript 交付模式也被吞。 该模式下 transcript final 本身就是交付通道(主干只在内容完全相同时才去重),新逻辑没有接收/判断 replyDelivery,两种模式一律 suppress。

建议方向

  • 不要按文本形状猜测后继 final 的性质。主干已有"同一执行折叠了多个输入"的结构性事实:codex 路径的 supersededTurns(只有 queue 用 transcript/native turn id 证明折叠关系后,前驱的 explicit final marker 才能覆盖后继 turn);Claude/PTY 路径有 PID marker 的 steerPromotedTurn 与 predecessor→promoted 推进链(advanceAncestorSessionTurn / rememberQueuedTurnAdvanceForPendingReady),目前这条事实还没接进 bridge gate。建议把 queued turn 被推进/折叠的事实接入 gate 输入,复用"精确身份 + 同执行证明",而不是 10 分钟窗口加关键词。
  • 如果只是不希望那句自述作为后继 turn 的答案投出,更安全的语义是不要把该 turn 结算为 answered(保留重放/让用户可以重问);静默 suppress 会把"多一条噪声"升级成"答复丢失"。
  • 影响面:shouldSuppressBridgeEmit 是所有结构化 bridge CLI(Codex / TraeX / Cursor / Antigravity / Pi / Grok / Hermes / Mtr / Coco)与 Claude PTY 家族共用的投递闸门,测试需要覆盖这些路径以及 send / transcript 两种交付模式,而不是只覆盖谓词自身的 4 个例句。

再次感谢,这个问题本身值得修;期待 rebase + 换成结构事实归因后的版本。

@deepcoldy

Copy link
Copy Markdown
Owner

补充一条独立复现(复审侧探针新增,首评未覆盖):旧 dispatch attempt 的 final marker 会借给同一 turnId 的新 attempt,吞掉重试的真实短答复。

复现条件

把本 PR 的净逻辑(isBridgeSendCompletionNarration + recentPriorFinalMarkerExplainsCompletionNarration 短路)移植到当前 master 后:

marker  = { sentAtMs, sessionId: 's', turnId: 'turn-X', dispatchAttempt: 0,
            responseKind: 'final', deliveryKind: 'current_session_send' }
turn    = { markTimeMs, isLocal: false, sessionId: 's', turnId: 'turn-X',
            dispatchAttempt: 1, chatId: 'oc', rootMessageId: 'om',
            finalText: 'I used botmux to check the final result: the query returned 42 rows.' }
→ shouldSuppressBridgeEmit(turn, undefined, [marker], false) === true   // SUPPRESS

同一 turnId 的 attempt 1 是重试,它自己的答复被 attempt 0 那条已消费的 final marker 吞掉。

探针矩阵(同一份 harness,仅切换短路的开/关)

场景 本 PR 逻辑 master 现状(短路关闭)
turn{X,attempt=1} + marker{X,attempt=0} final,send 模式 SUPPRESS emit
同上,transcript 模式 SUPPRESS emit
turn{X,attempt=1} + marker{Y,attempt=0}(不同 turn)final SUPPRESS emit
turn{X,attempt=1} + marker{X}(marker 无 dispatchAttempt)final SUPPRESS emit

为什么这是 P1 而不是 P2

借用循环里排除的只有 markerMatchesExactTurn(turn, marker),而该函数要求 marker.dispatchAttempt === turn.dispatchAttempt。于是:

  • attempt 相等 → 被排除(作者预期的那一条)
  • attempt 不等 → 不排除,落进 10 分钟窗口当成「前序 final」借走

方向恰好相反于 master 的设计意图——BridgeGateInput.dispatchAttempt 被放进 exact-turn 身份,正是为了让过期重试的 marker 不能给后一次 attempt 授信(shouldSuppressStructuredFallback 的注里也写明「Keep the dispatch attempt in the identity so a stale durable retry cannot suppress a later attempt of the same logical turn」)。本 PR 用一个更宽的旁路把这条隔离绕了。

后果同样是首评 P1 的形态:emitReadyTurns 在循环开头已 journalBridgeTurnClear,suppress 后该 turn 按 answered 结算退休,用户永久收不到重试的答复。

附带确认(与首评一致)

  • 作者两个负例(长文本 / marker 11 分钟前)在移植后确实不吞;摘掉「跨 turn 借用」这段守卫后作者用例咬红——测试钉得住他写的那个行为,问题在于该行为本身。
  • 两个负例是靠长度和窗口侥幸通过,不是靠文本形状区分后继 final 的性质。

结论

纳入 P1 清单(第 4 条)。修法仍是首评的建议方向:不要按文本形状猜,改为把 queue 已经有的「同一 native 执行折叠/推进」事实(supersededTurns;Claude/PTY 的 advanceAncestorSessionTurn + steerPromotedTurn 推进链)接进 gate 输入,走精确身份归因;或退一步不把该 turn 结算为 answered,别把噪声升级成丢失。

(已在 master 工作树上完成探针后还原,未改动任何生产代码。)

xgp01 and others added 4 commits November 3, 2026 19:03
本分支基于较早的仓库快照、与主干无共同祖先。合并时除
bridge-fallback-gate 及其测试外全部取主干版本;把「发送完成自述
抑制」重新落到主干现行的精确归因结构上:

- 仅当队列用 supersededTurns 证明后继输入已折叠进同一 native 执行、
  且存在前驱 turn 的 responseKind:final 发送 marker 时,才抑制后继
  terminal 上的短发送自述;不再用关键词加时间窗口借用相邻 turn marker。
- 前置 marker 须精确匹配前驱 turn 与 dispatchAttempt、同 session/话题、
  非 terminalIndependent、replyCard 为 final,发送时间落在
  [后继 markTimeMs, nextBoundaryMs);markTimeMs 缺失的 headless turn
  不抑制。
- 自述判定收窄:不超过 180 个可见字符、含 botmux、否定句排除、
  要求显式发送邻近结构,普通提及 botmux 的短答复不匹配。

Co-Authored-By: Claude Code <[email protected]>
折叠前驱 final 已投递后,后继 terminal 上的短「已通过 botmux 发送」
自述会被抑制,但识别谓词此前会误吞两类必须送达用户的文本:
- 英文缩写否定(haven't/wasn't)以及 no/none 与中文「没」不被
  \\bnot\\b 词边界命中,否定句被当成成功自述;
- 发送失败/被拒/未送达/HTTP 4xx-5xx 告警被当成成功自述静默,
  用户看不到投递失败。

两者都改为 fail open(识别为非自述、走正常投递)。该改动只放宽
抑制方向、不新增任何吞消息面;同时补上 180 字上限的边界用例。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit 471233f into deepcoldy:master Nov 3, 2026
11 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

已合并,感谢贡献!🎉

第一版提出问题后,你按评审意见把实现从「关键词 + 时间窗口借用相邻发送记录」改成了只认队列证明的折叠前驱关系(supersededTurns + 前驱 turn/attempt 精确匹配),方向和收口都做得很到位,后续的否定句与发送失败告警 fail-open 也在这个结构上很容易补齐。

合并前补充的两点已记录在 follow-up issue #2754,均为方向安全(不会吞真实答复)、不影响当前使用的细化项:

  1. 折叠场景下「发送自述 + 顺带回答后继问题」目前会随自述一并抑制,后续需要更细地区分交接说明与后继答案;
  2. worker 重启 / journal 恢复后折叠前驱不带 dispatchAttempt,该轮抑制会退回为正常投递(只是可能多一条消息,不会丢答复)。

欢迎继续贡献。

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

🚀 Released in v3.57.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