Commit 756ed34
Fix: Propagate native errors from ExecuteCommandWithCallbackAsync in ChatClient streaming path (#466)
Fixes the bug where `ChatClient` streaming was not checking the
`Response.Error` field returned by `ExecuteCommandWithCallbackAsync`.
When the native layer reported an error without invoking any callbacks,
the streaming method would silently complete with an empty stream
instead of propagating the error to the caller.
The equivalent fix for `AudioClient` was merged separately via PR #471.
## Changes Made
- **`ChatClient.cs`**: Capture the return value of
`ExecuteCommandWithCallbackAsync` and, when it carries an error (and no
callback has already failed), complete the channel with a
`FoundryLocalException` so the error propagates to the consumer's `await
foreach` loop. Added an internal constructor accepting `ICoreInterop`
and `ILogger` for dependency injection in unit tests.
- **`ChatClientStreamingErrorTests.cs`**: Unit tests verifying that
native-layer errors reported via `Response.Error` are propagated as
`FoundryLocalException` to callers, and that a successful (no-error)
response completes the stream normally.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>ExecuteCommandWithCallbackAsync response not
checked</issue_title>
> <issue_description>ExecuteCommandWithCallbackAsync returns a Response
whose .Error field may contain an error from the native layer (e.g.
missing audio file, invalid model, etc.). Both AudioClient and
ChatClient streaming paths are ignoring this return value, so when the
native side reported an error without invoking any callbacks the channel
was completed successfully and the caller observed an empty stream
instead of an exception.
>
> Capture the Response and, when it carries an error, complete the
channel with a FoundryLocalException so the error propagates to the
consumer's `await foreach` loop.</issue_description>
>
> <agent_instructions>Add necessary unit tests.</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #465
<!-- START COPILOT CODING AGENT TIPS -->
---
🔒 GitHub Advanced Security automatically protects Copilot coding agent
pull requests. You can protect all pull requests by enabling Advanced
Security for your repositories. [Learn more about Advanced
Security.](https://gh.io/cca-advanced-security)
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: baijumeswani <12852605+baijumeswani@users.noreply.github.com>
Co-authored-by: Baiju Meswani <baijumeswani@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Baiju Meswani <bmeswani@microsoft.com>1 parent 1d3ef47 commit 756ed34
1 file changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
199 | 210 | | |
200 | 211 | | |
201 | 212 | | |
| |||
0 commit comments