Skip to content

Commit 3e6735b

Browse files
committed
fix(models): accept local ollama models in fallback rows like the model field
Editing validation accepted an installed Ollama model (an unclaimed Ollama-shaped name where Ollama is reachable) in a block's model field but still rejected the same name in its fallback rows, although the fallback picker offers it and execution runs it on Ollama. Writing back a workflow saved with such a fallback through the workflow-state API failed outright, and editing or re-sending the rows failed through mothership edits and workflow-as-code. Both sites now ask one isRunnableModelId predicate. Also tidies follow-ups from the same changes: the MODEL_OPTION_SOURCES note no longer cites bare Ollama names, the browser-only Ollama check in blocks/utils is renamed so it no longer shares a name with the server's isOllamaAvailable, the model combobox uses DEFAULT_BLOCK_MODEL instead of its own copy, and two comments are reflowed.
1 parent ce51264 commit 3e6735b

7 files changed

Lines changed: 85 additions & 34 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/combobox/combobox.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/
1919
import type { SubBlockConfig } from '@/blocks/types'
2020
import { useDebounce } from '@/hooks/use-debounce'
2121
import { usePermissionConfig } from '@/hooks/use-permission-config'
22+
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'
2223
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
2324
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
2425

2526
/**
2627
* Constants for ComboBox component behavior
2728
*/
28-
const DEFAULT_MODEL = 'claude-sonnet-5-5'
2929
const ZOOM_FACTOR_BASE = 0.96
3030
const MIN_ZOOM = 0.1
3131
const MAX_ZOOM = 1
@@ -308,7 +308,7 @@ export const ComboBox = memo(function ComboBox({
308308

309309
/**
310310
* Determines the default option value to use.
311-
* Priority: explicit defaultValue > DEFAULT_MODEL for model field > first option
311+
* Priority: explicit defaultValue > DEFAULT_BLOCK_MODEL for model field > first option
312312
*/
313313
const defaultOptionValue = useMemo(() => {
314314
if (defaultValue !== undefined) {
@@ -322,7 +322,7 @@ export const ComboBox = memo(function ComboBox({
322322

323323
if (subBlockId === 'model') {
324324
const defaultModelOption = evaluatedOptions.find(
325-
(opt) => getOptionValue(opt) === DEFAULT_MODEL
325+
(opt) => getOptionValue(opt) === DEFAULT_BLOCK_MODEL
326326
)
327327
if (defaultModelOption) {
328328
return getOptionValue(defaultModelOption)

‎apps/sim/blocks/utils.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ export function getAgentModelOptions() {
265265
* catalog, and whether each offers Auto (so accepts sim-auto on hosted Sim).
266266
*
267267
* {@link getAgentModelOptions} is deliberately absent: the agent's model field also takes
268-
* bare Ollama names, free-typed ids (Bedrock inference profiles, fine-tunes) and retired
269-
* ids, so validation passes its values through unchanged.
268+
* free-typed ids (Bedrock inference profiles, fine-tunes) and retired ids, so validation
269+
* passes its values through unchanged.
270270
*/
271271
export const MODEL_OPTION_SOURCES: ReadonlyMap<unknown, { auto: boolean }> = new Map([
272272
[getModelOptions, { auto: false }],
@@ -352,12 +352,12 @@ function getProviderFromStore(model: string): string | null {
352352
}
353353

354354
/**
355-
* Whether an Ollama instance is available. `isOllamaConfigured` reads the
355+
* Whether this browser knows of an Ollama instance. `isOllamaConfigured` reads the
356356
* server-only `OLLAMA_URL` env var, which is always undefined in the browser —
357357
* there the providers store (populated from the server's model list, which is
358358
* non-empty only when Ollama is configured) is the signal.
359359
*/
360-
function isOllamaAvailable(): boolean {
360+
function hasOllamaInstance(): boolean {
361361
if (isOllamaConfigured) return true
362362
return useProvidersStore.getState().providers.ollama.models.length > 0
363363
}
@@ -417,7 +417,7 @@ export function shouldRequireApiKeyForModel(model: string): boolean {
417417
return false
418418
if (storeProvider) return true
419419

420-
if (isOllamaAvailable()) {
420+
if (hasOllamaInstance()) {
421421
if (normalizedModel.includes('/')) return true
422422
if (normalizedModel in getBaseModelProviders()) return true
423423
return false

‎apps/sim/lib/model-router/resolve.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ async function callModelRouter(
248248
}
249249

250250
/**
251-
* Resolves the sim-auto pseudo-model to a concrete model for one block
252-
* execution. Like any model check it throws when the workspace's permission group
253-
* denies sim-auto itself or its permission config cannot be loaded. Otherwise it never fails
254-
* the workflow: any error, timeout, non-hosted deployment, or fully unavailable
255-
* pool column falls back to `fallbackModel` (the block's standard default). Callers must supply the same already-projected
256-
* model-facing signals they pass to their provider boundary; this router never rescans them.
251+
* Resolves the sim-auto pseudo-model to a concrete model for one block execution. Like any
252+
* model check it throws when the workspace's permission group denies sim-auto itself or its
253+
* permission config cannot be loaded. Otherwise it never fails the workflow: any error,
254+
* timeout, non-hosted deployment, or fully unavailable pool column falls back to
255+
* `fallbackModel` (the block's standard default). Callers must supply the same
256+
* already-projected model-facing signals they pass to their provider boundary; this router
257+
* never rescans them.
257258
*/
258259
export async function resolveAutoModel(args: {
259260
ctx: ExecutionContext
@@ -262,7 +263,7 @@ export async function resolveAutoModel(args: {
262263
fallbackModel: string
263264
}): Promise<AutoRoutingResult> {
264265
const { ctx, blockId, signals, fallbackModel } = args
265-
// Before any fallback: a denied sim-auto must not run as whichever pool or default model is allowed.
266+
// Before any fallback: a denied sim-auto must not run as whichever model is allowed.
266267
await validateModelProvider(ctx.userId, ctx.workspaceId ?? undefined, SIM_AUTO_MODEL_ID, ctx)
267268
const fallback: AutoRoutingResult = {
268269
model: fallbackModel,

‎apps/sim/lib/mothership/request/session/run-replay.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export async function openRunReplay(params: {
9898
}
9999

100100
/**
101-
* The end a `replay_end` frame reports: its reason, `closed` for a frame this build
102-
* cannot parse (an unknown reason, a missing length), or `null` for any other frame. It is worker-to-Sim control, never a
103-
* stream event, whatever reason it carries.
101+
* The end a `replay_end` frame reports: its reason, `closed` for a frame this build cannot
102+
* parse (an unknown reason, a missing length), or `null` for any other frame. It is
103+
* worker-to-Sim control, never a stream event, whatever reason it carries.
104104
*/
105105
function replayEnd(value: unknown): RunReplayEnd | null {
106106
if (!isRecordLike(value) || value.type !== MothershipStreamV1EventType.run) return null

‎apps/sim/lib/workflows/editing/validation-models.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,42 @@ describe('model ids no provider declares', () => {
147147
expect(errors[0]?.error).toContain('Unknown model id')
148148
})
149149
})
150+
151+
describe('fallback model rows', () => {
152+
function validateFallback(blockType: string, model: string) {
153+
const result = validateInputsForBlock(
154+
blockType,
155+
{ fallbackModels: [{ id: 'row-1', model }] },
156+
`${blockType}-1`
157+
)
158+
return { errors: result.errors, rows: result.validInputs.fallbackModels }
159+
}
160+
161+
it.each(['agent', 'router_v2', 'evaluator'])(
162+
'accepts an installed Ollama model on %s where Ollama is reachable, as the model field does',
163+
(blockType) => {
164+
const { errors, rows } = validateFallback(blockType, 'mistral:latest')
165+
expect(errors).toEqual([])
166+
expect(rows).toEqual([expect.objectContaining({ model: 'mistral:latest' })])
167+
}
168+
)
169+
170+
it('rejects it on hosted Sim with no Ollama', () => {
171+
setEnvFlags({ isHosted: true })
172+
const { errors } = validateFallback('agent', 'mistral:latest')
173+
expect(errors[0]?.error).toContain('unknown model id "mistral:latest"')
174+
})
175+
176+
it('rejects it when the Ollama provider is blacklisted', () => {
177+
envFlagsMockFns.getBlacklistedProvidersFromEnv.mockReturnValue(['ollama'])
178+
const { errors } = validateFallback('agent', 'mistral:latest')
179+
expect(errors[0]?.error).toContain('unknown model id "mistral:latest"')
180+
})
181+
182+
it('still rejects sim-auto and free text', () => {
183+
expect(validateFallback('agent', 'sim-auto').errors[0]?.error).toContain('sim-auto')
184+
expect(validateFallback('agent', 'best available model').errors[0]?.error).toContain(
185+
'unknown model id'
186+
)
187+
})
188+
})

‎apps/sim/lib/workflows/editing/validation.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,13 @@ describe('validateInputsForBlock', () => {
505505
it('refuses sim-auto, evaluation models, unknown models, missing models, and non-arrays', () => {
506506
expect(validate([{ model: 'sim-auto' }]).valid).toBe(false)
507507
expect(validate([{ model: 'jev-latest' }]).valid).toBe(false)
508-
expect(validate([{ model: 'definitely-not-a-model-9000' }]).valid).toBe(false)
508+
// An unclaimed Ollama-shaped name is a possible local model wherever Ollama is reachable.
509+
setEnvFlags({ isHosted: true })
510+
try {
511+
expect(validate([{ model: 'definitely-not-a-model-9000' }]).valid).toBe(false)
512+
} finally {
513+
setEnvFlags({ isHosted: false })
514+
}
509515
expect(validate([{ apiKey: '{{KEY}}' }]).valid).toBe(false)
510516
expect(validate({ model: 'claude-sonnet-5' }).valid).toBe(false)
511517
})

‎apps/sim/lib/workflows/editing/validation.ts‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ function validateFallbackModelEntry(item: any, index: number): string | null {
560560
if (isEvaluationModel(model)) {
561561
return `${where}: ${model} is an evaluation model and cannot serve as a chat fallback`
562562
}
563-
if (!isKnownModelId(model) && !isCustomModelId(model)) {
563+
if (!isRunnableModelId(model)) {
564564
const suggestions = suggestModelIdsForUnknownModel(model)
565565
const suggestionText =
566566
suggestions.length > 0 ? ` Valid options include: ${suggestions.join(', ')}.` : ''
@@ -585,6 +585,23 @@ function validateFallbackModelEntry(item: any, index: number): string | null {
585585
return null
586586
}
587587

588+
/**
589+
* Whether Sim can run `model`: a catalogued or namespaced id, or a local Ollama name. An id no
590+
* provider claims runs on Ollama (`getProviderFromModel`'s default), so wherever an Ollama server
591+
* is reachable an Ollama-shaped name may be a locally installed model. The server cannot list
592+
* what is installed, so a mistyped name of that shape fails at execution instead. sim-auto is
593+
* never one: it never reaches a provider as itself.
594+
*/
595+
function isRunnableModelId(model: string): boolean {
596+
if (isKnownModelId(model) || isCustomModelId(model)) return true
597+
return (
598+
!isAutoModel(model) &&
599+
OLLAMA_MODEL_NAME.test(model) &&
600+
findProviderFromModel(model) === null &&
601+
isOllamaAvailable()
602+
)
603+
}
604+
588605
/** A file object as the file-upload editor stores it: at least its name and serve path. */
589606
function isStoredFile(value: unknown): boolean {
590607
return isPlainRecord(value) && Boolean(value.name) && Boolean(value.path)
@@ -1001,22 +1018,10 @@ export function validateValueForSubBlockType(
10011018
}
10021019
// sim-auto is valid only where the source offers Auto, which it does on hosted Sim
10031020
// only; writes of it anywhere else are rejected as unknown.
1004-
const isAuto = isAutoModel(trimmed)
1005-
if (isAuto && modelSource.auto && isHostedDeployment) {
1021+
if (isAutoModel(trimmed) && modelSource.auto && isHostedDeployment) {
10061022
return { valid: true, value: trimmed.toLowerCase() }
10071023
}
1008-
// An id no provider claims runs on Ollama (`getProviderFromModel`'s default), so
1009-
// wherever an Ollama server is reachable an Ollama-shaped name may be a locally
1010-
// installed model. The server cannot list what is installed, so a mistyped name of
1011-
// that shape fails at execution instead. sim-auto is never one: it never reaches a
1012-
// provider as itself.
1013-
const isUnknown = !isKnownModelId(trimmed) && !isCustomModelId(trimmed)
1014-
const mayBeLocalModel =
1015-
!isAuto &&
1016-
OLLAMA_MODEL_NAME.test(trimmed) &&
1017-
findProviderFromModel(trimmed) === null &&
1018-
isOllamaAvailable()
1019-
if (trimmed !== '' && isUnknown && !mayBeLocalModel) {
1024+
if (trimmed !== '' && !isRunnableModelId(trimmed)) {
10201025
const suggestions = suggestModelIdsForUnknownModel(trimmed)
10211026
const suggestionText =
10221027
suggestions.length > 0 ? ` Valid options include: ${suggestions.join(', ')}.` : ''

0 commit comments

Comments
 (0)