fix(ai): classify missing chat finish reasons as incomplete (#44864)

This commit is contained in:
Aiden Cline 2026-08-24 22:37:47 -05:00 committed by GitHub
parent d0252f7179
commit 895eff09b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import { HttpTransport } from "../route/transport/index.js"
import { Protocol } from "../route/protocol.js"
import {
AIError,
InvalidProviderOutputReason,
LLMEvent,
ProviderInternalReason,
UnknownProviderReason,
@ -1046,7 +1047,15 @@ const step = (state: ParserState, event: OpenAIChatEvent) =>
const finishEvents = Effect.fn("OpenAIChat.finishEvents")(function* (state: ParserState) {
if (state.finishReason === undefined && state.requireFinishReason)
return yield* ProviderShared.eventError(ADAPTER, "OpenAI Chat stream ended without finish_reason")
return yield* new AIError({
module: ADAPTER,
method: "stream",
reason: new InvalidProviderOutputReason({
classification: "incomplete-stream",
message: "OpenAI Chat stream ended without finish_reason",
route: ADAPTER,
}),
})
const events: LLMEvent[] = []
const toolCallEvents =
state.finishReason === undefined && Object.keys(state.tools).length > 0

View file

@ -362,6 +362,7 @@ describe("OpenAI-compatible Chat route", () => {
expect(error.reason).toMatchObject({
_tag: "InvalidProviderOutput",
classification: "incomplete-stream",
message: "OpenAI Chat stream ended without finish_reason",
})
}),