Skip to content

Background auto-update replaces chunks mid-session, breaking cross-authType model switching #4758

Description

@yiliang114

What happened?

When switching models via /model (e.g., from an anthropic provider to an openai provider), the switch fails with:

✕ Failed to switch model to
'openai::qwen3.7-maxhttps://idealab.alibaba-inc.com/api/openai/v1'.

Cannot find module
'/opt/homebrew/lib/node_modules/@qwen-code/qwen-code/chunks/openaiContentGenerator-4QXCH7L2.js'
imported from
/opt/homebrew/lib/node_modules/@qwen-code/qwen-code/chunks/chunk-MEN6IEKX.js

Root cause: handleAutoUpdate (line 59) spawns npm install -g @qwen-code/qwen-code@latest in the background while the session is still running. npm replaces the entire chunks/ directory with the new version's files. The new build produces chunks with different content-hash filenames (e.g., openaiContentGenerator-N3O3MYIT.js in 0.17.1 vs openaiContentGenerator-4QXCH7L2.js in 0.17.0).

Content generators are lazy-loaded per authType via dynamic import() in createContentGenerator() (contentGenerator.ts). If the user hasn't triggered a particular authType yet in the current session, Node.js hasn't cached that chunk. When the user switches authType after the background update, the in-memory code references the old hash but the file on disk has the new hash → ERR_MODULE_NOT_FOUND.

Reproduction (confirmed with real 0.17.0 → 0.17.1 packages):

  1. Start qwen-code 0.17.0 with --auth-type anthropic
  2. While running, replace chunks/ with 0.17.1's chunks (simulating background npm install -g)
  3. Open /model, select any [openai] model → error

The error only affects authType switches that haven't been loaded yet in the current process. Same-authType model switches work fine because Node.js ESM caches the already-loaded dynamic import.

What did you expect to happen?

Model switching should work reliably regardless of whether a background auto-update has occurred during the session.

Possible fixes:

  • Defer the update: don't run npm install -g while the session is active; show a message and let the user update on next launch
  • Restart prompt: after a successful background update, prompt the user to restart the session before the old chunks go stale
  • Catch and recover: catch ERR_MODULE_NOT_FOUND during model switch and show a clear message like "Qwen Code was updated in the background. Please restart to use the new version."

Client information

Client Information
  • Version: 0.17.0 → auto-updated to 0.17.1
  • Platform: macOS (darwin-arm64)
  • Install method: npm install -g
  • Install path: /opt/homebrew/lib/node_modules/@qwen-code/qwen-code/

Login information

API Key (openai-compatible provider via settings modelProviders)

Anything else we need to know?

  • The auto-update mechanism is inherited from upstream Gemini CLI (handleAutoUpdate.ts, all commits by Google contributors).
  • openaiContentGenerator-4QXCH7L2.js belongs to 0.17.0; openaiContentGenerator-N3O3MYIT.js belongs to 0.17.1 — confirmed by inspecting both npm tarballs.
  • The secondary cosmetic issue in the error message (openai::qwen3.7-maxhttps://... — modelId and baseUrl concatenated) is caused by ModelDialog.tsx:473 using the raw selection key containing a \0 separator that is invisible in terminal output.

Affected code path:

  • packages/cli/src/utils/handleAutoUpdate.ts:59 — spawns background update
  • packages/core/src/core/contentGenerator.ts:330-334 — lazy dynamic import per authType
  • packages/cli/src/utils/installationInfo.ts:178 — returns npm install -g as updateCommand

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

category/cliCommand line interface and interactiontype/bugSomething isn't working as expected

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions