fix(ai): map Z.AI's model_context_window_exceeded finish to length (#66646)

This commit is contained in:
Aiden Cline 2026-11-26 11:47:32 -06:00 • committed by GitHub
parent ac2263f34c
commit 3a2e427d0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -950,6 +950,8 @@ const mapFinishReason = Effect.fnUntraced(function* (event: OpenAIChatEvent, rea
case "end":
return "stop" as const
case "length":
// Z.AI stops with this when the prompt plus the generated output fill the context window.
case "model_context_window_exceeded":
return "length" as const
case "content_filter":
// Z.AI ends a response its safety review blocked with "sensitive".

View file

@ -647,6 +647,16 @@ describe("OpenAI-compatible Chat route", () => {
}),
)
it.effect("maps Z.AI's model_context_window_exceeded finish to a length finish", () =>
Effect.gen(function* () {
const response = yield* LLMClient.generate(request).pipe(
Effect.provide(fixedResponse(sseEvents(deltaChunk({}, "model_context_window_exceeded")))),
)
expect(response.finishReason).toEqual({ normalized: "length", raw: "model_context_window_exceeded" })
}),
)
it.effect("preserves content-filter finishes in the common reason algebra", () =>
Effect.gen(function* () {
const filtered = yield* LLMClient.generate(request).pipe(