~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(web): stop the model dropdown coming up empty on page load (#5053)
LearningCircuitbba522d9054b
diff --git a/changelog.d/+model-dropdown-empty-on-load.bugfix.md b/changelog.d/+model-dropdown-empty-on-load.bugfix.mdnew file mode 100644index 0000000000..50549f543a--- /dev/null+++ b/changelog.d/+model-dropdown-empty-on-load.bugfix.md@@ -0,0 +1 @@+Fix the Language Model dropdown frequently coming up empty on the New Research page (requiring a manual click of the refresh button). Three root causes are addressed: the page fired two concurrent `/available-models` requests on every load, which contended against a cold Ollama; Ollama's model-list query used a too-tight 2-second timeout (raised to 5s) whose failure was silently turned into an empty list; and a transient empty result could linger in the client cache. The list now loads once per page and self-heals from a transient empty response.diff --git a/src/local_deep_research/llm/providers/implementations/ollama.py b/src/local_deep_research/llm/providers/implementations/ollama.pyindex 2f20ec3a9e..962f495ca0 100644--- a/src/local_deep_research/llm/providers/implementations/ollama.py+++ b/src/local_deep_research/llm/providers/implementations/ollama.py@@ -80,9 +80,14 @@ class OllamaProvider(BaseLLMProvider):# Get authentication headersheaders = cls._get_auth_headers(api_key=api_key)- # Fetch models using centralized function+ # Fetch models using centralized function.+ # 5s (not 2s) because a cold Ollama — process just started, connection+ # not yet warm, host busy right after a restart — regularly needs more+ # than 2 seconds to answer /api/tags. A timeout here is silently turned+ # into an empty model list, which surfaces to the user as an empty model+ # dropdown, so err on the side of waiting a little longer.models = fetch_ollama_models(- base_url, timeout=2.0, auth_headers=headers+ base_url, timeout=5.0, auth_headers=headers)# Add provider info and format for LLM APIdiff --git a/src/local_deep_research/web/static/js/components/research.js b/src/local_deep_research/web/static/js/components/research.jsindex 72881bf13c..9f37a4c7d6 100644--- a/src/local_deep_research/web/static/js/components/research.js+++ b/src/local_deep_research/web/static/js/components/research.js@@ -989,20 +989,13 @@});}- // Load options data from APIs- Promise.all([- loadModelOptions(false),- loadSearchEngineOptions(false)- ]).then(() => {- // After loading data, initialize dropdowns- const currentProvider = modelProviderSelect ? modelProviderSelect.value : 'OLLAMA';- updateModelOptionsForProvider(currentProvider, false);- }).catch(error => {- SafeLogger.error('Failed to load options:', error);- if (window.ui && window.ui.showAlert) {- window.ui.showAlert('Failed to load model options. Please check your connection and try again.', 'error');- }- });+ // NOTE: model/search-engine options are loaded once by initializeResearch()+ // right after this function returns (its Promise.all also runs+ // setInitialFormValues() + loadSettings() once the data is in). A second+ // load was previously kicked off here too, firing two concurrent+ // /available-models requests on every page load — that self-inflicted+ // contention against a cold Ollama (2s list timeout) is a big reason the+ // model dropdown came up empty. Deliberately not reloading here.}/**@@ -1909,8 +1902,17 @@SafeLogger.log('Using expired cached model data due to API error');resolve(cachedData);} else {- // No cache and API failed - return empty array- SafeLogger.log('API failed and no cache available - returning empty model list');+ // No cache and API failed. Cache an empty list (short TTL,+ // see getCachedData) rather than leaving the cache null:+ // updateModelOptionsForProvider() treats a null cache as+ // "not loaded yet" and reloads, so on a *persistent*+ // failure (HTTP error, expired session, malformed+ // response) it would otherwise recurse into an unbounded+ // request loop. Caching [] bounds the retry to once per+ // EMPTY_CACHE_DURATION — same guard as the empty-success+ // path above.+ SafeLogger.log('API failed and no cache available - caching empty model list briefly');+ cacheData(CACHE_KEYS.MODELS, []);resolve([]);}});@@ -1972,6 +1974,15 @@// In-memory cache to avoid excessive API calls within a sessionconst memoryCache = {};const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes+ // An empty list almost always means a failed/timed-out provider fetch, not a+ // real "zero results", so it should not linger for the full window. We give+ // empties a much shorter TTL rather than skipping the cache write entirely,+ // on purpose: updateModelOptionsForProvider() treats a *null* cache as "not+ // loaded yet" and reloads, so never caching an empty result would turn that+ // into an unbounded reload loop whenever a provider genuinely returns none.+ // Caching the [] (just briefly) keeps getCachedData returning an array, which+ // stops the loop, while still expiring fast so a transient empty self-heals.+ const EMPTY_CACHE_DURATION = 15 * 1000; // 15 secondsfunction cacheData(key, data) {memoryCache[key] = {@@ -1982,7 +1993,12 @@function getCachedData(key) {const cached = memoryCache[key];- if (cached && (Date.now() - cached.timestamp < CACHE_DURATION)) {+ if (!cached) {+ return null;+ }+ const isEmpty = Array.isArray(cached.data) && cached.data.length === 0;+ const maxAge = isEmpty ? EMPTY_CACHE_DURATION : CACHE_DURATION;+ if (Date.now() - cached.timestamp < maxAge) {return cached.data;}return null;diff --git a/tests/js/components/research.test.js b/tests/js/components/research.test.jsindex ad040157b5..3372c77a8f 100644--- a/tests/js/components/research.test.js+++ b/tests/js/components/research.test.js@@ -28,6 +28,7 @@ import '@js/components/custom_dropdown.js'; // setupCustomDropdown (used by initconst START_RESEARCH = '/api/start_research';const CHAT_SESSIONS = '/api/chat/sessions';+const AVAILABLE_MODELS = '/settings/api/available-models';function buildForm() {document.body.innerHTML = `@@ -66,6 +67,12 @@ function buildForm() {}let fetchMock;+// Number of GET /available-models requests fired synchronously during init.+// Both loadModelOptions(false) call sites run synchronously inside+// initializeResearch (before any await), so a synchronous capture right after+// dispatch deterministically distinguishes "loaded once" (1) from the old+// duplicate-concurrent-load bug (2).+let initAvailableModelsCalls;beforeAll(async () => {// Keep init's model/search-engine loads and any submit request happy; the@@ -98,6 +105,11 @@ beforeAll(async () => {// handler and the query + model validators, applies the advanced-panel// state.document.dispatchEvent(new Event('DOMContentLoaded'));+ // Capture the model-list request count synchronously, before any async+ // reload path can add to it (see initAvailableModelsCalls above).+ initAvailableModelsCalls = fetchMock.mock.calls.filter(+ ([u]) => u === AVAILABLE_MODELS+ ).length;// Let the fire-and-forget model/search-engine loads settle.await Promise.resolve();await Promise.resolve();@@ -217,3 +229,13 @@ describe('research form — model-required guard', () => {expect(document.getElementById('query').getAttribute('aria-invalid')).toBe('true');});});++describe('research form — model list loading', () => {+ it('fetches the model list only once per page load (no duplicate concurrent request)', () => {+ // Regression guard: initializeResearch() and setupEventListeners() each+ // used to fire their own loadModelOptions(false), landing two concurrent+ // /available-models requests on every load and contending for a cold+ // Ollama — a primary reason the model dropdown came up empty.+ expect(initAvailableModelsCalls).toBe(1);+ });+});diff --git a/tests/llm_providers/test_ollama_provider.py b/tests/llm_providers/test_ollama_provider.pyindex e80e141855..f214f73930 100644--- a/tests/llm_providers/test_ollama_provider.py+++ b/tests/llm_providers/test_ollama_provider.py@@ -154,6 +154,28 @@ class TestOllamaListModels:assert isinstance(result, list)assert len(result) == 2+ def test_list_models_uses_generous_timeout_for_cold_ollama(self):+ """Passes a generous (>=5s) timeout when listing models.++ A cold Ollama (just started / connection not yet warm) regularly needs+ more than 2s to answer /api/tags, and a timeout is silently turned into+ an empty model list — which surfaces to the user as an empty model+ dropdown. Guard against a revert to the too-tight 2s value.+ """+ with patch(+ "local_deep_research.utilities.llm_utils.fetch_ollama_models"+ ) as mock_fetch:+ mock_fetch.return_value = []++ OllamaProvider.list_models_for_api(+ base_url="http://localhost:11434"+ )++ assert mock_fetch.call_count == 1+ _, kwargs = mock_fetch.call_args+ assert kwargs.get("timeout") is not None+ assert kwargs["timeout"] >= 5.0+def test_list_models_empty_without_url(self):"""Returns empty list when URL not provided."""# No base_url passed - should return empty list