Skip to content

fix: improve model merging logic in useModelsDerived for better instance-specific values - #17250

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/model-provider-error-0722
Jul 23, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/model-provider-error-0722

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

Summary

fix: improve model merging logic in useModelsDerived for better instance-specific values

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

useModelsDerived now gives instance models precedence over provider catalog models with duplicate names, while still adding unique catalog models.

Changes

Model precedence

Layer / File(s) Summary
Preserve instance models
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
Model merging keeps existing instance entries and inserts catalog entries only when their names are not already present; inline documentation reflects this behavior.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: wangq8

Poem

I’m a rabbit guarding models bright,
Instance entries stay in sight.
Catalog friends may join the queue,
Unless that name is already true.
A tidy merge, a carrot cheer!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description matches the required Summary section but is too brief and mostly repeats the title without useful context. Expand the Summary with the problem background, what changed in useModelsDerived, and why instance models should take precedence.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: fixing model merging so instance-specific values take precedence.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dosubot dosubot Bot added 🐞 bug Something isn't working, pull request that fix bug. 🧰 typescript Pull requests that update Typescript code labels Jul 22, 2026
@dcc123456 dcc123456 added the ci Continue Integration label Jul 22, 2026
@dcc123456
dcc123456 requested a review from wangq8 July 22, 2026 09:18
@dcc123456
dcc123456 marked this pull request as draft July 22, 2026 09:18
@dcc123456
dcc123456 marked this pull request as ready for review July 22, 2026 09:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between df963cf and 5926698.

📒 Files selected for processing (1)
  • web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts

Comment on lines +283 to +296
// 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);
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants