Skip to content

fix(ai): retry Cohere streams that end early - #61184

Merged
rekram1-node merged 1 commit into
devfrom
cohere-incomplete-retry
Nov 2, 2026
Merged

rekram1-node merged 1 commit into
devfrom
cohere-incomplete-retry

Conversation

@rekram1-node

Copy link
Copy Markdown
Contributor

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-stream classification, so AIError.isRetryable returned false.

 stream ends without a finish event
-  cohere onHalt -> "Cohere stream ended without message-end"   (not retryable)
+  shared requireTerminalEvent -> "The provider response ended unexpectedly."
+                                 classification: incomplete-stream (retryable)

Change

I removed Cohere's onHalt. Cohere's message-end step already emits a finish event, so the shared client check passes for complete streams and gives cut-off streams the same retryable error as everyone else.

I kept the finished state field even though nothing reads it now, because it shows up in the exported CohereChat.protocol type. The emitted .d.ts is identical before and after.

Verification

  • bun run test in packages/ai (includes recorded fixtures): 2030 pass, 0 fail
  • bun typecheck and bun run typecheck:tsc in packages/ai
  • tsc -p tsconfig.build.json --emitDeclarationOnly before and after: no diff
  • bun run check from the root

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rekram1-node
rekram1-node merged commit 3f3ee9e into dev Nov 2, 2026
21 checks passed
@rekram1-node
rekram1-node deleted the cohere-incomplete-retry branch November 2, 2026 04:02
@amrkmn amrkmn mentioned this pull request Nov 7, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant