Skip to content

fix(streaming): keep reasoning out of final text snapshot#302

Merged
liujuanjuan1984 merged 1 commit intomainfrom
eval/issue-300
Mar 23, 2026
Merged

fix(streaming): keep reasoning out of final text snapshot#302
liujuanjuan1984 merged 1 commit intomainfrom
eval/issue-300

Conversation

@liujuanjuan1984
Copy link
Collaborator

背景

修复 #300:streaming 完成后,final_snapshot 可能把原本只应属于 reasoning lane 的内容再次落到 text lane,导致刷新后出现重复正文。

本次改动

src/opencode_a2a/parts/text.py

  • 收紧 extract_text_from_parts() 的语义
  • final assistant text 只提取 canonical text parts
  • 不再把 reasoning parts 拼入最终文本

tests/parts/test_parts_text.py

  • 更新文本提取语义断言
  • 新 contract 改为明确忽略 reasoning parts

tests/upstream/test_opencode_upstream_client_params.py

  • 增加 upstream send_message() 回归测试
  • 覆盖响应 parts 同时包含 reasoning + text 时,只返回 final text 的场景

tests/execution/test_streaming_output_contract_core.py

  • 增加 streaming 收尾回归测试
  • 覆盖 stream 中已有 reasoning,最终 response payload 同时含 reasoning + text 时,final_snapshot 不重复 reasoning 内容

验证

  • uv run pre-commit run --all-files
  • uv run pytest
  • 350 passed
  • coverage: 91.08%

关联

Closes #300

@liujuanjuan1984
Copy link
Collaborator Author

本轮 PR 审查结论:

  1. 未发现阻塞问题。
  2. 改动范围合理,直接命中了 #300 的本地放大点:final assistant text 提取会把 reasoning 混入 text,随后 streaming 收尾再把这段污染后的文本补发成 final_snapshot
  3. 当前实现是稳健的:
    • 没有去改 streaming event contract 本身
    • 只收紧 final text 的 canonical 提取语义
    • upstream 提取层和 execution 收尾层都通过回归测试锁住了
  4. Closes #300 是准确的;当前没有必须补充的 Relates to

非阻塞说明:

  • jsonrpc/methods.py 也复用了同一个 extract_text_from_parts(),因此 message query 返回的 text 现在同样不会再混入 reasoning。这个变化与本次修复方向一致,我判断是正确收敛,不是额外风险。

@liujuanjuan1984
Copy link
Collaborator Author

第二轮 reviewer 审查结论:未发现新的阻塞问题。

需要明确的非阻塞边界:

  1. 这是一次有意的语义收紧,不是纯内部重构。

    • 现在 final assistant text / message query text 只代表 canonical text lane。
    • 如果上游某条消息只有 reasoning、没有 text,对应的 response.text / query text 现在会变为空,而不会再回退成 reasoning 内容。
    • 我判断这和 #300 想要的 contract 更一致,但它确实是一个需要认知到的行为边界变化。
  2. 当前测试已经覆盖了“reasoning + text 混合时不串 lane”,但没有额外覆盖“只有 reasoning、完全没有 text”的历史查询语义。

    • 我不认为这阻塞当前修复,因为那属于另一条产品语义选择。
    • 但如果后续下游对“纯 reasoning 消息的 query 表现”有要求,可以再单独补 contract test。

@liujuanjuan1984 liujuanjuan1984 marked this pull request as ready for review March 23, 2026 13:28
@liujuanjuan1984 liujuanjuan1984 merged commit b58a57e into main Mar 23, 2026
3 checks passed
@liujuanjuan1984 liujuanjuan1984 deleted the eval/issue-300 branch March 23, 2026 13:28
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] streaming 完成后 final_snapshot 混入 reasoning 内容,导致刷新后重复 text 消息

1 participant