Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 30, 2026

Related GitHub Issue

Closes: #11071

Roo Code Task Context (Optional)

No Roo Code task context for this PR

Description

This PR extends the GLM model detection implementation to apply GLM-4.7 specific parameters that were added in release 3.44.1, making GLM models on LM Studio and OpenAI-compatible endpoints behave more like they do on the Z.ai provider.

Key implementation details:

  1. Version Detection: Added isGlm47Plus() function to detect GLM-4.7 and higher versions using regex pattern matching
  2. Thinking Mode Support: For GLM-4.7+ models, the providers now send the thinking: { type: "enabled" | "disabled" } parameter, similar to how the Z.ai provider handles it
  3. Reasoning Effort Integration: Uses the existing shouldUseReasoningEffort() utility to determine whether to enable thinking mode based on user settings
  4. Backward Compatibility: Maintains all existing GLM optimizations (mergeToolResultText, disableParallelToolCalls) for all GLM models

Design choices:

What reviewers should focus on:

  • The regex pattern for detecting GLM-4.7+ versions - does it cover all expected variations?
  • The integration with shouldUseReasoningEffort() - does it correctly respect user settings?
  • Whether the thinking parameter should be applied to all GLM models or only 4.7+

Test Procedure

Unit Tests:

  1. Created comprehensive test suite with 101 test cases covering:

    • GLM model detection for various formats (standard, MLX, GGUF, HuggingFace, ChatGLM)
    • GLM-4.7+ version detection
    • Option generation for different GLM versions
    • Edge cases (undefined, empty strings, non-GLM models)
  2. Ran tests: cd src && npx vitest run api/providers/utils/__tests__/glm-model-detection.spec.ts

    • Result: ✅ All 101 tests passed
  3. Ran Z.ai provider tests to ensure no regression: cd src && npx vitest run api/providers/__tests__/zai.spec.ts

    • Result: ✅ All 33 tests passed
  4. Ran full linting and type checking via pre-push hooks

    • Result: ✅ No linting errors, all type checks passed

How to verify:

  1. Load a GLM-4.7 model in LM Studio (e.g., mlx-community/GLM-4.7-4bit)
  2. Configure Roo Code to use LM Studio provider
  3. Enable reasoning effort in settings
  4. Start a task and verify that the model receives the thinking parameter
  5. Check developer console for any GLM detection logs (if diagnostic logging is added)

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

No UI changes in this PR

Documentation Updates

  • No documentation updates are required.

Additional Notes

Implementation builds on PR #11082:

This PR assumes that PR #11082 (basic GLM detection) will be merged first, or can be incorporated into this PR if needed. The implementation is designed to be backward compatible and can work independently if the basic GLM detection is not yet merged.

Questions for reviewers:

  1. Should the thinking parameter also be applied to GLM-4.6 models, or only 4.7+?
  2. Should we add console logging to help users verify that GLM detection is working correctly?
  3. Is the version detection pattern robust enough, or should we be more conservative?

Relationship to issue context:

The user asked whether the GLM model detection would also apply model-specific parameters like those added for GLM-4.7 in release 3.44.1. This PR ensures that yes, GLM-4.7 specific parameters (thinking mode) are now applied to GLM models regardless of whether they're accessed via Z.ai, LM Studio, or OpenAI-compatible endpoints.

Get in Touch

@roomote


Important

Adds GLM-4.7+ thinking mode support for LM Studio and OpenAI-compatible endpoints with new model detection and parameter handling.

  • Behavior:
    • Adds isGlm47Plus() in glm-model-detection.ts to detect GLM-4.7+ versions using regex.
    • For GLM-4.7+ models, adds thinking parameter in base-openai-compatible-provider.ts and lm-studio.ts.
    • Uses shouldUseReasoningEffort() to enable thinking mode based on user settings.
  • Testing:
    • Adds 101 test cases in glm-model-detection.spec.ts for model detection and option generation.
    • Verifies GLM-4.7+ detection and thinking mode support.
  • Misc:
    • Maintains backward compatibility with existing GLM optimizations.

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

@roomote
Copy link
Contributor Author

roomote bot commented Jan 30, 2026

Rooviewer Clock   See task on Roo Cloud

Reviewed the GLM-4.7+ thinking mode implementation. Found 1 issue that affects both providers:

  • shouldUseReasoningEffort() always returns false for LM Studio and OpenAI-compatible providers because the default model info lacks supportsReasoningEffort and reasoningEffort properties, causing thinking mode to never be enabled for GLM-4.7+ models

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

Comment on lines +119 to +123
// For GLM-4.7+ models, add thinking mode support similar to Z.ai
if (glmOptions?.supportsThinking) {
const useReasoning = shouldUseReasoningEffort({ model: modelInfo, settings: this.options })
params.thinking = useReasoning ? { type: "enabled" } : { type: "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.

shouldUseReasoningEffort() will always return false for LM Studio models because modelInfo comes from either the model cache or openAiModelInfoSaneDefaults, neither of which have supportsReasoningEffort or reasoningEffort properties. The function's fallback logic checks !!modelDefaultEffort, which will be undefined for these models. This means thinking mode will never be enabled - the code will always send thinking: { type: "disabled" }. Consider either: (1) not relying on shouldUseReasoningEffort() for detected GLM-4.7+ models and instead default to enabled unless user explicitly disables via enableReasoningEffort: false, or (2) have getGlmModelOptions() return synthetic reasoning capability info that can be used instead of/in addition to the model info.

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

Comment on lines +123 to 127
// For GLM-4.7+ models, add thinking mode support similar to Z.ai
if (glmOptions?.supportsThinking) {
const useReasoning = shouldUseReasoningEffort({ model: info, settings: this.options })
params.thinking = useReasoning ? { type: "enabled" } : { type: "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.

Same issue as in lm-studio.ts: shouldUseReasoningEffort() will always return false for models that use default model info (e.g., dynamic providers) because openAiModelInfoSaneDefaults lacks supportsReasoningEffort and reasoningEffort properties. The thinking parameter will always be set to disabled for GLM-4.7+ models using generic OpenAI-compatible providers.

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.

[BUG] GLM4.5 via LMStudio as well as via an OpenAI-compatible endpoint stuck repeating file reads

1 participant