Repository navigation
fix(web): identify provider instances by id and skip clean cards on save - #17424
Conversation
📝 WalkthroughWalkthroughProvider 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. ChangesProvider instance updates
Estimated code review effort: 3 (Moderate) | ~20 minutes 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
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 winMark successfully updated special cards as saved.
Saved Bedrock and SoMark cards use
apiKind: 'add', so they skip Line 223 even thoughpayload.isDraftis false. Their React Hook Form dirty state and baseline remain stale, causing the next Save to resend the same update. Callref.markSaved()after every successful non-draft payload, regardless ofapiKind.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
📒 Files selected for processing (9)
web/src/hooks/use-llm-request.tsxweb/src/interfaces/request/llm.tsweb/src/pages/user-setting/setting-model/index.tsxweb/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.tsxweb/src/pages/user-setting/setting-model/instance-card/hooks.tsxweb/src/pages/user-setting/setting-model/instance-card/models-section/hooks.tsweb/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsxweb/src/pages/user-setting/setting-model/instance-card/somark-instance-card.tsxweb/src/utils/api.ts
| 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() })), |
There was a problem hiding this comment.
🎯 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
left a comment
There was a problem hiding this comment.
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 usesiduseFetchProviderInstance— parameter renamed toiduseLazyInstanceDetails— parameter renamed toinstanceIdIShowProviderInstanceRequestParams—instance_name→idIUpdateProviderInstanceRequestBody—idmade required (was optional)api.ts— URL routes useidpath segment- All card components (Bedrock, SoMark, Generic) — pass
instance.id useModelMutations— passesidalongside existing fields
2. Skip saving clean cards
The save flow now:
- Collects dirty payloads first (
getSavePayload()returns null for untouched cards) - Validates only dirty cards
- 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
Summary
fix(web): identify provider instances by id and skip clean cards on save