Repository navigation
fix(models-section): defer auto-fetch catalog until base_url is set for self-hosted providers - #17804
Conversation
…or self-hosted providers
📝 WalkthroughWalkthroughThe models section now preserves missing base URLs during credential resolution. Catalog loading checks provider-specific credentials and responds to credential and instance-detail changes. ChangesModels catalog credential flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 249-270: Update the auto-fetch useEffect to return early when
instanceDetailsLoaded is false, before calling resolveCreds or marking
hasAutoFetchedRef.current. Keep the existing credential readiness checks and
allow the effect to retry after instanceDetailsLoaded becomes true.
🪄 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: 8cacb97c-7d9d-4658-bf6a-669795055c8f
📒 Files selected for processing (2)
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.tsweb/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
| useEffect(() => { | ||
| if (hasAutoFetchedRef.current) return; | ||
| if (hideActions) return; | ||
| if (!providerName) return; | ||
| if (!credsReady) return; | ||
|
|
||
| const creds = resolveCreds(); | ||
| const hasBaseUrlField = creds.baseUrl !== undefined; | ||
| const ready = | ||
| (!requiresApiKey || !!creds.apiKey) && | ||
| (!hasBaseUrlField || !!creds.baseUrl); | ||
| if (!ready) return; | ||
| hasAutoFetchedRef.current = true; | ||
| handleListModels(); | ||
| // oxlint-disable-next-line react/exhaustive-deps | ||
| }, [providerName, instanceName, hideActions, credsReady]); | ||
| }, [ | ||
| providerName, | ||
| instanceName, | ||
| hideActions, | ||
| apiKeyValue, | ||
| baseUrlValue, | ||
| instanceDetailsLoaded, | ||
| ]); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the detail-load signal, form reset, and ModelsSection callers.
rg -n -C 10 --glob '*.{ts,tsx}' \
'\b(instanceDetailsLoaded|useFormResetOnDetailsLoad)\b' web/src
rg -n -C 6 --glob '*.{ts,tsx}' \
'(<ModelsSection\b|instanceDetailsLoaded\s*=)' web/srcRepository: infiniflow/ragflow
Length of output: 42825
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the relevant hook section and credential resolver.
sed -n '136,275p' web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
sed -n '1,122p' web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
rg -n -C 20 'function useResolveCreds|const useResolveCreds|resolvedBaseUrl|base_url|apiKey|baseUrl' web/src/pages/user-setting/setting-model/instance-card/models-section web/src/pages/user-setting/setting-model/instance-card/**/*.tsRepository: infiniflow/ragflow
Length of output: 50375
Gate the auto-fetch while instanceDetailsLoaded is false.
Run, resolveCreds() can return baseUrl: undefined from the persisted instance while fv.base_url is still absent. The effect then calls handleListModels() with no base_url and marks hasAutoFetchedRef.current, so the later details-load form reset cannot retry with the resolved URL.
🤖 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 249 - 270, Update the auto-fetch useEffect to return early when
instanceDetailsLoaded is false, before calling resolveCreds or marking
hasAutoFetchedRef.current. Keep the existing credential readiness checks and
allow the effect to retry after instanceDetailsLoaded becomes true.
wangq8
left a comment
There was a problem hiding this comment.
Nice fix. This addresses a real UX issue where self-hosted providers (Ollama, Xinference, LocalAI) would fire a doomed catalog request before the user had a chance to enter their base URL.
What I like:
-
string | undefinedforbaseUrl: Clever use ofundefinedvs empty string to distinguish "form has no base_url field at all" (e.g. VolcEngine, Google Cloud) from "field exists but is empty" (Ollama, etc.). This lets the readiness gate apply only to providers that actually have the field. -
Readiness check moved inside the effect: The comment about effect ordering (
useFormResetOnDetailsLoadrunning before this effect) justifies whyresolveCreds()is called inside the effect rather than during render. For saved cards where the form gets reset, reading during render would see stale (pre-reset) values. This is a subtle but important detail — thanks for documenting it. -
Backward compatible: The optional
instanceDetailsLoadedprop already exists in theModelsSectionPropsinterface and is passed through fromsaved-mode-card.tsx. No breaking changes.
Minor suggestions:
-
Type assertion
as any: On line 214 of hooks.ts, theapi_key: apiKey as anycast echoes the existing pattern (the original code already hadapi_key: apiKeywith implicit typing). This is consistent — no issue. -
The deps array now includes
baseUrlValueandinstanceDetailsLoadedalongsideapiKeyValue. Consider whether rapid changes tobaseUrlValue(e.g. user typing a long URL) could cause multiple re-fetches. ThehasAutoFetchedRef.currentguard prevents duplicate fetches once the first one triggers, so this should be fine.
Approved.
Summary
fix(models-section): defer auto-fetch catalog until base_url is set for self-hosted providers