Skip to content

[Priority: Med] [Review] 审查 streaming completed 是否需要补最终 status.message #455

@liujuanjuan1984

Description

@liujuanjuan1984

🔍 发现的问题 / 原始需求描述

  • 审查结论:需求仍然值得审查,但核心问题需要进一步说清楚。当前主干的 streaming 路径已经不是“只有 chunks、没有最终结果”:src/opencode_a2a/execution/coordinator.py 会在 completed 前补 final text snapshot artifact,src/opencode_a2a/output_modes.py 也会把 stream artifacts 规范化并持久化到 terminal task。
  • 因此,这个议题真正要审查的不是“是否补一条 completed status.message”,而是:当 A2A 下游在流式过程中只收到增量 chunks、出现中途断流、只订阅到后半段、或只在终态读取任务结果时,协议/实现是否应保证一个可直接消费的完整结果快照;如果需要,这个快照是否应落在 status.message,还是 artifact 已经足够。
  • 需要结合 A2A 生态进一步判断:当前 artifact-first 的 terminal 表达是否已经符合上游协议倾向,还是仍有必要为只消费 terminal status 的客户端补充一个更直接的完整文本入口。

🛠️ 详细实施方案

  • 先做 characterization tests,确认当前行为下:
    1. streaming terminal task 通过 artifact 已可重建最终文本;
    2. GetTask / terminal replay 是否已经能够覆盖“chunks 不完整”风险。
  • 在此基础上,再评估是否需要额外合成一个完整结果快照入口。若决定实现,不应预设 status.message 是唯一答案;必须先比较以下几种边界是否更符合当前 A2A 契约语义:
    • 保持 artifact-first,不新增 status.message
    • 仅在存在唯一 canonical final text artifact 时补 status.message
    • 通过更明确的 terminal task snapshot/聚合规则解决,而不是引入新的输出冗余
  • 需要联动检查 src/opencode_a2a/execution/coordinator.pysrc/opencode_a2a/output_modes.pysrc/opencode_a2a/server/application.py,确保 terminal event、持久化结果、GetTask/SubscribeToTask 返回面保持一致。
  • 核心逻辑/伪代码:
final_snapshot = resolve_terminal_result_snapshot(task)
if final_snapshot is already reliably reconstructable from artifacts:
    keep artifact-first contract
elif unique_final_text_artifact exists and ecosystem expects direct terminal text:
    consider deriving status.message from that artifact
else:
    avoid adding a second ambiguous final-result channel
  • 涉及文件:src/opencode_a2a/execution/coordinator.pysrc/opencode_a2a/output_modes.pysrc/opencode_a2a/server/application.pytests/execution/test_streaming_output_contract_core.pytests/server/test_output_negotiation.py

🧪 回归测试建议

  • 增加 streaming 终态场景测试,覆盖:仅 text artifact、text + tool_call、多 message_id、structured-only 输出、无 upstream message_id fallback、终态只通过 GetTask 读取结果。
  • 校验 GetTask 与重新 SubscribeToTask 时,最终文本不会重复、不会丢失、也不会错误拼接 reasoning/tool_call 内容。
  • 如果后续决定补 status.message,必须额外验证不会与现有 artifact replay / output negotiation 形成双份文本或语义漂移。
  • 执行 bash ./scripts/doctor.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:todoPlanned but not started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions