microsoft / microsoft/agent-framework
.NET: [Bug]: MapAGUI emits no RUN_ERROR when agent stream throws after SSE starts
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 2.3k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 358
Description
### Description
MapAGUI(...) does not reliably emit native AG-UI `RUN_ERROR` when an exception happens during agent streaming after SSE response has already started.
**What happens**
- agent stream throws during RunStreamingAsync(...) / AG-UI event conversion
- AGUIServerSentEventsResult logs An error occurred while streaming AG-UI events
- then it tries to send RunErrorEvent
- but this is too late because SseFormatter.WriteAsync(...) has already failed / stream is already broken
- client receives no AG-UI error event, often only generic “no AG-UI events received”
**Expected**
If exception happens while enumerating AG-UI events, server should emit native:
- RUN_ERROR { message, code }
and stop stream
- no RUN_FINISHED after error
**Why**
Current catch is in AGUIServerSentEventsResult.ExecuteAsync(), outside SseFormatter.WriteAsync(...).
That makes RUN_ERROR best-effort only after writer failure.
**Likely fix**
Catch non-cancellation exceptions inside AG-UI event enumeration path, before SSE writer fails:
- ideally in/around AsAGUIEventStreamAsync(...)
- emit RUN_ERROR
- then end enumeration
Related
- #2270
- #5209
- #3790
Relevant code
- Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIServerSentEventsResult.cs
- Microsoft.Agents.AI.AGUI/Shared/ChatResponseUpdateAGUIExtensions.cs
### Code Sample
```markdown
```
### Error Messages / Stack Traces
```markdown
```
### Package Versions
Microsoft.Agents.AI 1.1.0, Microsoft.Agents.AI.Hosting 1.1.0-preview.260410.1, Microsoft.Agents.AI.Hosting.AGUI.AspNetCore 1.1.0-preview.260410.1, Microsoft.Extensions.AI.OpenAI 10.4.1
### .NET Version
.NET 10
### Additional Context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.