Skip to content

Commit 9d842d7

Browse files
authored
fix(models): say why sim-auto is refused and tidy release follow-ups (#10437)
* fix(workflows): say why sim-auto is refused on a model field A model field that does not offer Auto, either because the block never does (guardrails, translate) or because the deployment is self-hosted, rejected sim-auto with the generic unknown-model-id error and its namespace examples. It now names the actual reason and points at the block's model.options for a concrete id. * refactor(mothership): classify a worker-reported cancel without a sentinel abort reason WorkerTerminalStop was never passed to abort(); it existed only so recordCancelled could feed a live signal through isExplicitStopReason. Branch on the live signal directly instead. The recorded cancel reason is unchanged, and the worker-reported cancel test now also asserts the root span finishes as explicit_stop. * refactor(urls): inline the single-use ollama url check into isOllamaReachable * test(blocks): check the agent's serialized provider through the real resolver The resolveModelProviderId and findConfiguredModelProvider tests asserted on a mocked getProviderFromModel and restated its stub; the real behaviour is covered by the providers utils tests. The agent block now has a real-resolver test that a model reference records the default provider rather than its written namespace, and its tool callback matches the router and evaluator one-liner.
1 parent a88589b commit 9d842d7

9 files changed

Lines changed: 51 additions & 71 deletions

File tree

‎apps/sim/blocks/blocks/agent.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,9 @@ describe('AgentBlock', () => {
123123
it('falls back to the same provider when no model is set', () => {
124124
expect(toolFunction?.({})).toBe('anthropic')
125125
})
126+
127+
it('records the default provider for a model reference, not its written namespace', () => {
128+
expect(toolFunction?.({ model: 'openrouter/<variable.x>' })).toBe('anthropic')
129+
})
126130
})
127131
})

