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):
- Start qwen-code 0.17.0 with
--auth-type anthropic
- While running, replace
chunks/ with 0.17.1's chunks (simulating background npm install -g)
- 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
What happened?
When switching models via
/model(e.g., from ananthropicprovider to anopenaiprovider), the switch fails with:Root cause:
handleAutoUpdate(line 59) spawnsnpm install -g @qwen-code/qwen-code@latestin the background while the session is still running. npm replaces the entirechunks/directory with the new version's files. The new build produces chunks with different content-hash filenames (e.g.,openaiContentGenerator-N3O3MYIT.jsin 0.17.1 vsopenaiContentGenerator-4QXCH7L2.jsin 0.17.0).Content generators are lazy-loaded per authType via dynamic
import()increateContentGenerator()(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):
--auth-type anthropicchunks/with 0.17.1's chunks (simulating backgroundnpm install -g)/model, select any[openai]model → errorThe 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:
npm install -gwhile the session is active; show a message and let the user update on next launchERR_MODULE_NOT_FOUNDduring 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
npm install -g/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?
handleAutoUpdate.ts, all commits by Google contributors).openaiContentGenerator-4QXCH7L2.jsbelongs to 0.17.0;openaiContentGenerator-N3O3MYIT.jsbelongs to 0.17.1 — confirmed by inspecting both npm tarballs.openai::qwen3.7-maxhttps://...— modelId and baseUrl concatenated) is caused byModelDialog.tsx:473using the raw selection key containing a\0separator that is invisible in terminal output.Affected code path:
packages/cli/src/utils/handleAutoUpdate.ts:59— spawns background updatepackages/core/src/core/contentGenerator.ts:330-334— lazy dynamic import per authTypepackages/cli/src/utils/installationInfo.ts:178— returnsnpm install -gas updateCommand