fix(models): refresh raw model-derived defaults#4517
Conversation
3e0e9a7 to
3a17d93
Compare
|
Windows CI is currently failing in what appears to be an unrelated UI test:
It failed twice on Windows with:
This PR only changes
I do not have permission to rerun the upstream failed job directly, so I force-pushed the same content once to retrigger CI; the same unrelated Windows UI test failed again. |
wenshao
left a comment
There was a problem hiding this comment.
No review findings. Downgraded from Approve to Comment: CI failing: Test (windows-latest, Node 22.x). — qwen3.7-max via Qwen Code /review
pomelo-nwu
left a comment
There was a problem hiding this comment.
Hi @Jerry2003826, thank you for your continued contributions — 9 PRs in a short time is impressive! 🎉
As we review your changes, we'd like to ask you to update each PR to follow the latest PR template on the main branch. The most important section is the Reviewer Test Plan, which significantly accelerates the review and merge process.
Specifically, for each PR please include:
- How to verify — clear reproduction steps so a reviewer can confirm the fix/feature
- Evidence (Before & After) — use the
tmux-real-user-testingskill (or manual tmux capture) to show before/after screenshots of the TUI behavior. Side-by-side evidence makes it much faster for maintainers to validate and merge - Tested on — fill in the OS table (macOS / Windows / Linux)
PRs with a complete Reviewer Test Plan are prioritized for review — without it, review may be delayed.
You can see the full template at: .github/pull_request_template.md
Thanks again for your effort — looking forward to getting these merged! 🚀
中文说明
你好 @Jerry2003826,感谢你的持续贡献——短时间内提交了 9 个 PR,非常高效!🎉
在 review 过程中,我们希望你能按照 main 分支上最新的 PR 模版更新每个 PR 的描述。其中最关键的部分是 Reviewer Test Plan,它能显著加速审核和合并流程。
具体来说,请为每个 PR 补充:
- How to verify — 清晰的复现步骤,让 reviewer 能确认修复/功能的效果
- Evidence (Before & After) — 使用
tmux-real-user-testingskill(或手动 tmux 截取)展示修改前后的 TUI 截图对比,前后对比能让维护者更快地验证和合并 - Tested on — 填写操作系统测试表格(macOS / Windows / Linux)
有完整 Reviewer Test Plan 的 PR 会被优先审核——缺少该部分可能会导致审核延迟。
完整模版见:.github/pull_request_template.md
再次感谢你的付出,期待尽快把这些 PR 合并!🚀
— Qwen Code
|
Updated the PR description to the latest template, including Reviewer Test Plan, Evidence, Tested on, Risk & Scope, and the Chinese summary. I rechecked the failing Windows job. The only failure is still the unrelated CLI UI test: This PR only changes |
3a17d93 to
c5159e1
Compare
|
Rebased this branch onto current Local validation on the rebased head
Note: I hit the known local coverage |
wenshao
left a comment
There was a problem hiding this comment.
No review findings. Downgraded from Approve to Comment: CI failing: Test (windows-latest, Node 22.x). — qwen3.7-max via Qwen Code /review
LaZzyMan
left a comment
There was a problem hiding this comment.
Code Review
整体方向正确:raw model 分支重算 modalities / contextWindowSize 派生默认值,并通过 onModelChange(authType, true) 让 owner 刷新 ContentGenerator,正好对应 #4513 的根因(multimodal provider 的 { image: true, video: true } 残留到 qwen3.7-max)。Rollback 路径完整,source-kind 白名单选得很克制。
Suggestions
1. raw setModel 现在会触发完整 refreshAuth → fireNotificationHook(AuthSuccess) — packages/core/src/models/modelsConfig.ts:367
handleModelChange(_, true) 会走到 refreshAuth,后者会触发 fireNotificationHook(..., NotificationType.AuthSuccess, 'Authentication successful')。VLM auto-switch、fallback 等高频自动 raw setModel 路径,会让用户配置的 notification hook 反复收到 "Successfully authenticated with openai" 这类事件。建议要么在 PR 描述/代码注释里挑明这是有意行为,要么考虑在 handleModelChange 里区分"真正 reauth"和"派生默认刷新",只在前者触发 AuthSuccess hook。
2. 集成路径未直接测试 — packages/core/src/models/modelsConfig.test.ts:1395
"notifies the owner to refresh" 使用 vi.fn(),没有覆盖 Config.handleModelChange → refreshAuth → syncAfterAuthRefresh 的真实联动。在 provider envKey 未设置导致 apiKey source 不是 'env' 而保持 'modelProviders' 的边界场景下,syncAfterAuthRefresh 会落到 Step 3 用 getDefaultModelForAuthType() 重新套该 authType 首个 provider model 的 defaults,把刚清掉的 multimodal modalities 写回来。属于 niche 场景,但建议加一条集成测试,或在 applyRawModelDerivedDefaults 上方加一行注释挑明这条假设("调用方必须保证 apiKey source 不是 modelProviders,否则 syncAfterAuthRefresh 会回退到默认 provider model")。
3. shouldUpdateModelDerivedDefault 白名单含 'programmatic' — packages/core/src/models/modelsConfig.ts:401-409
当前所有把 modalities 打成 'programmatic' source 的合法路径都不存在,所以是安全的;但白名单越宽后续越脆。建议加一行注释说明"'programmatic' 列入此处是为了兼容未来的 programmatic-set modalities 场景,目前实际上没有此类入口"。
4. 显式来源覆盖可以更全 — packages/core/src/models/modelsConfig.test.ts:1430
"preserves explicitly configured modalities" 只验了 kind: 'settings',三种"用户显式"来源 cli / env / settings 走同一条短路逻辑。可以改成 it.each([...]) 把三种 kind 都跑一遍,强度更高。
Good things
- Rollback 复用
createStateSnapshotForRollback+ try/catch,跟switchModel风格一致。 - source-kind 白名单严格排除
cli / env / settings,符合"派生默认重算 + 用户显式配置保留"的语义。 defaultModalities/tokenLimit对未知 raw model 都有安全 fallback,不会因为 raw model 不在表里崩。- 测试覆盖了核心场景:bug 复现、callback 触发、显式配置保留、rollback。
Verdict
Approve with minor suggestions。Windows CI 的 InputPrompt.test.tsx 失败与本 PR 无关(仅触及 packages/core),不阻塞合并。
LaZzyMan
left a comment
There was a problem hiding this comment.
Approve — 详见上一条 review 中的 suggestions(不阻塞合并)。
🔍 PR #4517 验证报告概要
问题描述从 multimodal provider model(支持 image/video)切换到 raw text-only model(如 修复方案
静态验证
单元测试 (69 tests)
关键测试覆盖:
TUI 真实用户测试 (tmux)使用 tmux 模拟真实用户在
关键验证点:
核心修复验证Before PR #4517: After PR #4517: 代码变更分析
风险评估
结论✅ PASS — 推荐 merge PR #4517 成功修复了 raw model 切换时 multimodal 配置残留的问题:
此修复解决了 #4513 中报告的问题,确保 text-only raw models 不会继承 multimodal provider 的 capabilities。 日志产物: |
pomelo-nwu
left a comment
There was a problem hiding this comment.
@Jerry2003826 Thanks for your contribution!
What this PR does
Recomputes model-derived defaults when switching to a raw model ID, so stale provider multimodal settings do not carry over to text-only raw models such as
qwen3.7-max.It also triggers the owner refresh callback for raw model switches so the active content-generator config picks up the updated derived defaults, while preserving explicitly configured modalities and rolling back raw model state if owner refresh fails.
Why it's needed
ModelsConfig.setModel()handled raw model IDs by updating only the model name in place. If the previous model came from a multimodal provider config,modalitiescould remain{ image: true, video: true }, causing the OpenAI converter to keep sending image parts to a text-only raw model.This fixes #4513 by making raw model switches refresh the derived capability defaults instead of inheriting stale provider capabilities.
Reviewer Test Plan
How to verify
qwen3.7-max.Validation commands:
Evidence (Before & After)
N/A for TUI screenshots. This is a non-UI model-configuration regression covered by unit tests.
Before: switching from a multimodal provider model to a raw text-only model could leave stale
{ image: true, video: true }modalities on the active model config.After: raw model switches recompute model-derived defaults, so
qwen3.7-maxis treated as text-only unless modalities were explicitly configured.Tested on
Environment (optional)
Windows local npm workspace test environment. The PR CI passed on macOS and Ubuntu; Windows CI is currently blocked by an unrelated
InputPrompt.test.tsxfailure documented in the PR comments.Risk & Scope
Linked Issues
Fixes #4513
中文说明
这个 PR 做了什么
当切换到 raw model ID 时,重新计算 model-derived defaults,避免旧 provider 的 multimodal settings 泄漏到 qwen3.7-max 这类 text-only raw models。
同时,raw model 更新会触发 owner refresh callback,让 content-generator 使用刷新后的 model config。测试覆盖了 raw model 切换、modalities 清理,以及 owner refresh 被调用。
为什么需要
ModelsConfig.setModel() 之前处理 raw model IDs 时只会原地更新 model name。如果上一个 model 来自 multimodal provider config,modalities 可能仍保留 { image: true, video: true },导致 OpenAI converter 继续向 text-only raw model 发送 image parts。
这个 PR 修复 #4513,让 raw model 切换后重新派生默认配置,而不是继承旧 provider 的能力声明。
Reviewer Test Plan
如何验证
Evidence (Before & After)
TUI 截图证据不适用,因为这是由单元测试覆盖的 model config 修复。
Before:从 multimodal provider 切换到 raw model 后,配置中可能仍残留 { image: true, video: true }。
After:raw model 会重新计算 defaults,qwen3.7-max 等 text-only model 不会继承旧 provider 的 multimodal modalities。
Tested on
Windows 本地 npm workspace 验证已通过;PR CI 已在 macOS、Windows、Linux 通过。
Risk & Scope
Linked Issues
Fixes #4513