Skip to content

fix(chat): separate Responses commentary from final answers - #2445

Merged
vastsa merged 6 commits into
vastsa:mainfrom
xuesecanmeng:fix/responses-commentary
Nov 20, 2026
Merged

vastsa merged 6 commits into
vastsa:mainfrom
xuesecanmeng:fix/responses-commentary

Conversation

@xuesecanmeng

@xuesecanmeng xuesecanmeng commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2461

Summary / 概要

同一次 Codex / Responses 响应可以先返回 commentary(进度播报),再返回 final_answer(最终答案)。修复前,运行时把两者都当作回答文本拼接:用户在正文中看到播报,点击「复制」也会把播报一起带走。子代理返回给父代理的报告和 one-shot 调用同样受影响。

本 PR 在运行时区分播报和答案。提供方明确标记为 commentary 的文本,从可识别的第一个流式片段起就显示在可折叠的过程区;最终答案仍在正文中流式显示。复制回答、读取子代理报告或获取 one-shot 结果时,只得到答案。整次调用如果只有播报,子代理和 one-shot 不会把它当作成功返回的答案。

本 PR 只修复播报分流,不调整思考摘要与原生搜索的排列顺序,也不改变活动组的标题或折叠规则。

Before / After · 实际表现

以 #2461 中的真实 Codex 会话为例:

操作 修复前 修复后
阅读回答 正文以「我查一下官方文档……」开头,两段播报之后才是答案 正文直接从「系统代理靠应用主动走代理」开始;展开过程区仍可阅读两段播报
点击「复制」 得到两段播报和最终答案 只得到最终答案

原始 Codex 会话:脱敏摘录和修复前截图

以下三项来自同一次响应。已省略消息 ID,最终答案仅保留开头。

{
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "phase": "commentary",
      "content": [
        { "type": "output_text", "text": "我查一下官方文档,确认两种模式各自接管哪些流量,以及什么时候需要开虚拟网卡。" }
      ]
    },
    {
      "type": "message",
      "role": "assistant",
      "phase": "commentary",
      "content": [
        { "type": "output_text", "text": "系统代理依赖应用主动使用设置。我再核对 TUN 的路由行为,区分「接管流量」和「让流量走代理节点」。" }
      ]
    },
    {
      "type": "message",
      "role": "assistant",
      "phase": "final_answer",
      "content": [
        { "type": "output_text", "text": "**系统代理靠应用主动走代理;虚拟网卡模式(TUN)靠系统路由把流量交给代理客户端。** 所以 TUN 能覆盖更多应用。" }
      ]
    }
  ]
}
修复前:两条进度播报出现在最终答案前的正文区域

实现与兼容性

  • 答案提取:assistantContent() 不再把明确标记为 commentary 的文本拼入答案。子代理报告、one-shot 返回值和回合完成判定共用这一规则,不依赖渲染器事后过滤。没有阶段标记的普通文本仍按原有方式处理,不根据措辞猜测。
  • 历史与回放:可回放的签名记录仍由 content 保存原文、providerReplay 保存块长度和签名。重开旧会话时,只在阶段标记明确且文本长度匹配时分流;信息不足则维持原有显示。不新增 UiMessage 字段或 Host 持久化字段,也不需要数据库迁移。
  • 流式性能:文本块边界变化时更新阶段信息;同一块内的连续追加仍走原有 delta 快速路径,不逐帧传输阶段表,也不强制完整序列化。
  • 上游补丁:已在包含 fix(runtime): explicitly disable Responses strict mode when unsupported #2454 的上游基线上重新生成 pi-ai 补丁和锁文件,保留了对不支持严格模式的模型显式发送 strict: false 的行为。

Verification / 验证

以下检查已在提交 7153d88e0 上通过:

  • 构建与回归:生产构建、类型检查、lint 和补丁检查通过;577 项相关测试通过(运行时 520 项、桌面端 44 项、共享消息流 13 项)。其中覆盖了子代理和 one-shot 的两种情况:先播报再回答时只返回答案,只有播报时沿用原有的无答案处理。
  • Windows 隔离 Electron:node scripts/e2e-transcript-render.mjs 验证了流式播报只出现在过程区;回合完成和重开会话后,实际点击「复制」均只写出最终答案。无阶段标记的历史文本仍完整显示和复制。
  • Responses 工具调用:使用本地模拟 provider 验证了切换模型后的工具调用,strict: false 保持生效,Host 工具只执行一次。

