Repository navigation
fix(ai): retry Cohere streams that end early - #61184
Merged
Merged
Conversation
There was a problem hiding this comment.
The change looks good. Removing Cohere's own onHalt lets the shared requireTerminalEvent check handle cut-off streams. Cohere's message-end step already emits finish through Lifecycle.finish, so complete streams still pass. Streams cut off before that now fail with the incomplete-stream error, which can be retried, the same as other providers.
I reproduced the problem on the base: the updated test fails there with the old error, which can't be retried. With this change it passes. The full packages/ai suite passes (2058 tests, 0 fail), and so does typecheck:tsc.
Public API: unchanged.
No concerns.
14 tasks
1 task
This was referenced Nov 7, 2026
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.
Problem
When a Cohere stream got cut off before
message-end, the step just failed. Every other provider retries in that case.Cohere had its own end-of-stream check that ran before the shared one and failed with a plain "Cohere stream ended without message-end" error. That error has no
incomplete-streamclassification, soAIError.isRetryablereturned false.Change
I removed Cohere's
onHalt. Cohere'smessage-endstep already emits afinishevent, so the shared client check passes for complete streams and gives cut-off streams the same retryable error as everyone else.I kept the
finishedstate field even though nothing reads it now, because it shows up in the exportedCohereChat.protocoltype. The emitted.d.tsis identical before and after.Verification
bun run testinpackages/ai(includes recorded fixtures): 2030 pass, 0 failbun typecheckandbun run typecheck:tscinpackages/aitsc -p tsconfig.build.json --emitDeclarationOnlybefore and after: no diffbun run checkfrom the root