Repository navigation
fix: improve model merging logic in useModelsDerived for better instance-specific values - #17250
Conversation
…nce-specific values
📝 WalkthroughWalkthrough
ChangesModel precedence
Estimated code review effort: 2 (Simple) | ~5 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ 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: The models list now prioritizes instanceItems, so update
the edit flow in handleEditSubmit to write the submitted model values into the
authoritative instance state/cache or a local instance override, not only the
catalog. Ensure the edited existing model renders its new values immediately
while preserving instance precedence and existing behavior for catalog-only
models.
🪄 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
Run ID: 6a0ac4c7-52ff-4984-a5d9-5a4df15ff500
📒 Files selected for processing (1)
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
| // Union of instance models + catalog, keyed by `name`. Instance entries | ||
| // win on conflict so that editing an already-added model loads the | ||
| // instance-specific values (e.g. a user-customised `max_tokens`) rather | ||
| // than the upstream catalog defaults; catalog entries are only used to | ||
| // fill in models that have not been added yet. Instance set is listed | ||
| // first so already-added models stay at the top on the initial render. | ||
| const models: IProviderModelItem[] = useMemo(() => { | ||
| const byName = new Map<string, IProviderModelItem>(); | ||
| instanceItems.forEach((m) => byName.set(m.name, m)); | ||
| catalog.forEach((m) => byName.set(m.name, m)); | ||
| catalog.forEach((m) => { | ||
| if (!byName.has(m.name)) { | ||
| byName.set(m.name, m); | ||
| } | ||
| }); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Keep local model edits in sync with instance precedence.
Because catalog entries are now ignored when instanceItems contains the same name, handleEditSubmit’s catalog update at Line [665-669] is no longer reflected for existing models. After editing an instance model, the row continues rendering stale instanceItems values until the backend data refreshes. Update the authoritative instance state/cache in the edit path, or maintain a local instance override.
🤖 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 283 - 296, The models list now prioritizes instanceItems, so update
the edit flow in handleEditSubmit to write the submitted model values into the
authoritative instance state/cache or a local instance override, not only the
catalog. Ensure the edited existing model renders its new values immediately
while preserving instance precedence and existing behavior for catalog-only
models.
wangq8
left a comment
There was a problem hiding this comment.
LGTM. This is a good fix — the old behavior where catalog entries always overwrote instance entries meant any user-customized model settings (like max_tokens) would silently reset to upstream defaults. The new logic preserves instance-specific values and only falls back to catalog entries for models not yet added.
One minor suggestion: consider adding a unit test that verifies instance entries are preserved when a catalog entry with the same name exists, to prevent regressions — though not a blocker for this PR.
Code is clean and the updated comment accurately describes the new behavior.
Summary
fix: improve model merging logic in useModelsDerived for better instance-specific values