Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves provider streaming failure handling by classifying auth- and stream-related failures without changing the provider event contract, ensuring turns fail deterministically (rather than returning partial/placeholder output) and preserving cancellation semantics when errors occur after cancellation.
Changes:
- Add
ProviderStreamFailureClassifierto (a) detect expiredAuthStatusand (b) classify terminal"failed"provider events / exceptions intoProviderFailureKind. - Update OpenAI MEAI + Anthropic SDK stream adapters to emit stable
"failed"terminal events for malformed SSE/parser/transport errors while re-checking cancellation before synthesizing failure events. - Update runtime/provider execution flow to treat expired preflight auth as unavailable and to convert terminal provider
"failed"events into turn-failingProviderExecutionExceptions; add/extend unit + integration coverage.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/SharpClaw.Code.UnitTests/Providers/ProviderStreamAdapterTests.cs | Adds unit coverage for malformed SSE → "failed" event and for cancellation preservation; validates classifier status-code reflection behavior. |
| tests/SharpClaw.Code.IntegrationTests/Runtime/ProviderRuntimeEventFlowTests.cs | Adds integration coverage for expired preflight auth failing early and streamed auth failure events failing the turn. |
| src/SharpClaw.Code.Providers/OpenAiCompatibleProvider.cs | Throws early on pre-canceled tokens before starting the stream. |
| src/SharpClaw.Code.Providers/Models/ProviderStreamFailureClassifier.cs | New classifier for expiry/auth failure detection and stable exception-to-failed-content formatting. |
| src/SharpClaw.Code.Providers/Internal/OpenAiMeaiStreamAdapter.cs | Uses classifier-based error descriptions and re-checks cancellation before emitting synthetic "failed" events. |
| src/SharpClaw.Code.Providers/Internal/AnthropicSdkStreamAdapter.cs | Same as above for Anthropic SDK streaming events. |
| src/SharpClaw.Code.Providers/AnthropicProvider.cs | Adds early cancellation check and maps auth failures during stream start to ProviderExecutionException(AuthenticationUnavailable). |
| src/SharpClaw.Code.Agents/Internal/ProviderBackedAgentKernel.cs | Treats expired auth as unavailable and converts terminal provider "failed" events into classified ProviderExecutionExceptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+88
to
+94
| logger.LogInformation("Started Anthropic SDK stream for request {RequestId}.", request.Id); | ||
|
|
||
| var stream = client.Messages.CreateStreaming(parameters, cancellationToken); | ||
| return new ProviderStreamHandle(request, AnthropicSdkStreamAdapter.AdaptAsync(stream, request.Id, systemClock, cancellationToken)); | ||
| IAsyncEnumerable<RawMessageStreamEvent> stream; | ||
| try | ||
| { | ||
| stream = client.Messages.CreateStreaming(parameters, cancellationToken); | ||
| } |
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.
Summary
failedevents into classified turn failures, including auth failures during streaming.Root Cause
Provider auth preflight trusted
AuthStatus.IsAuthenticatedwithout consideringExpiresAtUtc, and the runtime collected terminal providerfailedevents without failing the turn. Streaming adapter exceptions also needed to re-check cancellation before emitting a synthetic failed provider event.Runtime Impact
Expired auth before stream now fails as
AuthenticationUnavailablebefore provider resolution or stream start. Expired or invalid auth during a stream now fails the turn instead of returning partial text or placeholder output. Malformed SSE/parser failures keep using the stable terminalfailedevent shape and are surfaced as provider stream failures.Validation
dotnet test SharpClawCode.sln