fix(providers): preserve add-provider form selection on background reload (#1838)

loadProviders dropped the __add_provider__ sentinel selection during a
background provider refresh because it is not a real provider id, which
navigated users out of the in-progress Add provider form and discarded
their unsaved input. Preserve the sentinel alongside real provider ids.

Fixes #1765
This commit is contained in:
Ibrahim Khan
2026-06-26 19:38:09 +03:00
committed by GitHub
parent f4e90ca232
commit 903e8ecbb0
2 changed files with 26 additions and 1 deletions
@@ -389,6 +389,25 @@ describe('useConfigStore provider persistence', () => {
expect(state.currentVariant).toBe('fast');
});
test('provider reload preserves the add-provider sentinel selection', async () => {
// The user has opened the "Add provider" form, which sets selectedProviderId
// to the sentinel. A background provider refresh must not navigate them away
// (and discard their unsaved input) just because the sentinel is not a real
// provider id. See issue #1765.
useConfigStore.setState({
activeDirectoryKey: DIRECTORY,
currentProviderId: 'live',
currentModelId: 'live-model',
selectedProviderId: '__add_provider__',
directoryScoped: {},
});
liveProviderId = 'live';
await useConfigStore.getState().loadProviders({ source: 'test:add-provider' });
expect(useConfigStore.getState().selectedProviderId).toBe('__add_provider__');
});
test('setAgent applies settings default variant for an agent configured model', () => {
useSessionUIStore.setState({ currentSessionId: 'ses_agent_default_variant' });
useConfigStore.setState({
+7 -1
View File
@@ -30,6 +30,9 @@ const STT_SILENCE_HOLD_MS_MAX = 10000;
const FALLBACK_PROVIDER_ID = "opencode";
const FALLBACK_MODEL_ID = "big-pickle";
// Sentinel selectedProviderId used by the providers UI while the "Add provider"
// form is open. It is intentionally not a real provider id.
const ADD_PROVIDER_SENTINEL = "__add_provider__";
const GIT_UTILITY_PROVIDER_ID = "zen";
const GIT_UTILITY_PREFERRED_MODEL_ID = "big-pickle";
const PROVIDER_CONFIG_REFRESH_CONCURRENCY = 4;
@@ -1573,7 +1576,10 @@ export const useConfigStore = create<ConfigStore>()(
const currentSelectedProviderId = state.activeDirectoryKey === directoryKey
? state.selectedProviderId
: baseSnapshot.selectedProviderId;
const selectedProviderId = processedProviders.some((provider) => provider.id === currentSelectedProviderId)
// Preserve the add-provider sentinel so a background refresh does not
// navigate the user out of the in-progress add-provider form (issue #1765).
const selectedProviderId = currentSelectedProviderId === ADD_PROVIDER_SENTINEL
|| processedProviders.some((provider) => provider.id === currentSelectedProviderId)
? currentSelectedProviderId
: (resolvedModel?.providerId ?? processedProviders[0]?.id ?? "");