Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): fix stale client mirror and empty-refresh bug

[._.]/ Adam Eivybe0d8f794679
diff --git a/client/src/utils/providers.js b/client/src/utils/providers.js
index 147cd65002..4737819a9e 100644
--- a/client/src/utils/providers.js
+++ b/client/src/utils/providers.js
@@ -414,17 +414,21 @@ export const enabledApiProviderFilter = (provider) => Boolean(provider?.enabled)
export const isProcessProvider = (provider) => isCliProvider(provider) || isTuiProvider(provider);
/**
- * A `claude` CLI/TUI provider is "Ollama-backed" — the Claude Ollama pattern —
- * when it carries the `ollamaBacked` marker or its ANTHROPIC_BASE_URL points at
- * an Ollama daemon. Such a provider runs the Claude Code harness but generates
- * tokens locally, so its model list is refreshed from Ollama (including the TUI
- * variant, which the server refreshes via the `type==='tui' && ollamaBacked`
- * branch). MIRROR of `isOllamaBackedProvider` in server/lib/aiToolkit/providers.js.
- * @param {{ollamaBacked?:boolean,envVars?:Record<string,string>}} provider
+ * Whether `provider` is served by an Ollama daemon rather than its nominal
+ * cloud/CLI backend: the built-in `ollama` API provider itself (id match), an
+ * `api`-type provider whose `endpoint` points at Ollama, or the Claude-Ollama
+ * CLI/TUI pattern — a `claude` process carrying the `ollamaBacked` marker or an
+ * `ANTHROPIC_BASE_URL` pointed at Ollama, which runs the Claude Code harness but
+ * generates tokens locally, so its model list is refreshed from Ollama
+ * (including the TUI variant, which the server refreshes via the
+ * `type==='tui' && ollamaBacked` branch). MIRROR of `isOllamaBackedProvider` in
+ * server/lib/aiToolkit/providers.js.
+ * @param {{id?:string,endpoint?:string,ollamaBacked?:boolean,envVars?:Record<string,string>}} provider
*/
export const isOllamaBackedProvider = (provider) => {
+ if (provider?.id === 'ollama') return true;
if (provider?.ollamaBacked === true) return true;
- const base = String(provider?.envVars?.ANTHROPIC_BASE_URL || '');
+ const base = String(provider?.envVars?.ANTHROPIC_BASE_URL || provider?.endpoint || '');
return /:11434\b/.test(base) || /ollama/i.test(base);
};
diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.js
index 8a66de0bdf..5db172cf54 100644
--- a/client/src/utils/providers.test.js
+++ b/client/src/utils/providers.test.js
@@ -117,9 +117,16 @@ describe('provider type predicates', () => {
// inferred from ANTHROPIC_BASE_URL (port 11434 or "ollama" host)
expect(isOllamaBackedProvider({ envVars: { ANTHROPIC_BASE_URL: 'http://localhost:11434' } })).toBe(true);
expect(isOllamaBackedProvider({ envVars: { ANTHROPIC_BASE_URL: 'http://my-ollama:1234' } })).toBe(true);
+ // the built-in `ollama` API provider itself (endpoint carries the daemon
+ // URL, not envVars) — id match regardless of endpoint/envVars shape
+ expect(isOllamaBackedProvider({ id: 'ollama', type: 'api', endpoint: 'http://localhost:11434/v1' })).toBe(true);
+ // any other api-type provider whose endpoint points at Ollama
+ expect(isOllamaBackedProvider({ id: 'local-llm', type: 'api', endpoint: 'http://192.168.1.5:11434/v1' })).toBe(true);
+ expect(isOllamaBackedProvider({ id: 'renamed', type: 'api', endpoint: 'https://my-ollama-box.example.com/v1' })).toBe(true);
// plain claude TUI / cloud providers are NOT ollama-backed
expect(isOllamaBackedProvider({ type: 'tui', command: 'claude' })).toBe(false);
expect(isOllamaBackedProvider({ type: 'cli', command: 'claude', envVars: {} })).toBe(false);
+ expect(isOllamaBackedProvider({ id: 'anthropic', type: 'api', endpoint: 'https://api.anthropic.com' })).toBe(false);
expect(isOllamaBackedProvider(null)).toBe(false);
});
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index 9d39638fd2..775709ddf2 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -659,7 +659,14 @@ export function createProviderService(config = {}) {
return null;
}
- let models = [];
+ // `null` = no refreshable branch matched below (provider type/shape isn't
+ // refreshable — the pre-existing no-op case); an array = a completed
+ // fetch, which may legitimately be empty (e.g. an Ollama-backed provider
+ // whose only installed model was just deleted). Only the `null` sentinel
+ // means "nothing to persist" — a `.length === 0` check here would also
+ // swallow that legitimate empty result and leave a deleted model stuck
+ // in the provider's persisted list.
+ let models = null;
try {
if (provider.type === 'api') {
@@ -677,7 +684,7 @@ export function createProviderService(config = {}) {
return null;
}
- if (!models || models.length === 0) {
+ if (models === null) {
return null;
}
diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.js
index 8a5ab436e4..b3d1575dd7 100644
--- a/server/lib/aiToolkit/providers.test.js
+++ b/server/lib/aiToolkit/providers.test.js
@@ -783,6 +783,28 @@ describe('Provider Service', () => {
const result = await providerService.refreshProviderModels(p.id);
expect(result).toBeNull();
});
+
+ it('persists a legitimately empty model list rather than treating it as a failed fetch', async () => {
+ // The last installed Ollama model was just deleted — /api/tags succeeds
+ // with zero entries. This must NOT collapse into the same `null` result
+ // as an unreachable endpoint, or a deleted model stays stuck in the
+ // provider's persisted list forever.
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => ({ models: [] }),
+ }));
+
+ const p = await providerService.createProvider({
+ name: 'Ollama',
+ type: 'api',
+ endpoint: 'http://localhost:11434',
+ models: ['llama3.2'], // stale — the model was just deleted
+ });
+
+ const updated = await providerService.refreshProviderModels(p.id);
+ expect(updated).not.toBeNull();
+ expect(updated.models).toEqual([]);
+ });
});
describe('reserved-key prototype safety (#2521)', () => {