Repository navigation
Description
Description
We're using Qwen on premise. During the usage, the context window grows without being stopped by auto compact.
I've locally applied a fix, see additional context below. Another possibility to quickly circumvent the issue is to use the environmental variable NANOCODER_CONTEXT_LIMIT which skips the problematic code path.
Environment
- OS: Windows 11
- Node version: v24.14.1
- Nanocoder version: 1.26.1
- Provider: Qwen
- Model: Qwen 3.6 27B
Steps to Reproduce
- set up Qwen on premise
- use it as single provider in agents.config.json
- make a prompt that uses many tokens, e.g. an extensive security analysis on a huge project.
Expected Behavior
AutoCompact should regularly decrease the context window before it's too huge
Actual Behavior
Auto Compact is never triggered.
Logs/Screenshots
Additional Context
- I have searched existing issues to ensure this is not a duplicate
- I can reproduce this issue consistently
- This issue occurs with the latest version of nanocoder
I've analyzed the code both by Qwen and myself.
The problem seems to be in source/utils/auto-compact.ts in function performAutoCompact(). When trying to determine the contextLimit, not the real providerConfig but a hardcoded one is used which fails in our case:
contextLimit = await getModelContextLimit(model, {
providerConfig: {
name: provider,
type: 'openai',
models: [model],
config: {},
},
});
A solution would be to get the real one (with a fallback), e.g. with the following code
let providerConfig = client?.getProviderConfig();
if (!providerConfig) {
// Fallback: some providers (gemini, anthropic) may return undefined.
// Try resolving via model index as last resort — but we still need
// the provider name which is passed separately.
providerConfig = {
name: provider,
type: 'openai',
models: [model],
config: {},
} as any;
}
followed by this change that uses the so determined one:
contextLimit = await getModelContextLimit(model, {
providerConfig,
});
I've fixed it locally and tested by compiling and copying the generated auto-compact.js into the respective nanocode folder overwriting the existing one.
Activity
[-][Bug] performAutoCompact when using Qwen on premise[/-][+][Bug] performAutoCompact fails when using Qwen on premise[/+]will-lamerton commentedon May 22, 2026
Thank you for opening this issue @rolfwendt and for the detailed breakdown and fix. Would you like to open a PR for what you've done or are you happy for the team to take this and apply your fix? Obviously want to give you the credit and chance to do so for finding, identifying and fixing :)
rolfwendt commentedon May 22, 2026
Thanks for your quick response!
I'd be happy if you could apply it yourself and check it thoroughly, because I don't know your project as well as I think would be needed to "be sure" about the fix. And more than half of the credits go to Qwen - I was just the human-in-the-middle ensuring that it's no complete BS :-)
will-lamerton commentedon May 22, 2026
@rolfwendt - thanks for this once again, fix applied with regression tests :) this will be out in the next release which is pending!
fix: auto-compact ignored provider contextWindow. Closes Nano-Collect…