-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add configurable context window limit for Qwen CLI provider #7600
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
Conversation
- Add qwenCodeMaxContextWindow setting to provider-settings schema - Update QwenCodeHandler to apply context window limit when configured - Add comprehensive tests for the new functionality - Addresses issue #7598 where large context windows cause performance issues
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.
Reviewing my own code because apparently I trust no one, not even myself.
|
|
||
| const qwenCodeSchema = apiModelIdProviderModelSchema.extend({ | ||
| qwenCodeOauthPath: z.string().optional(), | ||
| qwenCodeMaxContextWindow: z.number().int().min(1000).max(1000000).optional(), |
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.
Is the naming pattern intentional? I noticed AWS Bedrock uses awsModelContextWindow for a similar purpose. The "Max" prefix here does make the limiting behavior clearer, but we might want to consider consistency across providers. What do you think?
| qwenCodeModels[id as keyof typeof qwenCodeModels] || qwenCodeModels[qwenCodeDefaultModelId] | ||
|
|
||
| // Apply custom context window limit if configured | ||
| if (this.options.qwenCodeMaxContextWindow && this.options.qwenCodeMaxContextWindow > 0) { |
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.
Consider adding a debug or info log here when the context window is being limited? It could help users understand when and why their context is being capped:
| if (this.options.qwenCodeMaxContextWindow && this.options.qwenCodeMaxContextWindow > 0) { | |
| if (this.options.qwenCodeMaxContextWindow && this.options.qwenCodeMaxContextWindow > 0) { | |
| const originalWindow = info.contextWindow; | |
| info = { | |
| ...info, | |
| contextWindow: Math.min(info.contextWindow, this.options.qwenCodeMaxContextWindow), | |
| } | |
| if (info.contextWindow < originalWindow) { | |
| console.debug(`Qwen context window limited from ${originalWindow} to ${info.contextWindow} tokens`); | |
| } | |
| } |
| expect(info.maxTokens).toBe(qwenCodeModels["qwen3-coder-flash"].maxTokens) | ||
| expect(info.description).toBe(qwenCodeModels["qwen3-coder-flash"].description) | ||
| }) | ||
| }) |
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.
Great test coverage for the getModel() method! Would it be worth adding a test for the completePrompt method as well to ensure the context window limit is properly applied there too? The method calls getModel() internally, so it should work, but explicit verification never hurts.
|
Issue needs scoping. |
This PR attempts to address Issue #7598. Feedback and guidance are welcome.
Summary
Adds a configurable context window limit for the Qwen CLI provider to prevent performance issues when token usage exceeds ~200k tokens.
Problem
The Qwen CLI provider currently defaults to a large context window size of 1 million tokens. In practice, when token usage exceeds approximately 200,000 tokens, tasks in Roo Code become very slow and tend to over-engineer outputs, negatively impacting performance.
Solution
This PR introduces a new optional setting
qwenCodeMaxContextWindowthat allows users to limit the context window size for the Qwen CLI provider. When configured, the provider will use the minimum of the configured limit and the model's default context window.Changes
qwenCodeMaxContextWindowsetting to provider-settings schema with validation (min: 1000, max: 1,000,000)QwenCodeHandlerto apply the context window limit when configuredTesting
Related Issue
Fixes #7598
Important
Adds
qwenCodeMaxContextWindowsetting to limit context window size for Qwen CLI provider, with validation and tests.qwenCodeMaxContextWindowsetting to limit context window size for Qwen CLI provider.QwenCodeHandler.qwenCodeMaxContextWindowtoqwenCodeSchemainprovider-settings.tswith validation (min: 1000, max: 1,000,000).qwen-code.spec.tsfor default behavior, context window limiting, and edge cases (0, negative, larger values).This description was created by
for 22148e4. You can customize this summary. It will automatically update as commits are pushed.