Skip to content

fix: auto-select usable provider when local model is stale#126

Open
nkmohit wants to merge 2 commits intoTHU-MAIC:mainfrom
nkmohit:fix/llm-autoselect-unusable-provider
Open

fix: auto-select usable provider when local model is stale#126
nkmohit wants to merge 2 commits intoTHU-MAIC:mainfrom
nkmohit:fix/llm-autoselect-unusable-provider

Conversation

@nkmohit
Copy link

@nkmohit nkmohit commented Mar 19, 2026

Summary

Fixes LLM auto-selection when stale localStorage keeps a non-empty but unusable provider/model selection. Previously, fetchServerProviders() only auto-selected a server-configured LLM when modelId was empty, so persisted selections like openai:gpt-4o could remain active even when that provider had no client API key and no server-side configuration.

Related Issues

Fixes #118

Changes

  • Added a small isProviderUsable(...) check inside fetchServerProviders() in lib/store/settings.ts
  • Reused the same provider usability rule already used elsewhere in the repo:
    • provider does not require an API key, or has a client API key, or is server-configured
    • provider has at least one model
    • provider has a usable base URL source
  • Changed LLM auto-select so it runs when:
    • modelId is empty, or
    • the currently selected provider is unusable
  • Ensured fallback auto-selection only chooses usable server-configured providers

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD or build changes

Verification

Steps to reproduce / test

  1. Configure the server so that google is server-configured and openai is not
  2. Start the app on main
  3. Force stale localStorage state in the browser:
    • providerId = openai
    • modelId = gpt-4o
    • no OpenAI client API key
  4. Reload the app and confirm the stale selection remains on main
  5. Switch to this fix branch, apply the same stale localStorage state, and reload
  6. Confirm the selection auto-switches to the usable server-configured provider

What you personally verified

  • Verified the bug was real:
    • On main, with only google server-configured, I forced stale localStorage to:
      • providerId = openai
      • modelId = gpt-4o
    • After reload, it stayed:
      • openai gpt-4o
    • That confirmed the old auto-select logic was too narrow
  • Verified the fix:
    • On fix/llm-autoselect-unusable-provider, with the same stale localStorage setup, the app auto-switched to:
      • google gemini-3.1-pro-preview
  • Ran pnpm exec tsc --noEmit
  • Ran pnpm lint lib/store/settings.ts

Evidence

  • CI passes (pnpm check && pnpm lint && npx tsc --noEmit)
  • Manually tested locally
  • Screenshots / recordings attached (if UI changes)
    before (main): openai gpt-4o
    after (fix branch): google gemini-3.1-pro-preview
Screenshot 2026-03-19 at 4 05 06 PM

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have added/updated documentation as needed
  • My changes do not introduce new warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LLM auto-select doesn't override unusable provider from localStorage

1 participant