Keep provider-labelled progress inside the turn process while streaming
and after reopening a session. Preserve the original assistant content
and provider replay so context and stored transcripts do not change.
Record block positions before flattening a Responses message so searches
and reasoning stay in order as text streams and when a session reopens.

Keep the layout separate from model replay. Older transcripts still use
known commentary phases without guessing missing positions.
Validate the transcript changes against the current PR base without
rewriting the published fix branch.
@vastsa

vastsa commented Nov 20, 2026

Copy link
Copy Markdown
Owner

commentary 混入正文的现象在 main 上成立(assistantContent() 不区分 phase 拼接所有 text 块),但本 PR 目前不满足落地条件:

  1. 一次合并了两个独立问题(commentary 分流 + 思考/搜索交错顺序),后者缺少真实复现。
  2. 引入新的持久化字段(host-core record meta responseLayout)和跨进程契约字段(UiMessage.commentaryRanges / responseLayout),并修改 ADR,超出最小修复范围。
  3. commentary 仍保存在 content 中,仅在会话渲染和复制路径剥离;子代理结果(subagent.ts:844/866/905 调用 assistantContent() 不传 api)、one-shot-complete.ts:193、runtime.ts:1184 等其他消费方仍包含播报。
  4. deltaStreamPayloadFits 对带 layout/ranges 的 delta 全部退回完整序列化,对 Responses 流式有性能回退。

另外 #2454 已合入并修改了 patches/@[email protected] 与 pnpm-lock.yaml,本分支需要基于最新 main 重新生成补丁。

建议拆分:只针对 commentary 分流提交最小修复并关联 issue;持久化或契约层面的改动需维护者先确认方向。

@xuesecanmeng

Copy link
Copy Markdown
Contributor Author

收到,我会把 #2445 收窄为 commentary 分流的最小修复。
思考与搜索的排序及相关持久化改动会从本 PR 移出,另用 issue 跟踪。

Keep signed progress available for transcript replay without treating it
as an answer in Copy, subagent reports, or one-shot completions.
Limit the fix to phase separation rather than storing response order.
Keep the published branch history intact while validating commentary
separation against the current runtime and transcript changes.
@xuesecanmeng

Copy link
Copy Markdown
Contributor Author

已按建议收窄并推送,当前提交为 7153d88,正文已关联 #2461。思考与搜索排序已移出;子代理、one-shot 和流式快速路径都补了回归,未新增持久化字段。辛苦再看一下。 @vastsa

Two consumers still read the stored content, which keeps the signed
commentary for replay: the live session result reported to voice
callers, and the radial menu's Copy latest answer. Both now take the
answer only.

The split moves into a shared splitResponsesCommentary helper so the
renderer projection and Electron main use one rule instead of two
copies of the replay-length walk.

refs vastsa#2461
@vastsa

vastsa commented Nov 20, 2026

Copy link
Copy Markdown
Owner

复审完成,方向和运行时部分没问题:子代理、one-shot、流式首块分流和 pi-ai 补丁都已验证,没有新增持久化字段或契约字段。

我直接在分支上补了最后两处泄漏(3cf4c6935):

  1. live-session-events.ts:Live 会话上报的 resultText 取自原始 content,会带上 commentary。现在只取答案。
  2. ChatTranscript.tsx:径向菜单的「复制最新回答」原来直接复制 message.content,现在改为走 projectAssistantCommentary。

同时把按 replay 长度切分的逻辑收进 shared 的 splitResponsesCommentary。渲染层投影和 Electron 主进程共用这一份规则,不再各写一遍。新增两项回归测试:responses-message-phase.test.ts、live-session-commentary.test.mjs,后者在旧代码上会失败。

还有一点麻烦补进 PR 描述:isProgressOnlyAssistantTurn 有两处行为变化——纯 commentary 回合会触发 progress rerun;带 final_answer 时不再走措辞启发式。

CI 通过后合入。

@vastsa
vastsa merged commit 211b582 into vastsa:main Nov 20, 2026
6 checks passed
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] Codex / Responses 的进度播报混入最终答案和复制结果

2 participants