Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 30, 2026

This PR attempts to address Issue #11071.

Related GitHub Issue

Addresses: #11071 (comment by @mark-ucalgary)

Description

According to the Z.ai documentation for GLM-4.6 and GLM-4.6V, both models support thinking mode. However, the current codebase only defines thinking support for GLM-4.7.

This PR adds thinking mode support for GLM-4.6 and GLM-4.6V models across:

  1. Model type definitions
  2. GLM detection logic
  3. Z.ai provider implementation
  4. Test coverage

Changes Made

1. Model Definitions (packages/types/src/providers/zai.ts)

  • Added supportsReasoningEffort: ["disable", "medium"] to GLM-4.6 (international and mainland)
  • Added supportsReasoningEffort: ["disable", "medium"] to GLM-4.6V (international and mainland)
  • Added reasoningEffort: "medium" and preserveReasoning: true to both models

2. GLM Detection (src/api/providers/utils/glm-model-detection.ts)

  • Updated supportsThinking detection to include GLM-4.6 base model
  • Updated to include GLM-4.6V and its variants (v-flash, v-flashx)
  • Now detects: GLM-4.6, GLM-4.6V, GLM-4.6V-Flash, GLM-4.6V-FlashX, and GLM-4.7 variants

3. Z.ai Provider (src/api/providers/zai.ts)

  • Updated comments to reflect support for GLM-4.6, GLM-4.6V, and GLM-4.7
  • Changed detection from checking specific model ID to checking for supportsReasoningEffort array
  • This makes the implementation generic and future-proof for any GLM model with thinking support

4. Tests (src/api/providers/utils/__tests__/glm-model-detection.spec.ts)

  • Added test cases for GLM-4.6 base model thinking support
  • Added test cases for GLM-4.6V vision variants thinking support
  • Reorganized tests for clarity between models that support thinking and those that do not

Test Procedure

Run the GLM detection tests:

cd src && npx vitest run api/providers/utils/__tests__/glm-model-detection.spec.ts

The updated tests verify:

  • ✅ GLM-4.6 base model has supportsThinking: true
  • ✅ GLM-4.6V and its variants have supportsThinking: true
  • ✅ GLM-4.7 variants continue to have supportsThinking: true
  • ✅ GLM-4.5 variants correctly have supportsThinking: false

Impact

For Z.ai provider users:

  • GLM-4.6 and GLM-4.6V models will now properly send the thinking parameter
  • Users can control thinking mode via the reasoning effort settings
  • Thinking content will be preserved in conversation history

For LM Studio and OpenAI-compatible endpoint users:

Pre-Submission Checklist

Screenshots / Videos

N/A - Backend feature, no UI changes.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This PR builds on the GLM detection work in PR #11096 and addresses the specific feedback from @mark-ucalgary regarding GLM-4.6 and GLM-4.6V thinking support as documented by Z.ai.

Feedback and guidance are welcome!


Important

Adds thinking mode support for GLM-4.6 and GLM-4.6V models, updating model definitions, detection logic, provider implementations, and tests.

  • Behavior:
    • Adds thinking mode support for GLM-4.6 and GLM-4.6V models in zai.ts, glm-model-detection.ts, and zai.ts.
    • Updates GLM detection logic in glm-model-detection.ts to include GLM-4.6 and GLM-4.6V.
    • Modifies createStream in base-openai-compatible-provider.ts to handle thinking mode for GLM models.
  • Tests:
    • Adds test cases for GLM-4.6 and GLM-4.6V thinking support in glm-model-detection.spec.ts.
    • Reorganizes tests to distinguish models with and without thinking support.
  • Misc:
    • Updates comments in zai.ts to reflect new model support.
    • Adjusts NativeToolCallParser to handle tool call synchronization more robustly.

This description was created by Ellipsis for 23256cd. You can customize this summary. It will automatically update as commits are pushed.

…1071

This PR combines:
1. PR #11093 fix: NativeToolCallParser processFinishReason hasStarted check
2. GLM model detection utility for LM Studio and OpenAI-compatible providers
3. mergeToolResultText optimization for GLM models
4. Disable parallel_tool_calls for GLM models
5. GLM-4.7 thinking parameter support
6. Diagnostic logging for GLM detection

