fix(agui): defer RunErrorEvent emission to prevent premature disconnect - #292
Closed
weimch wants to merge 1 commit into
Closed
fix(agui): defer RunErrorEvent emission to prevent premature disconnect#292weimch wants to merge 1 commit into
weimch wants to merge 1 commit into
Conversation
…premature disconnect - EventTranslator: replace immediate RunErrorEvent with CustomEvent(name='trpc_error') on error events mid-stream - AGUI agent: track last_event_is_error in _run_trpc_in_background loop, emit RunErrorEvent only when run ends with error as last event - This prevents premature connection close when sub-agents (GraphAgent, ChainAgent, etc.) yield error events but continue executing Fixes #TAPD-1020419452137024294
Contributor
AI Code Review现在我已经全面了解了上下文。让我来汇总一下审查结果。 发现的问题
|
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.
问题
PCG-应用宝 pcerypeng 反馈:使用 GrafAgent + AGUI 服务部署时,如果增加一个 AgentNode,该 AgentNode 返回一个带 error 的 Event,客户端与服务的连接会被断开,但此时 Agent 并没有结束,仍在持续执行。
根因
EventTranslator 在遇到
is_error() and not function_responses的 Event 时,立即翻译为 RunErrorEvent。根据 AG-UI 协议规范,RunErrorEvent 是终止事件,合规客户端收到后会关闭连接。但服务端 SSE stream 实际保持开着——Translator 是 per-event 调用的,return只结束单个 event 的翻译,外层循环继续消费后续事件。核心矛盾:AgentNode 级别的可恢复错误与真正的致命系统错误在 Translator 层无法区分,都满足
is_error() and not function_responses。修复方案(方案 D:延迟决策到 run 结束)
不在 error Event 出现时立即发 RunErrorEvent,等 run 结束后检查最后一个 Event 是否为 error,再决定发 RunErrorEvent 还是 RunFinishedEvent。
改动点
_event_translator.py:error Event 改为发CustomEvent(name="trpc_error", value={code, message}),不再发 RunErrorEvent,移除return让翻译继续_agui_agent.py:在_run_trpc_in_background的run_async循环中跟踪last_event_is_error;循环结束后如果为 True,发 RunErrorEvent(用最后一个 event 的 error_code/error_message)正确性
最后一个 event 是否为 error 完美捕捉了 run 是否因错误终止的运行时状态:
测试
关联