Skip to content

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

@wyuc

Description

@wyuc

Description

When fetchServerProviders() returns server-configured providers, the LLM auto-select logic only triggers when state.modelId is empty (line 887). But users with stale localStorage data may have a non-empty modelId pointing to a provider with no API key (neither client-provided nor server-configured).

How It Happens

  1. User previously selected a model like openai:gpt-4o (stored in localStorage)
  2. The v0→v1 migration only clears modelId when it's exactly gpt-4o-mini (line 952-955), missing other model IDs
  3. fetchServerProviders() runs but skips auto-select because modelId is not empty
  4. Generation APIs use the stale openai:gpt-4o → server has no OpenAI key → "API key required for provider: openai"

Root Cause

lib/store/settings.ts line 887 — auto-select condition !state.modelId is too narrow. It should also trigger when the current provider is not usable (no client key AND not server-configured).

Suggested Fix

In fetchServerProviders(), also auto-select when the current providerId has requiresApiKey but has no client key and is not isServerConfigured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions