-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: handle empty stream responses from GLM models #8483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add graceful handling for empty API responses in Task.ts - Implement GLM-specific fallback responses in OpenAI and base providers - Add retry logic for GLM models when empty streams occur - Add comprehensive tests for empty stream scenarios Fixes #8482
) { | ||
yield { | ||
type: "text", | ||
text: "I'm having trouble generating a response. Please try rephrasing your request or breaking it down into smaller steps.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GLM fallback response here is hardcoded. To ensure consistency and proper localization, consider wrapping this error message in a translation function.
text: "I'm having trouble generating a response. Please try rephrasing your request or breaking it down into smaller steps.", | |
text: t("I'm having trouble generating a response. Please try rephrasing your request or breaking it down into smaller steps."), |
This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.
const isGLMModel = | ||
modelId && (modelId.toLowerCase().includes("glm") || modelId.toLowerCase().includes("chatglm")) | ||
|
||
if (isGLMModel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the GLM-specific branch handling empty responses (around lines 2349–2365), fallback messages and prompts are hardcoded. Consider using a translation function (e.g. t('...')) and possibly refactoring the duplicated GLM check into a helper for clarity.
This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performing self-review: a robot grading its own homework—what could possibly be biased?
const isGLMModel = | ||
modelId && (modelId.toLowerCase().includes("glm") || modelId.toLowerCase().includes("chatglm")) | ||
|
||
if (isGLMModel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Potential infinite retry loop for GLM empty streams. This path pushes a clarification and immediately retries with no max attempts or backoff. If the provider keeps returning empty streams, this can loop indefinitely and spam error messages. Recommend adding a capped retry counter (e.g., 1–3 attempts) with small delay and logging, and falling back to the standard error after the cap. Also consider adding unit tests that simulate repeated empty responses to verify the retry cap and final behavior.
} | ||
|
||
// For GLM models that may return empty streams, provide a fallback response | ||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Duplicate GLM detection logic. The same modelId.includes('glm'|'chatglm') condition appears here, in BaseOpenAiCompatibleProvider, and in Task.ts. Consider extracting a small helper (e.g., isGlmModel(modelId)) to keep behavior consistent and reduce drift.
@@ -0,0 +1,193 @@ | |||
import { describe, it, expect, vi, beforeEach } from "vitest" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] Unused import 'beforeEach' may trip stricter lint settings; suggest removing it.
import { describe, it, expect, vi, beforeEach } from "vitest" | |
import { describe, it, expect, vi } from "vitest" |
Summary
This PR addresses Issue #8482 where GLM-4.6 models occasionally return empty streams, causing "Unexpected API Response" errors in Roo Code.
Problem
Users experiencing intermittent failures when using GLM-4.6 with both OpenAI Compatible and Z AI providers. The error occurs when the model returns an empty stream with no text content, causing the application to fail with an unhelpful error message.
Solution
Implemented a three-layer approach to handle empty streams gracefully:
Changes
Testing
Impact
Fixes #8482
Important
Fixes handling of empty stream responses from GLM models by adding fallback responses and retry logic, improving error handling and user experience.
Task.ts
by retrying with clarification prompts.OpenAiHandler
andBaseOpenAiCompatibleProvider
.glm-empty-stream.spec.ts
with 4 test cases for GLM and non-GLM models.This description was created by
for 8663724. You can customize this summary. It will automatically update as commits are pushed.