Skip to content

fix(models-section): defer auto-fetch catalog until base_url is set for self-hosted providers - #17804

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/models-section-base-url-gate
Aug 6, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/models-section-base-url-gate

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

Summary

fix(models-section): defer auto-fetch catalog until base_url is set for self-hosted providers

@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 Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The models section now preserves missing base URLs during credential resolution. Catalog loading checks provider-specific credentials and responds to credential and instance-detail changes.

Changes

Models catalog credential flow

Layer / File(s) Summary
Credential resolution and catalog loading
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts
ResolvedCreds.baseUrl can be undefined. Catalog loading resolves credentials inside the effect, validates VolcEngine API keys and required base URLs, and updates its dependencies.
Models section catalog wiring
web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
ModelsSection passes the current base URL and instanceDetailsLoaded state to useModelsCatalog.

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

Possibly related PRs

Suggested reviewers: haruko386

Poem

A rabbit checks the keys with care,
And keeps the missing URL bare.
The catalog waits, then hops ahead,
When instance details have been read.
Fresh models bloom in rows of light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change: delaying catalog auto-fetch until base_url is configured for self-hosted providers.
Description check ✅ Passed The description uses the required Summary heading and clearly states the purpose of the change.
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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4d997bc and 1ac32eb.

📒 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

Comment on lines 249 to +270
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,
]);

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

🧩 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/src

Repository: 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/**/*.ts

Repository: 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.

@dcc123456
dcc123456 requested a review from wangq8 August 5, 2026 08:47

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

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:

  1. string | undefined for baseUrl: Clever use of undefined vs 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.

  2. Readiness check moved inside the effect: The comment about effect ordering (useFormResetOnDetailsLoad running before this effect) justifies why resolveCreds() 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.

  3. Backward compatible: The optional instanceDetailsLoaded prop already exists in the ModelsSectionProps interface and is passed through from saved-mode-card.tsx. No breaking changes.

Minor suggestions:

  1. Type assertion as any: On line 214 of hooks.ts, the api_key: apiKey as any cast echoes the existing pattern (the original code already had api_key: apiKey with implicit typing). This is consistent — no issue.

  2. The deps array now includes baseUrlValue and instanceDetailsLoaded alongside apiKeyValue. Consider whether rapid changes to baseUrlValue (e.g. user typing a long URL) could cause multiple re-fetches. The hasAutoFetchedRef.current guard prevents duplicate fetches once the first one triggers, so this should be fine.

Approved.

@wangq8 wangq8 added dependencies Pull requests that update a dependency file ci Continue Integration and removed dependencies Pull requests that update a dependency file labels Aug 5, 2026
@wangq8
wangq8 merged commit d5000de into infiniflow:main Aug 6, 2026
15 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.

2 participants