Skip to content

refactor: remove localStorage persistence for system model settings - #16934

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:refactor/remove-localstorage-system-model-settings
Jul 15, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:refactor/remove-localstorage-system-model-settings

Conversation

@euvre

@euvre euvre commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Remove the localStorage-based persistence layer from the system model settings page. The localStorage workaround was originally added to handle the case where the Go backend hadn't been rebuilt yet and didn't return TTS/ASR/VLM defaults from the API.

Now that the backend API (GET /api/v1/models/default) is the source of truth for all model types (including ASR/VLM/TTS), the localStorage persistence is redundant and introduces unnecessary complexity. This PR:

  • Removes the STORAGE_KEY constant, loadPersistedValues, and savePersistedValues helper functions
  • Initializes persistedValues state directly from defaultModelDictionary instead of localStorage
  • Syncs state with the API response via useEffect instead of localStorage
  • Simplifies the resolution order to: API response → empty string (fallback)

The system model settings page previously persisted model selections to
localStorage as a workaround for when the Go backend hadn't been rebuilt
to return TTS/ASR/VLM defaults from the API. Now that the backend API
(GET /api/v1/models/default) is the source of truth for all model types,
the localStorage persistence layer is redundant.

- Remove STORAGE_KEY constant, loadPersistedValues, and savePersistedValues
- Initialize persistedValues state from defaultModelDictionary
- Sync state with API response via useEffect instead of localStorage
- Simplify resolution order: API response -> empty string fallback
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code 🧰 typescript Pull requests that update Typescript code labels Jul 15, 2026
@euvre euvre added the ci Continue Integration label Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7aea1aeb-478b-42ef-b1df-fde8b1876ee5

📥 Commits

Reviewing files that changed from the base of the PR and between a6da9b4 and d206773.

📒 Files selected for processing (1)
  • web/src/pages/agent/form/agent-form/index.tsx

📝 Walkthrough

Walkthrough

SystemSetting now derives model selections from API-backed defaults without localStorage persistence. The agent form also replaces the hardcoded visual input file label with an internationalized translation.

Changes

System settings and agent form

Layer / File(s) Summary
API-backed selection state
web/src/pages/user-setting/setting-model/layout/system-setting.tsx
Removes localStorage persistence, reads values from defaultModelDictionary with empty-string fallbacks, and routes changes through setDefaultModel.
Localized visual input label
web/src/pages/agent/form/agent-form/index.tsx
Uses t('flow.visualInputFile') for the visual input file field label.

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

Possibly related PRs

Poem

A bunny hops through settings bright,
API values guide the light.
No storage stash beneath the floor,
Translated labels bloom once more,
Clean defaults nibble worries away!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: removing localStorage persistence from system model settings.
Description check ✅ Passed The description includes the required Summary and provides relevant background plus a clear summary 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.

@euvre
euvre requested a review from dcc123456 July 15, 2026 04:10

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

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/layout/system-setting.tsx (1)

120-126: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use nullish coalescing to prevent optimistic UI updates from failing on clear.

The || operator causes an empty string ('') to evaluate as falsy. If a user clears an optional model field, handleFieldChange sets its local state to ''. The || operator then falls back to defaultModelDictionary[field], instantly reverting the UI to the old value until the API call resolves.

Using ?? ensures that explicitly set empty strings are respected. The proposed fix below also updates the resolution order comment to accurately reflect the presence of the local state.

🐛 Proposed fix
-  // Resolution order (same for ALL model types including ASR/VLM/TTS):
-  //   1. API response (from Go backend GET /api/v1/models/default)
-  //   2. empty string (fallback)
+  // Resolution order (same for ALL model types including ASR/VLM/TTS):
+  //   1. Local state (optimistic updates)
+  //   2. API response (from Go backend GET /api/v1/models/default)
+  //   3. empty string (fallback)
   const getValue = useCallback(
     (field: string) =>
-      persistedValues[field] || defaultModelDictionary[field] || '',
+      persistedValues[field] ?? defaultModelDictionary[field] ?? '',
     [persistedValues, defaultModelDictionary],
   );
🤖 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/layout/system-setting.tsx` around
lines 120 - 126, Update getValue in the system-setting component to use nullish
coalescing instead of truthiness-based fallback, so explicitly cleared
empty-string values from persistedValues remain visible. Revise the adjacent
resolution-order comment to reflect local state taking precedence, followed by
the default model dictionary and empty-string fallback.
🧹 Nitpick comments (1)
web/src/pages/user-setting/setting-model/layout/system-setting.tsx (1)

87-95: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Rename persistedValues to reflect its new purpose.

Since the state is no longer persisted to localStorage and merely mirrors the API response for optimistic updates, the name persistedValues is now misleading. Consider renaming it to something like modelSelections or localSelections.

💡 Proposed rename (requires changes in other functions)
-  const [persistedValues, setPersistedValues] = useState<
+  const [modelSelections, setModelSelections] = useState<
     Record<string, string>
   >(defaultModelDictionary);

   useEffect(() => {
-    setPersistedValues(defaultModelDictionary);
+    setModelSelections(defaultModelDictionary);
   }, [defaultModelDictionary]);

You will also need to update the downstream references in handleFieldChange and getValue:

// In handleFieldChange:
setModelSelections((prev) => ({ ...prev, [field]: value || '' }));

// In getValue:
modelSelections[field] ?? defaultModelDictionary[field] ?? ''
🤖 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/layout/system-setting.tsx` around
lines 87 - 95, Rename the persistedValues state and setPersistedValues setter to
modelSelections and setModelSelections, and update all references including
handleFieldChange, getValue, and the defaultModelDictionary synchronization
effect. Preserve the existing optimistic update and API-default fallback
behavior.
🤖 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.

Outside diff comments:
In `@web/src/pages/user-setting/setting-model/layout/system-setting.tsx`:
- Around line 120-126: Update getValue in the system-setting component to use
nullish coalescing instead of truthiness-based fallback, so explicitly cleared
empty-string values from persistedValues remain visible. Revise the adjacent
resolution-order comment to reflect local state taking precedence, followed by
the default model dictionary and empty-string fallback.

---

Nitpick comments:
In `@web/src/pages/user-setting/setting-model/layout/system-setting.tsx`:
- Around line 87-95: Rename the persistedValues state and setPersistedValues
setter to modelSelections and setModelSelections, and update all references
including handleFieldChange, getValue, and the defaultModelDictionary
synchronization effect. Preserve the existing optimistic update and API-default
fallback behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55df5d84-cf82-4f4a-a686-aba6fca52176

📥 Commits

Reviewing files that changed from the base of the PR and between 14d361a and ad61e56.

📒 Files selected for processing (1)
  • web/src/pages/user-setting/setting-model/layout/system-setting.tsx

@codecov

codecov Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (5cf95d2) to head (d206773).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16934      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The persistedValues state was a redundant mirror of defaultModelDictionary.
Since useSetDefaultModel invalidates the query on success and React Query
automatically refetches, the local state layer adds no value.

- Remove persistedValues useState/useEffect and getValue wrapper
- Read directly from defaultModelDictionary with ?? fallback
- Simplify handleFieldChange to a single setDefaultModel call
Replace hardcoded 'Visual Input File' string with t('flow.visualInputFile')
@wangq8
wangq8 merged commit 5184373 into infiniflow:main Jul 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code 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