From 81c00868da77d4f5c869e935856f565777529f25 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 23 Nov 2026 11:50:15 -0800 Subject: [PATCH 1/2] fix(models): route tagged ollama names that share a cloud prefix to ollama findProviderFromModel matched provider patterns (/^gpt/, /^mistral/, /^claude/, ...) against any id that no namespace or catalog entry claimed. The browser registers the installed Ollama list, so the editor resolved a local model such as gpt-oss:20b or mistral:latest to Ollama, but the server never holds that list: execution fell through to the cloud pattern and sent the request to OpenAI or Mistral with the user's key, or failed on a missing one. Ollama lists every installed model as name:tag, and no cloud model id carries an Ollama tag, so a bare tagged name is now left unclaimed before patterns run and getProviderFromModel defaults it to Ollama, the same as every other local name. Namespaces and exact catalog ids still win first, so bedrock/...:0 and openrouter/...:free are unaffected. Saved workflows heal without a migration, and the editor, execution, permission checks and the editing validator now agree on the provider. getModelCapabilities re-implemented the pattern scan and kept reporting a cloud provider's capabilities for these names; it now falls back to findProviderFromModel so the two cannot disagree. --- .../editing/validation-models.test.ts | 9 +++++++ apps/sim/providers/models.test.ts | 24 +++++++++++++++++++ apps/sim/providers/models.ts | 24 ++++++++++--------- apps/sim/tools/llm/chat.test.ts | 14 +++++++++++ 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/apps/sim/lib/workflows/editing/validation-models.test.ts b/apps/sim/lib/workflows/editing/validation-models.test.ts index e52b1e40df9..f7ffe08c9c9 100644 --- a/apps/sim/lib/workflows/editing/validation-models.test.ts +++ b/apps/sim/lib/workflows/editing/validation-models.test.ts @@ -109,6 +109,15 @@ describe('model ids no provider declares', () => { expect(errors[0]?.error).toContain('Unknown model id') }) + it.each(['gpt-oss:20b', 'mistral:latest'])( + 'accepts %s, an installed Ollama model sharing a cloud prefix, where it runs on Ollama', + (model) => { + expect(validateModel('router_v2', model)).toEqual({ errors: [], model }) + setEnvFlags({ isHosted: true }) + expect(validateModel('router_v2', model).errors[0]?.error).toContain('Unknown model id') + } + ) + it.each(['hhao/qwen2.5-coder-tools', 'hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M'])( 'accepts a namespaced Ollama library name such as %s', (model) => { diff --git a/apps/sim/providers/models.test.ts b/apps/sim/providers/models.test.ts index 07bfa2118aa..32499c4a9e5 100644 --- a/apps/sim/providers/models.test.ts +++ b/apps/sim/providers/models.test.ts @@ -3,7 +3,9 @@ import { findProviderFromModel, getBaseModelProviders, getHostedModels, + getModelCapabilities, getModelPricing, + getProviderFromModel, getProviderModels, getStaticProviderModels, isCustomModelId, @@ -98,6 +100,28 @@ describe('custom cloud model routing', () => { }) }) +describe('tagged Ollama model names that share a cloud prefix', () => { + it.each(['gpt-oss:20b', 'mistral:latest', 'GPT-OSS:120B', 'hf.co/org/gemini-like:Q4_K_M'])( + 'leaves %s unclaimed, so it runs on Ollama with Ollama capabilities', + (model) => { + expect(findProviderFromModel(model)).toBeNull() + expect(getProviderFromModel(model)).toBe('ollama') + expect(getModelCapabilities(model)).toBeNull() + } + ) + + it('still resolves untagged cloud ids, namespaced tags, and catalog ids by their provider', () => { + expect(findProviderFromModel('gpt-oss-custom')).toBe('openai') + expect(findProviderFromModel('mistral-large-latest')).toBe('mistral') + expect(findProviderFromModel('ollama/gpt-oss:20b')).toBe('ollama') + expect(findProviderFromModel('openrouter/org/model:free')).toBe('openrouter') + expect(findProviderFromModel('bedrock/amazon.nova-lite-v1:0')).toBe('bedrock') + expect(getModelCapabilities('ollama/gpt-oss:20b')).toEqual( + PROVIDER_DEFINITIONS.ollama.capabilities + ) + }) +}) + describe('catalog featured model metadata', () => { it('defines at most one active featured model per provider', () => { for (const provider of Object.values(PROVIDER_DEFINITIONS)) { diff --git a/apps/sim/providers/models.ts b/apps/sim/providers/models.ts index a57bc29b113..ac8996c4d17 100644 --- a/apps/sim/providers/models.ts +++ b/apps/sim/providers/models.ts @@ -6915,6 +6915,9 @@ export function getBaseModelProviders(): Record { ) } +/** An Ollama model reference with its tag: `[host/][namespace/]name:tag`. */ +const OLLAMA_TAGGED_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*:[\w.-]+$/ + /** * The provider that declares `model`, or `null` when none does. Resolves catalog entries and * provider patterns without guessing a fallback provider. @@ -6945,6 +6948,14 @@ export function findProviderFromModel(model: string): ProviderId | null { } } + /** + * Provider patterns are cloud model-name prefixes, and no cloud model id carries an Ollama + * `:tag`. Ollama lists every installed model with its tag (`gpt-oss:20b`, `mistral:latest`), + * so a tagged name a pattern would claim is a local model that only shares a prefix with a + * cloud family. The server never holds the installed list, so the name itself has to say so. + */ + if (OLLAMA_TAGGED_MODEL_NAME.test(normalizedModel)) return null + for (const [providerId, provider] of Object.entries(PROVIDER_DEFINITIONS)) { if (provider.modelPatterns?.some((pattern) => pattern.test(normalizedModel))) { return providerId as ProviderId @@ -6995,17 +7006,8 @@ export function getModelCapabilities(modelId: string): ModelCapabilities | null } } - for (const provider of Object.values(PROVIDER_DEFINITIONS)) { - if (provider.modelPatterns) { - for (const pattern of provider.modelPatterns) { - if (pattern.test(modelId.toLowerCase())) { - return provider.capabilities || null - } - } - } - } - - return null + const providerId = findProviderFromModel(modelId) + return providerId ? PROVIDER_DEFINITIONS[providerId]?.capabilities || null : null } export function getProvidersWithToolUsageControl(): string[] { diff --git a/apps/sim/tools/llm/chat.test.ts b/apps/sim/tools/llm/chat.test.ts index b57bbfcabe3..e1f44184488 100644 --- a/apps/sim/tools/llm/chat.test.ts +++ b/apps/sim/tools/llm/chat.test.ts @@ -37,4 +37,18 @@ describe('llmChatTool.operation', () => { }) ).toThrow('sim-auto has no provider until the model router resolves it') }) + + it.each(['gpt-oss:20b', 'mistral:latest', 'claude-local:7b', 'gemini-tuned/chat:q4_k_m'])( + 'sends a locally installed Ollama model that shares a cloud prefix to Ollama: %s', + (model) => { + const input = llmChatTool.operation.input({ + model, + systemPrompt: 'Translate to French', + context: 'hello', + }) as Record + + expect(input.provider).toBe('ollama') + expect(input.model).toBe(model) + } + ) }) From b71aaac02170427f1bb89317388b1079cb59880a Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 23 Nov 2026 11:59:22 -0800 Subject: [PATCH 2/2] improvement(models): share the ollama model-name rule between the resolver and the validator --- apps/sim/lib/workflows/editing/validation.ts | 4 +--- apps/sim/providers/models.test.ts | 4 ++-- apps/sim/providers/models.ts | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/sim/lib/workflows/editing/validation.ts b/apps/sim/lib/workflows/editing/validation.ts index 57a4b7b0854..ad75b75ae51 100644 --- a/apps/sim/lib/workflows/editing/validation.ts +++ b/apps/sim/lib/workflows/editing/validation.ts @@ -51,6 +51,7 @@ import { isCustomModelId, isEvaluationModel, isKnownModelId, + OLLAMA_MODEL_NAME, suggestModelIdsForUnknownModel, } from '@/providers/models' import { isPiByokOnlyMode } from '@/providers/pi-providers' @@ -589,9 +590,6 @@ function isStoredFile(value: unknown): boolean { return isPlainRecord(value) && Boolean(value.name) && Boolean(value.path) } -/** An Ollama model name: `[namespace/]name[:tag]`, e.g. `llama3.1:8b` or `hf.co/org/model:Q4_K_M`. */ -const OLLAMA_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*(:[\w.-]+)?$/ - /** * Validates a value against its expected subBlock type * Returns validation result with the value or an error diff --git a/apps/sim/providers/models.test.ts b/apps/sim/providers/models.test.ts index 32499c4a9e5..2752fb7593a 100644 --- a/apps/sim/providers/models.test.ts +++ b/apps/sim/providers/models.test.ts @@ -101,8 +101,8 @@ describe('custom cloud model routing', () => { }) describe('tagged Ollama model names that share a cloud prefix', () => { - it.each(['gpt-oss:20b', 'mistral:latest', 'GPT-OSS:120B', 'hf.co/org/gemini-like:Q4_K_M'])( - 'leaves %s unclaimed, so it runs on Ollama with Ollama capabilities', + it.each(['gpt-oss:20b', 'mistral:latest', 'GPT-OSS:120B', 'claude-local:7b'])( + 'leaves %s unclaimed, so it runs on Ollama with no cloud capabilities', (model) => { expect(findProviderFromModel(model)).toBeNull() expect(getProviderFromModel(model)).toBe('ollama') diff --git a/apps/sim/providers/models.ts b/apps/sim/providers/models.ts index ac8996c4d17..ebeae0e515c 100644 --- a/apps/sim/providers/models.ts +++ b/apps/sim/providers/models.ts @@ -6915,8 +6915,8 @@ export function getBaseModelProviders(): Record { ) } -/** An Ollama model reference with its tag: `[host/][namespace/]name:tag`. */ -const OLLAMA_TAGGED_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*:[\w.-]+$/ +/** An Ollama model name, `[host/][namespace/]name[:tag]`: `llama3.1:8b`, `hf.co/org/model:Q4_K_M`. */ +export const OLLAMA_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*(:[\w.-]+)?$/ /** * The provider that declares `model`, or `null` when none does. Resolves catalog entries and @@ -6954,7 +6954,7 @@ export function findProviderFromModel(model: string): ProviderId | null { * so a tagged name a pattern would claim is a local model that only shares a prefix with a * cloud family. The server never holds the installed list, so the name itself has to say so. */ - if (OLLAMA_TAGGED_MODEL_NAME.test(normalizedModel)) return null + if (normalizedModel.includes(':') && OLLAMA_MODEL_NAME.test(normalizedModel)) return null for (const [providerId, provider] of Object.entries(PROVIDER_DEFINITIONS)) { if (provider.modelPatterns?.some((pattern) => pattern.test(normalizedModel))) {