Classify empty provider streams as retryable#183
Merged
Conversation
Bedrock intermittently terminates ConverseStream responses without ever starting an assistant message when a model emits an empty completion (observed in production on Haiku 4.5 as messageStop with no prior messageStart and zero output tokens). The strict stream state machine correctly rejects the shape but surfaced it as an opaque protocol error that retry middleware could not detect. Introduce model.ErrEmptyStream plus model.NewEmptyStreamError, which pair the sentinel with a retryable unavailable ProviderError (code empty_stream). The Bedrock and Anthropic adapters classify message stop without an active message and event streams that close before message start through it, and classify streams that close mid-message as retryable truncated_stream provider errors. Duplicate message stops stay hard protocol errors. Adapters still never fabricate responses; retry policy remains with the integrating application.
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
model.ErrEmptyStream+model.NewEmptyStreamError, pairing a detection sentinel with a retryableunavailableProviderError (codeempty_stream).truncated_streamprovider errors; duplicate message stops remain hard protocol errors.Rationale
Bedrock intermittently terminates ConverseStream responses without ever emitting
messageStartwhen the model produces an empty completion (observed in production on Haiku 4.5:messageStopfirst, zero output tokens, reproducible per transcript). The strict state machine introduced in v0.62 correctly rejects the shape, but callers could not distinguish it from a corrupted stream, so retry middleware had nothing to key on. Adapters still never fabricate a response; retry policy stays with the integrating application.Test evidence
make lint: 0 issues.make test: full suite green.streamEndedEarlyErrortable test,NewEmptyStreamErrorcontract test.