Skip to content

[Bug] performAutoCompact fails when using Qwen on premise #525

Closed

Description

@rolfwendt

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

  1. set up Qwen on premise
  2. use it as single provider in agents.config.json
  3. 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

Image

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

  1. added
    bug
    on May 22, 2026
  2. changed the title [-][Bug] performAutoCompact when using Qwen on premise[/-] [+][Bug] performAutoCompact fails when using Qwen on premise[/+] on May 22, 2026
  3. will-lamerton commented on May 22, 2026

    @will-lamerton
    Member

    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 :)

  4. rolfwendt commented on May 22, 2026

    @rolfwendt
    Author

    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 :-)

  5. will-lamerton commented on May 22, 2026

    @will-lamerton
    Member

    @rolfwendt - thanks for this once again, fix applied with regression tests :) this will be out in the next release which is pending!

  6. added a commit that references this issue on May 24, 2026
    a2d5a87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions