Repository navigation
Conversation
_deliver_agent handled token/delta and hitl_required but ignored error chunks, so a stream that emitted partial text and then failed still satisfied the success path and the failed run was pushed as a completed delivery. Record the explicit error and raise before the usage/success notification, keeping the trajectory write in the finally block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1881
问题
CronDeliveryService._deliver_agent处理了token/delta与hitl_required,但没有记录显式 error chunk:于是当 stream 先输出文本、再 yield 一个
{"type": "error"}、然后正常结束迭代时,outbound非空 → 成功路径照常执行(record_turn_usage+push_session_text+ 成功通知)→ 失败的运行被当作完成投递。(本报告只限定「error 作为 chunk 返回」这一情形,不涉及生成器直接 raise。)
改动
在 chunk 分支里记录显式流错误,并在用量与成功通知之前抛错;
finally里的轨迹落库保持不变:测试
在
tests/unit/cron/test_cron_delivery.py里追加(沿用该文件既有的 cron delivery fixture 与_stream替身写法):RuntimeError("synthetic failure")、不得 push、且轨迹里仍投影了 prompt(与既有test_agent_empty_reply_does_not_push同构);pytest tests/unit/cron/test_cron_delivery.py -k "stream_error or error_only or plain_text"→ 3 passed;把 error 分支与抛错去掉后,恰好第一条失败、其余两条通过。备注
ruff check src tests与ruff format --check src tests均通过。附件投递缺失是另一个问题(#1880),按报告建议分开修。