‎apps/sim/blocks/blocks/agent.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,7 @@ Return ONLY the JSON array.`,
418418
tools: {
419419
access: [...MODEL_PROVIDER_ACCESS_IDS],
420420
config: {
421-
tool: (params: Record<string, any>) => {
422-
return resolveModelProviderId(params.model)
423-
},
421+
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
424422
params: (params: Record<string, any>) => {
425423
const normalizedFiles = normalizeFileInput(params.files)
426424
const baseParams = normalizedFiles ? { ...params, files: normalizedFiles } : params

‎apps/sim/blocks/utils.test.ts‎

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import { evaluateSubBlockCondition } from '@sim/workflow-code/catalog/canonical-
6565
import { S3Icon } from '@/components/icons'
6666
import type { BlockConfig } from '@/blocks/types'
6767
import {
68-
findConfiguredModelProvider,
6968
getAgentModelOptions,
7069
getApiKeyCondition,
7170
getModelOptions,
@@ -379,28 +378,14 @@ describe('resolveModelProviderId', () => {
379378
beforeEach(() => {
380379
resolver.mockReset()
381380
resolver.mockImplementation(((model: string) => {
382-
if (model.startsWith('openrouter/')) return 'openrouter'
383381
if (model === DEFAULT_BLOCK_MODEL) return 'anthropic'
384382
throw new Error(`No provider found for model: ${model}`)
385383
}) as unknown as typeof getProviderFromModel)
386384
})
387385

388-
it('resolves a gateway model that the base model map deliberately omits', () => {
389-
expect(resolveModelProviderId('openrouter/meta-llama/llama-4-maverick')).toBe('openrouter')
390-
})
391-
392386
it('uses the default block model when the model is unset or still an unresolved reference', () => {
393387
expect(resolveModelProviderId('openrouter/<variable.vllm>')).toBe('anthropic')
394388
expect(resolveModelProviderId(undefined)).toBe('anthropic')
395-
expect(resolver).not.toHaveBeenCalledWith('openrouter/<variable.vllm>')
396-
})
397-
398-
it('looks up sim-auto as the model it falls back to, never as itself', () => {
399-
expect(resolveModelProviderId('sim-auto')).toBe('anthropic')
400-
expect(resolveModelProviderId(' SIM-AUTO ')).toBe('anthropic')
401-
expect(resolver).toHaveBeenCalledWith(DEFAULT_BLOCK_MODEL)
402-
expect(resolver).not.toHaveBeenCalledWith('sim-auto')
403-
expect(resolver).not.toHaveBeenCalledWith(' SIM-AUTO ')
404389
})
405390

406391
it('never throws when the resolver rejects the model', () => {
@@ -409,29 +394,6 @@ describe('resolveModelProviderId', () => {
409394
})
410395
})
411396

412-
describe('findConfiguredModelProvider', () => {
413-
const resolver = vi.mocked(getProviderFromModel)
414-
415-
beforeEach(() => {
416-
resolver.mockReset()
417-
resolver.mockImplementation(((model: string) => {
418-
if (model.startsWith('openrouter/')) return 'openrouter'
419-
if (model === 'sim-auto') throw new Error('sim-auto has no provider')
420-
if (model === 'blacklisted-model') throw new Error('blacklisted')
421-
return 'anthropic'
422-
}) as unknown as typeof getProviderFromModel)
423-
})
424-
425-
it('keeps the explicit namespace of a model reference', () => {
426-
expect(findConfiguredModelProvider('openrouter/<variable.vllm>')).toBe('openrouter')
427-
})
428-
429-
it('names no provider for sim-auto or a blacklisted model', () => {
430-
expect(findConfiguredModelProvider('sim-auto')).toBeNull()
431-
expect(findConfiguredModelProvider('blacklisted-model')).toBeNull()
432-
})
433-
})
434-
435397
describe('withSavedCredential', () => {
436398
const picker = {
437399
id: 'credential',

‎apps/sim/lib/core/utils/urls.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,6 @@ export function getOllamaUrl(): string {
294294
return env.OLLAMA_URL || DEFAULT_OLLAMA_URL
295295
}
296296

297-
/**
298-
* Whether OLLAMA_URL names a server, as opposed to {@link getOllamaUrl} falling
299-
* back to the loopback default. Callers use this to tell "someone pointed us at
300-
* an Ollama" apart from "nobody configured one".
301-
*/
302-
function isOllamaUrlConfigured(): boolean {
303-
return Boolean(env.OLLAMA_URL)
304-
}
305-
306297
/**
307298
* Whether this deployment has an Ollama server to talk to. Self-hosted deployments run
308299
* alongside their own Ollama, so the loopback default {@link getOllamaUrl} falls back to is a
@@ -313,7 +304,7 @@ function isOllamaUrlConfigured(): boolean {
313304
* all answer through this, so a picker never lists models its client then refuses.
314305
*/
315306
export function isOllamaReachable(): boolean {
316-
return !isHosted || isOllamaUrlConfigured()
307+
return !isHosted || Boolean(env.OLLAMA_URL)
317308
}
318309

319310
/** Whether Ollama can serve a model here: {@link isOllamaReachable}, and not blacklisted. */

‎apps/sim/lib/mothership/request/lifecycle/start.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ import {
2828
MothershipStreamV1EventType,
2929
} from '@/lib/mothership/generated/mothership-stream-v1'
3030
import { TitleRequest } from '@/lib/mothership/generated/protocol'
31+
import {
32+
CopilotRequestCancelReason,
33+
CopilotTransport,
34+
} from '@/lib/mothership/observability/trace-attribute-values'
35+
import { startCopilotOtelRoot } from '@/lib/mothership/request/otel'
3136
import { isExplicitStopReason } from '@/lib/mothership/request/session/abort-reason'
37+
import { RequestTraceOutcome } from '@/lib/mothership/request/trace'
3238
import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
3339

3440
const {
@@ -621,6 +627,11 @@ describe('createSSEStream terminal error handling', () => {
621627
contentBlocks: [],
622628
toolCalls: [],
623629
})
630+
const otelRoot = startCopilotOtelRoot({
631+
requestId: 'req-cancelled',
632+
transport: CopilotTransport.Stream,
633+
})
634+
const finish = vi.spyOn(otelRoot, 'finish')
624635

625636
const stream = createSSEStream({
626637
requestPayload: { message: 'hello' },
@@ -633,6 +644,7 @@ describe('createSSEStream terminal error handling', () => {
633644
titleModel: 'gpt-5.4',
634645
requestId: 'req-cancelled',
635646
orchestrateOptions: { userId: 'user-1' },
647+
otelRoot,
636648
})
637649

638650
await drainStream(stream)
@@ -654,6 +666,13 @@ describe('createSSEStream terminal error handling', () => {
654666
'Stream cancelled with unknown abort reason',
655667
expect.anything()
656668
)
669+
await vi.waitFor(() =>
670+
expect(finish).toHaveBeenCalledWith(
671+
RequestTraceOutcome.cancelled,
672+
undefined,
673+
CopilotRequestCancelReason.ExplicitStop
674+
)
675+
)
657676
})
658677

659678
it('releases the stream registration and pollers when preview initialization fails before the lifecycle starts', async () => {

‎apps/sim/lib/mothership/request/lifecycle/start.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,11 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
186186

187187
// Only explicit cancellation affects the run; browser attachment is independent.
188188
const recordCancelled = (errorMessage?: string): CopilotRequestCancelReasonValue => {
189-
// A cancelled verdict with this node's signal still live came from the worker's terminal
190-
// (live or replayed in recovery): a Stop that reached the worker before this node saw it.
191-
const rawReason = abortController.signal.aborted
192-
? abortController.signal.reason
193-
: AbortReason.WorkerTerminalStop
189+
const { aborted, reason: rawReason } = abortController.signal
194190
let cancelReason: CopilotRequestCancelReasonValue
195-
if (isExplicitStopReason(rawReason)) {
191+
// A cancelled verdict on a live signal came from the worker's terminal (live or replayed in
192+
// recovery), which it sends only for a Stop.
193+
if (!aborted || isExplicitStopReason(rawReason)) {
196194
cancelReason = CopilotRequestCancelReason.ExplicitStop
197195
} else {
198196
cancelReason = CopilotRequestCancelReason.Unknown

‎apps/sim/lib/mothership/request/session/abort-reason.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ export const AbortReason = {
2828
* 250ms poller's next tick) rather than by the polling timer.
2929
*/
3030
MarkerObservedAtBodyClose: 'redis_abort_marker:body_close',
31-
/**
32-
* The turn's cancelled verdict came from the worker's terminal, which it sends only for a
33-
* Stop, while this node's signal never fired: the Stop reached the worker another way.
34-
* Classification only; nothing aborts with it.
35-
*/
36-
WorkerTerminalStop: 'worker_terminal:cancelled',
3731
/** Internal timeout on the outbound explicit-abort fetch to the worker. */
3832
ExplicitAbortFetchTimeout: 'timeout:explicit_abort_fetch',
3933
} as const
@@ -53,7 +47,6 @@ export function isExplicitStopReason(reason: unknown): boolean {
5347
return (
5448
reason === AbortReason.UserStop ||
5549
reason === AbortReason.RedisPoller ||
56-
reason === AbortReason.MarkerObservedAtBodyClose ||
57-
reason === AbortReason.WorkerTerminalStop
50+
reason === AbortReason.MarkerObservedAtBodyClose
5851
)
5952
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ describe('router and evaluator model fields', () => {
7070
it('rejects sim-auto on self-hosted Sim, where Auto is never offered', () => {
7171
const { errors, model } = validateModel('router_v2', 'sim-auto')
7272
expect(model).toBeUndefined()
73-
expect(errors[0]?.error).toContain('Unknown model id')
73+
expect(errors[0]?.error).toBe(
74+
'Block "router_v2" does not offer Auto ("sim-auto") on a self-hosted deployment; set model to a concrete model id from components/blocks/router_v2.json (the model.options array).'
75+
)
7476
})
7577
})
7678

@@ -81,7 +83,9 @@ describe('translate and guardrails model fields', () => {
8183
setEnvFlags({ isHosted: true })
8284
const { errors, model } = validateModel(blockType, 'sim-auto')
8385
expect(model).toBeUndefined()
84-
expect(errors[0]?.error).toContain('Unknown model id')
86+
expect(errors[0]?.error).toBe(
87+
`Block "${blockType}" does not offer Auto ("sim-auto"); set model to a concrete model id from components/blocks/${blockType}.json (the model.options array).`
88+
)
8589
}
8690
)
8791
})

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,21 @@ export function validateValueForSubBlockType(
10161016
if (containsReference(trimmed)) {
10171017
return { valid: true, value: trimmed }
10181018
}
1019-
// sim-auto is valid only where the source offers Auto, which it does on hosted Sim
1020-
// only; writes of it anywhere else are rejected as unknown.
1021-
if (isAutoModel(trimmed) && modelSource.auto && isHostedDeployment) {
1022-
return { valid: true, value: trimmed.toLowerCase() }
1019+
// sim-auto is valid only where the source offers Auto, which it does on hosted Sim only.
1020+
if (isAutoModel(trimmed)) {
1021+
if (modelSource.auto && isHostedDeployment) {
1022+
return { valid: true, value: trimmed.toLowerCase() }
1023+
}
1024+
return {
1025+
valid: false,
1026+
error: {
1027+
blockId,
1028+
blockType,
1029+
field: fieldName,
1030+
value,
1031+
error: `Block "${blockType}" does not offer Auto ("sim-auto")${modelSource.auto ? ' on a self-hosted deployment' : ''}; set model to a concrete model id from components/blocks/${blockType}.json (the model.options array).`,
1032+
},
1033+
}
10231034
}
10241035
if (trimmed !== '' && !isRunnableModelId(trimmed)) {
10251036
const suggestions = suggestModelIdsForUnknownModel(trimmed)

0 commit comments

Comments
 (0)