Skip to content

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

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
dcc123456:fix/model-provider-error-0722
Jul 27, 2026
Merged

wangq8 merged 3 commits 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 size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧰 typescript Pull requests that update Typescript code labels Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

useModelsDerived now prioritizes instance models over catalog models on name conflicts. useModelEdit updates the instance-models query cache when edits are submitted, and its caller no longer passes a catalog setter.

Changes

Instance model settings

Layer / File(s) Summary
Preserve instance model values
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
useModelsDerived adds catalog models only when no same-named instance model exists.
Optimistic model editing
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts, web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
useModelEdit updates matching instance-model query entries with edited properties, while ModelsSection uses the revised hook signature.

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

Possibly related PRs

  • infiniflow/ragflow#17250: Updates the same model-merging logic to give instance models precedence over catalog models.

Suggested reviewers: wangq8

Poem

A rabbit hops through models bright,
Instance values win the fight.
Edits bloom in cached fields anew,
Catalog friends still join the queue.
Conflict resolved with whiskers light!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change by describing improved model merging for instance-specific values.
Description check ✅ Passed The description includes the required Summary section and states the main goal of the change.
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.

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.

@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: 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

📥 Commits

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

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

@dcc123456
dcc123456 requested a review from wangq8 July 27, 2026 07:58
@dcc123456 dcc123456 added the ci Continue Integration label Jul 27, 2026
@dcc123456
dcc123456 marked this pull request as draft July 27, 2026 07:58
@dcc123456
dcc123456 marked this pull request as ready for review July 27, 2026 07:58
@dcc123456
dcc123456 marked this pull request as draft July 27, 2026 07:59
@dcc123456
dcc123456 marked this pull request as ready for review July 27, 2026 08:12
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 27, 2026

@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 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

📥 Commits

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

📒 Files selected for processing (2)
  • web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
  • web/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

Comment on lines +668 to +681
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),
};

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.

🗄️ 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 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.

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 setCatalog from the useModelEdit signature and ModelsSection — it's no longer needed, cleaner API
  • The comment update in useModelsDerived now 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.

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:M This PR changes 30-99 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