Repository navigation
fix: improve model merging logic in useModelsDerived for better instance-specific values - #17422
Conversation
…nce-specific values
📝 WalkthroughWalkthrough
ChangesInstance model settings
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts`:
- Around line 283-296: Update useModelEdit so optimistic edits to existing
models modify the instance-backed cache/state used by instanceItems, preserving
immediate updates to fields such as max_tokens and model_types. Remove the
catalog-only setCatalog optimistic update, while leaving catalog handling for
models not yet present in the instance source unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a4f27ed7-0e9b-4263-b235-11f6a44d5b62
📒 Files selected for processing (1)
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts`:
- Around line 668-681: Update the instance-model derivation used by this query
update and the later buildModelInfo sync so an explicit item.is_tools === false
is authoritative: remove tool-related feature keys before deriving capabilities.
Only use catalog tool features when item.is_tools is undefined, while preserving
existing behavior for true and unrelated model properties.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e424e8fd-9b7e-4de0-b03d-c730d63d1d00
📒 Files selected for processing (2)
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.tsweb/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
💤 Files with no reviewable changes (1)
- web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
| queryClient.setQueryData<IInstanceModel[]>( | ||
| LlmKeys.instanceModels(providerName, instanceName), | ||
| (prev) => { | ||
| if (!prev) return prev; | ||
| const idx = prev.findIndex((m) => m.name === targetName); | ||
| if (idx === -1) return prev; | ||
| const next = [...prev]; | ||
| const existing = next[idx]; | ||
| next[idx] = { | ||
| ...existing, | ||
| max_tokens: item.max_tokens ?? 0, | ||
| model_type: item.model_types ?? [], | ||
| is_tools: hasToolFeature(item.features), | ||
| }; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Preserve an explicit disabled tool setting.
When an edit stores is_tools: false, the instance-item derivation still retains catalog tool features, so the UI—and a later buildModelInfo sync—can turn the setting back on. Treat false as authoritative and strip tool feature keys; only fall back to catalog capabilities when is_tools is undefined.
Proposed fix
- const features =
- im.is_tools && !hasToolFeature(catalogFeats)
+ const features =
+ im.is_tools === false
+ ? (catalogFeats ?? []).filter(
+ (feature) => !TOOL_FEATURE_KEYS.includes(feature),
+ )
+ : im.is_tools && !hasToolFeature(catalogFeats)
? [...(catalogFeats ?? []), 'is_tools']
: catalogFeats;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts`
around lines 668 - 681, Update the instance-model derivation used by this query
update and the later buildModelInfo sync so an explicit item.is_tools === false
is authoritative: remove tool-related feature keys before deriving capabilities.
Only use catalog tool features when item.is_tools is undefined, while preserving
existing behavior for true and unrelated model properties.
wangq8
left a comment
There was a problem hiding this comment.
Review: PR #17422 — fix: improve model merging logic in useModelsDerived for better instance-specific values
Verdict: LGTM ✅ — solid bugfix
This PR fixes a real UX bug where editing an already-added model's properties (e.g. max_tokens) would appear to succeed but the UI never reflected the change. The root cause was two-fold:
Problem 1: Merge order was backwards
In useModelsDerived, the old code let catalog entries overwrite instance entries when building the union map. This meant that any model already attached to the instance retained its catalog defaults regardless of user edits. The fix reverses the merge to let instance entries win, only using catalog entries to fill in models that haven't been added yet.
Old: catalog.forEach((m) => byName.set(m.name, m)) — always overwrites
New: catalog.forEach((m) => { if (!byName.has(m.name)) byName.set(m.name, m) }) — catalog is fallback only
Problem 2: Edit was patching the wrong data source
handleEditSubmit was patching the local catalog state via setCatalog, but since instance entries always won the merge (even under the old logic), catalog-only updates were invisible for any model that had been added. The fix patches the instanceModels query cache directly — the actual source of truth for attached models — so the UI reflects changes immediately.
Additional improvements:
- Removed
setCatalogfrom theuseModelEditsignature andModelsSection— it's no longer needed, cleaner API - The comment update in
useModelsDerivednow accurately documents the intended merge semantics
Details:
- Files changed: 2
- Additions: 39, Deletions: 18
- Author: dcc123456
No regressions expected. The query cache patch mirrors the same shape used elsewhere in the codebase.
Summary
fix: improve model merging logic in useModelsDerived for better instance-specific values