Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 30, 2026

Summary

This PR attempts to address Issue #11071 by implementing a comprehensive GLM model family detection system that addresses the feedback from @mark-ucalgary.

Problem

GLM4.5 models via LM Studio and OpenAI-compatible endpoints were getting stuck in repeated file read loops. Previous attempts to fix this did not:

  1. Show logging messages in the console
  2. Successfully resolve the file read looping
  3. Take a strategic approach to GLM model family detection

Solution

This PR implements a strategic GLM model family detection system that:

1. GLM Model Detection Utility (glm-model-detection.ts)

  • Family Detection: Identifies if a model is part of the GLM family using flexible regex patterns
  • Version Detection: Distinguishes between GLM-4.5, GLM-4.6, and GLM-4.7
  • Variant Detection: Identifies specific variants (base, air, airx, flash, flashx, x, v, v-flash, v-flashx)
  • Capability Detection: Determines vision support and thinking/reasoning support

Supports various model ID formats:

  • Standard: glm-4.5, glm-4.7-flash
  • With prefix: mlx-community/GLM-4.5-4bit
  • GGUF files: GLM-4.5-UD-Q8_K_XL-00001-of-00008.gguf
  • ChatGLM: chatglm-6b, chatglm3-6b

2. Console Logging

Added logGlmDetection() function that outputs detection results to console:

[LM Studio] Using model ID: "mlx-community/GLM-4.5-4bit"
[GLM Detection] ✓ GLM model detected: "mlx-community/GLM-4.5-4bit"
[GLM Detection]   - Version: 4.5
[GLM Detection]   - Variant: base
[GLM Detection]   - Display name: GLM-4.5
[GLM Detection]   - Supports vision: false
[GLM Detection]   - Supports thinking: false
[GLM Detection]   - mergeToolResultText: true
[GLM Detection]   - disableParallelToolCalls: true

3. Provider Updates

Updated LmStudioHandler and BaseOpenAiCompatibleProvider to:

  • Detect GLM models on construction and log results
  • Use convertToZAiFormat with mergeToolResultText: true for GLM models (prevents conversation flow disruption)
  • Disable parallel_tool_calls for GLM models (they may not support it)
  • Add thinking parameter support for GLM-4.7 models
  • Handle reasoning_content in stream responses

4. Comprehensive Tests

Added 33 test cases covering:

  • Model ID pattern matching
  • Version detection
  • Variant detection
  • Thinking support detection
  • Configuration flags
  • Display name generation
  • Real-world model ID formats
  • Logging functionality

Testing

All tests pass:

  • 33 new tests for GLM detection utility
  • 21 existing tests for lmstudio.spec.ts and base-openai-compatible-provider.spec.ts
  • TypeScript compilation passes
  • ESLint passes

How to Test

  1. Build and install the extension from this branch
  2. Open VS Code Developer Tools (Help -> Toggle Developer Tools)
  3. Go to the Console tab
  4. Start using Roo Code with your GLM model
  5. Look for [LM Studio] or [GLM Detection] log messages

If detection is working, you should see logs indicating the model was detected and what optimizations were applied.

Feedback Welcome

This is an attempt to address the issue. Feedback and guidance are welcome!


Important

Introduces strategic GLM model family detection for LM Studio and OpenAI-compatible providers, with utility, provider updates, logging, and comprehensive tests.

  • GLM Model Detection Utility (glm-model-detection.ts):
    • Detects GLM model family, version, variant, vision, and thinking support using regex patterns.
    • Supports model ID formats like glm-4.5, mlx-community/GLM-4.5-4bit, and chatglm-6b.
  • Provider Updates:
    • BaseOpenAiCompatibleProvider and LmStudioHandler detect GLM models on construction, log results, and adjust settings like mergeToolResultText and parallel_tool_calls.
    • Add thinking parameter for GLM-4.7 models.
  • Console Logging:
    • logGlmDetection() logs detection results to console.
  • Tests:
    • 33 new test cases for GLM detection utility in glm-model-detection.spec.ts.
    • Tests cover model ID matching, version/variant detection, and logging.

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

…AI-compatible providers

This PR addresses Issue #11071 by implementing a comprehensive GLM model detection system:

1. Created glm-model-detection.ts utility that:
   - Detects GLM family models (GLM-4.5, 4.6, 4.7 and variants)
   - Supports various model ID formats (standard, MLX, GGUF, ChatGLM)
   - Identifies version (4.5, 4.6, 4.7) and variant (base, air, flash, v, etc.)
   - Returns appropriate configuration for each model

2. Updated LmStudioHandler to:
   - Detect GLM models and log detection results to console
   - Use convertToZAiFormat with mergeToolResultText for GLM models
   - Disable parallel_tool_calls for GLM models
   - Handle reasoning_content for GLM-4.7 models

3. Updated BaseOpenAiCompatibleProvider similarly

4. Added 33 comprehensive tests for the detection utility

The detection uses flexible regex patterns to match model IDs like:
- mlx-community/GLM-4.5-4bit
- GLM-4.5-UD-Q8_K_XL-00001-of-00008.gguf
- glm-4.5, glm-4.7-flash, etc.
@roomote
Copy link
Contributor Author

roomote bot commented Jan 30, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. Found 2 issues in lm-studio.ts that should be addressed.

  • Dead code: parallelToolCalls computed but never used in completePrompt (lines 240-242)
  • Missing thinking parameter for GLM-4.7 models in createMessage request params (line 128)

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

Comment on lines +240 to +242
// Determine parallel_tool_calls setting for GLM models
const parallelToolCalls =
this.glmConfig?.isGlmModel && this.glmConfig.disableParallelToolCalls ? false : true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dead code: parallelToolCalls is computed here but never used. The params object below does not include parallel_tool_calls. Either add it to params or remove this computation.

Suggested change
// Determine parallel_tool_calls setting for GLM models
const parallelToolCalls =
this.glmConfig?.isGlmModel && this.glmConfig.disableParallelToolCalls ? false : true

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

tool_choice: metadata?.tool_choice,
parallel_tool_calls: metadata?.parallelToolCalls ?? true,
parallel_tool_calls: parallelToolCalls,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing thinking parameter for GLM-4.7 models. Unlike BaseOpenAiCompatibleProvider, this handler does not add the thinking parameter to requests when this.glmConfig.supportsThinking is true. While the code correctly handles reasoning_content in responses (lines 161-167), without sending the thinking parameter, GLM-4.7's thinking mode won't be activated. Consider adding the same logic used in BaseOpenAiCompatibleProvider (lines 138-145) here.

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

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant