Skip to content

fix(messaging): final-only delivery for WeChat interim block text (#292) - #294

Open
desmondc9 wants to merge 1 commit into
Tencent:mainfrom
desmondc9:fix/292-interim-text-duplicate
Open

desmondc9 wants to merge 1 commit into
Tencent:mainfrom
desmondc9:fix/292-interim-text-duplicate

Conversation

@desmondc9

Copy link
Copy Markdown

问题摘要

Issue #292:agent 在工具调用之间产出的中间文本(旁白/commentary)被逐条直发到微信,且同一段文本随后又并入最终回复重发。微信不能编辑消息,用户收到重复消息(实测 A / B / A(重复) / 8 两起同构)。

根因

  1. 插件已向 dispatchReplyFromConfigdisableBlockStreaming: true,但工具调用之间的块级旁白(block)仍从宿主直达插件的 deliver 回调并外发;
  2. 宿主最终 payload 去重(directlySentBlockKeys / sentFinalPayloadDedupeKeys)只登记 terminal 内容、排除 commentary,因此最终回复再把相同文本重发一遍 —— 重复源自宿主,按 issue 约定本 PR 不改宿主

修复策略(插件侧,final-only 交付)

微信是不可编辑消息的通道,故对中间块文本采用 final-only 交付:在插件的 deliver 路径识别并跳过「非最终、纯文本」的 block payload,只保留会被并入最终回复的前置内容,避免同文双发。

  • 新增 src/messaging/interim-reply-policy.ts:纯函数 isInterimTextOnlyWeixinReply(payload, info),仅在交付种类为 block、且为纯文本时判定应跳过。
  • src/messaging/process-message.tsdeliver 回调读取宿主导入的第二个参数 { kind },对判定命中的 payload 提前返回(debug 日志记录)。
  • 严格不误伤:final(含合法的多条 final)、携带媒体(mediaUrl/mediaUrls)、isError、审批(channelData.execApproval)、tool 摘要、以及 kind 未知(防御旧宿主)一律照常发送。

测试说明

新增 src/messaging/interim-reply-policy.test.ts(9 例,vitest,co-located):

  • 跳过 block 纯文本(旁白)✔
  • 保留 final / 多条 final ✔
  • 保留媒体 block / tool ✔
  • 保留审批(execApproval)block ✔
  • 保留 isError ✔
  • 保留 tool 摘要(tool 输出不会并入最终回复,删除会造成内容丢失)✔
  • kind 未知(防御)与空/仅媒体 payload 保留 ✔

本地验证

npm run ci 全绿:oxfmt format:check + oxlint + tsc typecheck + vitest(28 文件 / 412 用例)+ build。oxlint 仅有既存告警(如 process-message.ts:508,位于基线未改动行),与本次改动无关。

Fixes #292

…only delivery

WeChat cannot edit or retract a sent message. Block-streamed commentary
between tool calls and other interim text payloads were sent verbatim and
then merged into the final reply again, so users received the same content
twice. Skip interim (tool/block) text-only payloads at the deliver seam,
keeping media, errors, approval prompts, and all final payloads.

Fixes Tencent#292
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.

[bug] 工具间中间文本被直发并随最终回复重复发送(微信用户收到重复消息,去重键未登记 commentary)

1 participant