Closes #11071
This commit adds GLM model detection and related optimizations to the
OpenAI Compatible provider (OpenAiHandler), which handles the "OpenAI
Compatible" option in the UI when users set a custom base URL.

Changes:
- Import GLM detection utilities and Z.ai format converter
- Add glmConfig property to track GLM model configuration
- Detect GLM model on construction when model ID is available
- Re-detect GLM model in createMessage if model ID changes
- For GLM models:
  - Use convertToZAiFormat with mergeToolResultText to prevent
    conversation flow disruption
  - Disable parallel_tool_calls as GLM models may not support it
  - Add thinking parameter for GLM-4.7 models
- Add console logging for detection results and applied optimizations

This addresses the feedback in issue #11071 where the user clarified
they are using the "OpenAI Compatible" provider, not the "OpenAI"
provider. The previous changes in this PR only affected the
base-openai-compatible-provider.ts (used by Z.ai, Groq, etc.) and
lm-studio.ts, but not openai.ts which handles OpenAI Compatible.
- Add supportsReasoningEffort to GLM-4.6 and GLM-4.6V model definitions
- Update GLM detection logic to recognize GLM-4.6/4.6V thinking support
- Update Z.ai provider to handle thinking mode for all GLM models with reasoning
- Update tests to reflect GLM-4.6/4.6V thinking support

Addresses issue #11071 where Z.ai documentation shows GLM-4.6 and GLM-4.6V
support thinking mode, but this was not reflected in the codebase.
@roomote
Copy link
Contributor Author

roomote bot commented Jan 30, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. Found 2 issues to address:

  • Inconsistency between GLM detection and model definitions: glm-4.6v-flash and glm-4.6v-flashx are marked as supporting thinking in glm-model-detection.ts but don't have supportsReasoningEffort in zai.ts
  • Log messages say "GLM-4.7 thinking mode" but now apply to GLM-4.6 models as well (in base-openai-compatible-provider.ts, lm-studio.ts, and openai.ts)

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment on lines +141 to +146
// GLM-4.6, GLM-4.6V, and GLM-4.7 have built-in thinking support
// For GLM-4.6, only the base model and vision variants support thinking
const supportsThinking =
version === "4.7" ||
(version === "4.6" &&
(variant === "base" || variant === "v" || variant === "v-flash" || variant === "v-flashx"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This detection includes v-flash and v-flashx variants as supporting thinking, but the model definitions in zai.ts don't include supportsReasoningEffort for glm-4.6v-flash or glm-4.6v-flashx. This inconsistency means the Z.ai provider (which checks Array.isArray(info.supportsReasoningEffort)) will correctly exclude these models from thinking mode, but LM Studio and OpenAI Compatible providers will incorrectly try to send the thinking parameter to them. Either add supportsReasoningEffort to the flash variants in zai.ts if they truly support thinking, or remove v-flash and v-flashx from this detection logic.

Fix it with Roo Code or mention @roomote and request a fix.

if (this.glmConfig.isGlmModel && this.glmConfig.supportsThinking) {
const useReasoning = this.options.enableReasoningEffort !== false // Default to enabled for GLM-4.7
;(params as any).thinking = useReasoning ? { type: "enabled" } : { type: "disabled" }
console.log(`[${this.providerName}] GLM-4.7 thinking mode: ${useReasoning ? "enabled" : "disabled"}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The log message says "GLM-4.7 thinking mode" but this code now also executes for GLM-4.6 and GLM-4.6V models. Consider updating to something like "GLM thinking mode" or using this.glmConfig.displayName for accuracy. The same issue exists in lm-studio.ts and openai.ts.

Suggested change
console.log(`[${this.providerName}] GLM-4.7 thinking mode: ${useReasoning ? "enabled" : "disabled"}`)
console.log(`[${this.providerName}] ${this.glmConfig.displayName} thinking mode: ${useReasoning ? "enabled" : "disabled"}`)

Fix it with Roo Code or mention @roomote and request a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant