Skip to content

fix(web): identify provider instances by id and skip clean cards on save - #17424

Merged
wangq8 merged 4 commits into
infiniflow:mainfrom
dcc123456:fix/modelprovider-0721
Jul 28, 2026
Merged

wangq8 merged 4 commits into
infiniflow:mainfrom
dcc123456:fix/modelprovider-0721

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

Summary

fix(web): identify provider instances by id and skip clean cards on save

@dosubot dosubot Bot added size:M This PR changes 30-99 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
@dcc123456
dcc123456 requested a review from wangq8 July 27, 2026 07:57
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Provider instance operations now identify instances by stable IDs across request types, URLs, React Query keys, and settings cards. Batch model saves now generate, validate, and dispatch payloads only for modified cards.

Changes

Provider instance updates

Layer / File(s) Summary
Instance ID request contract
web/src/interfaces/request/llm.ts, web/src/utils/api.ts, web/src/hooks/use-llm-request.tsx
Provider instance request payloads, endpoint paths, query keys, fetching, and cache invalidation now use required instance IDs.
Instance detail identifier wiring
web/src/pages/user-setting/setting-model/instance-card/hooks.tsx, .../*instance-card.tsx
Saved provider instance cards pass instance.id to detail-fetching hooks and APIs.
Dirty card save flow
web/src/pages/user-setting/setting-model/index.tsx, .../instance-card/hooks.tsx, .../instance-card/models-section/hooks.ts, .../bedrock-instance-card.tsx, .../somark-instance-card.tsx
Unchanged cards return no payload, model-toggle updates include the instance ID, and batch saves validate and dispatch only dirty cards.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: lynn-inf

Poem

A bunny hops through IDs so clear,
No name-bound paths can interfere.
Unchanged cards rest in clover green,
While dirty saves march in a tidy stream.
“Hop, hop!” says Bun—the cache is clean!

🚥 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 is concise and accurately describes the two main changes: provider instance IDs and skipping clean cards on save.
Description check ✅ Passed The description includes the required Summary section and states the PR purpose, though it is brief and lacks extra context.
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/src/pages/user-setting/setting-model/index.tsx (1)

201-224: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Mark successfully updated special cards as saved.

Saved Bedrock and SoMark cards use apiKind: 'add', so they skip Line 223 even though payload.isDraft is false. Their React Hook Form dirty state and baseline remain stale, causing the next Save to resend the same update. Call ref.markSaved() after every successful non-draft payload, regardless of apiKind.

Proposed fix
-        if (payload.apiKind === 'add') {
+        if (payload.apiKind === 'add') {
           const ret = await addProviderInstance(payload.payload as any);
           if (ret?.code !== 0) {
             return;
           }
           if (payload.isDraft) {
             setNewlySavedInstanceName(payload.instanceName);
           }
         } else {
           const ret = await updateProviderInstance(payload.payload as any);
           if (ret?.code !== 0) {
             return;
           }
-          ref.markSaved();
+        }
+        if (!payload.isDraft) {
+          ref.markSaved();
         }
🤖 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/index.tsx` around lines 201 - 224,
The save loop must mark every successfully persisted non-draft payload as saved,
including special cards using apiKind 'add'. Update the success handling in the
validation loop around addProviderInstance and updateProviderInstance so
ref.markSaved() runs whenever payload.isDraft is false, while retaining
newlySavedInstanceName handling for drafts and stopping on failures.
🤖 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/index.tsx`:
- Around line 179-185: Update the save flow around dirty and validations so
draft refs are validated even when getSavePayload() returns null, while clean
saved cards remain excluded from validation and dispatch. Ensure blank-draft
Save triggers required-name validation instead of returning early, and add
focused coverage for blank-draft Save versus clean saved-card Save.

---

Outside diff comments:
In `@web/src/pages/user-setting/setting-model/index.tsx`:
- Around line 201-224: The save loop must mark every successfully persisted
non-draft payload as saved, including special cards using apiKind 'add'. Update
the success handling in the validation loop around addProviderInstance and
updateProviderInstance so ref.markSaved() runs whenever payload.isDraft is
false, while retaining newlySavedInstanceName handling for drafts and stopping
on failures.
🪄 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: 06b57358-7c6f-4981-8eac-24ee4d672bf6

📥 Commits

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

📒 Files selected for processing (9)
  • web/src/hooks/use-llm-request.tsx
  • web/src/interfaces/request/llm.ts
  • web/src/pages/user-setting/setting-model/index.tsx
  • web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.tsx
  • web/src/pages/user-setting/setting-model/instance-card/hooks.tsx
  • web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
  • web/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsx
  • web/src/pages/user-setting/setting-model/instance-card/somark-instance-card.tsx
  • web/src/utils/api.ts

Comment on lines +179 to +185
const dirty = refs
.map((r) => ({ ref: r, payload: r.getSavePayload() }))
.filter((e) => e.payload !== null);
if (dirty.length === 0) return;

const validations = await Promise.all(
refs.map(async (r) => ({ ref: r, valid: await r.validate() })),
dirty.map(async (e) => ({ ...e, valid: await e.ref.validate() })),

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

Validate blank drafts before filtering null payloads.

A draft with no name returns null at this point, so Save exits without running its required-name validation. Keep clean saved cards excluded, but include draft refs in validation even when they have no dispatchable payload. Add a focused test for blank-draft Save versus clean saved-card Save. As per coding guidelines, “Preserve valid behavior with focused tests.”

🤖 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/index.tsx` around lines 179 - 185,
Update the save flow around dirty and validations so draft refs are validated
even when getSavePayload() returns null, while clean saved cards remain excluded
from validation and dispatch. Ensure blank-draft Save triggers required-name
validation instead of returning early, and add focused coverage for blank-draft
Save versus clean saved-card Save.

Source: Coding guidelines

@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 #17424 — fix(web): identify provider instances by id and skip clean cards on save

Verdict: Approve with one suggestion ⚠️

This is a well-structured refactor with two logical changes:

1. Identify instances by id instead of instance_name

Architecturally sound. Instance names can change (rename feature), but ids are stable. The backend endpoints (GET/PUT /providers/.../instances/<instance_id_or_name>) already support lookup by either id or name (tries get_by_id first, falls back to get_by_provider_id_and_instance_name), so this is fully compatible.

Affected areas (consistently updated):

  • LlmKeys.providerInstance — query key now uses id
  • useFetchProviderInstance — parameter renamed to id
  • useLazyInstanceDetails — parameter renamed to instanceId
  • IShowProviderInstanceRequestParams — instance_name → id
  • IUpdateProviderInstanceRequestBody — id made required (was optional)
  • api.ts — URL routes use id path segment
  • All card components (Bedrock, SoMark, Generic) — pass instance.id
  • useModelMutations — passes id alongside existing fields

2. Skip saving clean cards

The save flow now:

  1. Collects dirty payloads first (getSavePayload() returns null for untouched cards)
  2. Validates only dirty cards
  3. Saves only dirty cards

This avoids unnecessary API calls for unmodified cards. The dirty check in useInstanceSaveState uses both form.formState.isDirty and a rename check (editedNameRef !== instanceName). Individual card components (Bedrock, SoMark) also have their own isDirty guard as a safety net.

⚠️ Suggestion

In index.tsx (setting-model), the save loop iterates over validations:

for (const { ref, payload } of validations) {

This works correctly because validations was built from dirty entries ({ ...e, valid: ... }) and all dirty entries have non-null payloads by definition. However, the if (!payload) continue guard (line 202 in the new code) is now dead code — it was needed when the loop iterated over all refs, but now every entry in validations has a payload. Consider removing it for clarity, or keep it as a defensive guard. Either way is fine — not blocking.

Details:

  • Files changed: 9
  • Additions: 44, Deletions: 44
  • Author: dcc123456

@yingfeng yingfeng added the ci Continue Integration label Jul 27, 2026
@wangq8
wangq8 merged commit 3268938 into infiniflow:main Jul 28, 2026
6 checks passed
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.

3 participants