From 949cc060ad42370068533c30b6da7755c31daeda Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 11:27:32 -0800 Subject: [PATCH 1/4] 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. --- .../editing/validation-models.test.ts | 8 ++++++-- apps/sim/lib/workflows/editing/validation.ts | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/sim/lib/workflows/editing/validation-models.test.ts b/apps/sim/lib/workflows/editing/validation-models.test.ts index 7617cc560b7..8dddf4dee42 100644 --- a/apps/sim/lib/workflows/editing/validation-models.test.ts +++ b/apps/sim/lib/workflows/editing/validation-models.test.ts @@ -70,7 +70,9 @@ describe('router and evaluator model fields', () => { it('rejects sim-auto on self-hosted Sim, where Auto is never offered', () => { const { errors, model } = validateModel('router_v2', 'sim-auto') expect(model).toBeUndefined() - expect(errors[0]?.error).toContain('Unknown model id') + expect(errors[0]?.error).toBe( + '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).' + ) }) }) @@ -81,7 +83,9 @@ describe('translate and guardrails model fields', () => { setEnvFlags({ isHosted: true }) const { errors, model } = validateModel(blockType, 'sim-auto') expect(model).toBeUndefined() - expect(errors[0]?.error).toContain('Unknown model id') + expect(errors[0]?.error).toBe( + `Block "${blockType}" does not offer Auto ("sim-auto"); set model to a concrete model id from components/blocks/${blockType}.json (the model.options array).` + ) } ) }) diff --git a/apps/sim/lib/workflows/editing/validation.ts b/apps/sim/lib/workflows/editing/validation.ts index 95022b6f386..dd8084ee0fa 100644 --- a/apps/sim/lib/workflows/editing/validation.ts +++ b/apps/sim/lib/workflows/editing/validation.ts @@ -1016,10 +1016,21 @@ export function validateValueForSubBlockType( if (containsReference(trimmed)) { return { valid: true, value: trimmed } } - // sim-auto is valid only where the source offers Auto, which it does on hosted Sim - // only; writes of it anywhere else are rejected as unknown. - if (isAutoModel(trimmed) && modelSource.auto && isHostedDeployment) { - return { valid: true, value: trimmed.toLowerCase() } + // sim-auto is valid only where the source offers Auto, which it does on hosted Sim only. + if (isAutoModel(trimmed)) { + if (modelSource.auto && isHostedDeployment) { + return { valid: true, value: trimmed.toLowerCase() } + } + return { + valid: false, + error: { + blockId, + blockType, + field: fieldName, + value, + 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).`, + }, + } } if (trimmed !== '' && !isRunnableModelId(trimmed)) { const suggestions = suggestModelIdsForUnknownModel(trimmed) From 3f60eff647711284a1e199b9bf150eb4d0fc3582 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 11:27:40 -0800 Subject: [PATCH 2/4] 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. --- .../request/lifecycle/start.test.ts | 19 +++++++++++++++++++ .../lib/mothership/request/lifecycle/start.ts | 10 ++++------ .../request/session/abort-reason.ts | 9 +-------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/apps/sim/lib/mothership/request/lifecycle/start.test.ts b/apps/sim/lib/mothership/request/lifecycle/start.test.ts index e1746d03ea4..fae1e7b1b50 100644 --- a/apps/sim/lib/mothership/request/lifecycle/start.test.ts +++ b/apps/sim/lib/mothership/request/lifecycle/start.test.ts @@ -28,7 +28,13 @@ import { MothershipStreamV1EventType, } from '@/lib/mothership/generated/mothership-stream-v1' import { TitleRequest } from '@/lib/mothership/generated/protocol' +import { + CopilotRequestCancelReason, + CopilotTransport, +} from '@/lib/mothership/observability/trace-attribute-values' +import { startCopilotOtelRoot } from '@/lib/mothership/request/otel' import { isExplicitStopReason } from '@/lib/mothership/request/session/abort-reason' +import { RequestTraceOutcome } from '@/lib/mothership/request/trace' import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' const { @@ -621,6 +627,11 @@ describe('createSSEStream terminal error handling', () => { contentBlocks: [], toolCalls: [], }) + const otelRoot = startCopilotOtelRoot({ + requestId: 'req-cancelled', + transport: CopilotTransport.Stream, + }) + const finish = vi.spyOn(otelRoot, 'finish') const stream = createSSEStream({ requestPayload: { message: 'hello' }, @@ -633,6 +644,7 @@ describe('createSSEStream terminal error handling', () => { titleModel: 'gpt-5.4', requestId: 'req-cancelled', orchestrateOptions: { userId: 'user-1' }, + otelRoot, }) await drainStream(stream) @@ -654,6 +666,13 @@ describe('createSSEStream terminal error handling', () => { 'Stream cancelled with unknown abort reason', expect.anything() ) + await vi.waitFor(() => + expect(finish).toHaveBeenCalledWith( + RequestTraceOutcome.cancelled, + undefined, + CopilotRequestCancelReason.ExplicitStop + ) + ) }) it('releases the stream registration and pollers when preview initialization fails before the lifecycle starts', async () => { diff --git a/apps/sim/lib/mothership/request/lifecycle/start.ts b/apps/sim/lib/mothership/request/lifecycle/start.ts index cdbb9184670..90ab0cc1b31 100644 --- a/apps/sim/lib/mothership/request/lifecycle/start.ts +++ b/apps/sim/lib/mothership/request/lifecycle/start.ts @@ -186,13 +186,11 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS // Only explicit cancellation affects the run; browser attachment is independent. const recordCancelled = (errorMessage?: string): CopilotRequestCancelReasonValue => { - // A cancelled verdict with this node's signal still live came from the worker's terminal - // (live or replayed in recovery): a Stop that reached the worker before this node saw it. - const rawReason = abortController.signal.aborted - ? abortController.signal.reason - : AbortReason.WorkerTerminalStop + const { aborted, reason: rawReason } = abortController.signal let cancelReason: CopilotRequestCancelReasonValue - if (isExplicitStopReason(rawReason)) { + // A cancelled verdict on a live signal came from the worker's terminal (live or replayed in + // recovery), which it sends only for a Stop. + if (!aborted || isExplicitStopReason(rawReason)) { cancelReason = CopilotRequestCancelReason.ExplicitStop } else { cancelReason = CopilotRequestCancelReason.Unknown diff --git a/apps/sim/lib/mothership/request/session/abort-reason.ts b/apps/sim/lib/mothership/request/session/abort-reason.ts index d761051e7c5..25e6a952af6 100644 --- a/apps/sim/lib/mothership/request/session/abort-reason.ts +++ b/apps/sim/lib/mothership/request/session/abort-reason.ts @@ -28,12 +28,6 @@ export const AbortReason = { * 250ms poller's next tick) rather than by the polling timer. */ MarkerObservedAtBodyClose: 'redis_abort_marker:body_close', - /** - * The turn's cancelled verdict came from the worker's terminal, which it sends only for a - * Stop, while this node's signal never fired: the Stop reached the worker another way. - * Classification only; nothing aborts with it. - */ - WorkerTerminalStop: 'worker_terminal:cancelled', /** Internal timeout on the outbound explicit-abort fetch to the worker. */ ExplicitAbortFetchTimeout: 'timeout:explicit_abort_fetch', } as const @@ -53,7 +47,6 @@ export function isExplicitStopReason(reason: unknown): boolean { return ( reason === AbortReason.UserStop || reason === AbortReason.RedisPoller || - reason === AbortReason.MarkerObservedAtBodyClose || - reason === AbortReason.WorkerTerminalStop + reason === AbortReason.MarkerObservedAtBodyClose ) } From 8febc76a68168f4f032b18f5457dbb261823e7fb Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 11:27:41 -0800 Subject: [PATCH 3/4] refactor(urls): inline the single-use ollama url check into isOllamaReachable --- apps/sim/lib/core/utils/urls.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/apps/sim/lib/core/utils/urls.ts b/apps/sim/lib/core/utils/urls.ts index 144bd84faa1..b8d787eb810 100644 --- a/apps/sim/lib/core/utils/urls.ts +++ b/apps/sim/lib/core/utils/urls.ts @@ -294,15 +294,6 @@ export function getOllamaUrl(): string { return env.OLLAMA_URL || DEFAULT_OLLAMA_URL } -/** - * Whether OLLAMA_URL names a server, as opposed to {@link getOllamaUrl} falling - * back to the loopback default. Callers use this to tell "someone pointed us at - * an Ollama" apart from "nobody configured one". - */ -function isOllamaUrlConfigured(): boolean { - return Boolean(env.OLLAMA_URL) -} - /** * Whether this deployment has an Ollama server to talk to. Self-hosted deployments run * alongside their own Ollama, so the loopback default {@link getOllamaUrl} falls back to is a @@ -313,7 +304,7 @@ function isOllamaUrlConfigured(): boolean { * all answer through this, so a picker never lists models its client then refuses. */ export function isOllamaReachable(): boolean { - return !isHosted || isOllamaUrlConfigured() + return !isHosted || Boolean(env.OLLAMA_URL) } /** Whether Ollama can serve a model here: {@link isOllamaReachable}, and not blacklisted. */ From 5e8827db294a6853941825c7e2b20a5b1e0d4faa Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 11:27:43 -0800 Subject: [PATCH 4/4] 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. --- apps/sim/blocks/blocks/agent.test.ts | 4 +++ apps/sim/blocks/blocks/agent.ts | 4 +-- apps/sim/blocks/utils.test.ts | 38 ---------------------------- 3 files changed, 5 insertions(+), 41 deletions(-) diff --git a/apps/sim/blocks/blocks/agent.test.ts b/apps/sim/blocks/blocks/agent.test.ts index 05936948cfb..217b5aedd63 100644 --- a/apps/sim/blocks/blocks/agent.test.ts +++ b/apps/sim/blocks/blocks/agent.test.ts @@ -123,5 +123,9 @@ describe('AgentBlock', () => { it('falls back to the same provider when no model is set', () => { expect(toolFunction?.({})).toBe('anthropic') }) + + it('records the default provider for a model reference, not its written namespace', () => { + expect(toolFunction?.({ model: 'openrouter/' })).toBe('anthropic') + }) }) }) diff --git a/apps/sim/blocks/blocks/agent.ts b/apps/sim/blocks/blocks/agent.ts index dd5a00b6790..d05d6211632 100644 --- a/apps/sim/blocks/blocks/agent.ts +++ b/apps/sim/blocks/blocks/agent.ts @@ -418,9 +418,7 @@ Return ONLY the JSON array.`, tools: { access: [...MODEL_PROVIDER_ACCESS_IDS], config: { - tool: (params: Record) => { - return resolveModelProviderId(params.model) - }, + tool: (params: Record) => resolveModelProviderId(params.model), params: (params: Record) => { const normalizedFiles = normalizeFileInput(params.files) const baseParams = normalizedFiles ? { ...params, files: normalizedFiles } : params diff --git a/apps/sim/blocks/utils.test.ts b/apps/sim/blocks/utils.test.ts index 5db6ba4e670..076a8edd183 100644 --- a/apps/sim/blocks/utils.test.ts +++ b/apps/sim/blocks/utils.test.ts @@ -65,7 +65,6 @@ import { evaluateSubBlockCondition } from '@sim/workflow-code/catalog/canonical- import { S3Icon } from '@/components/icons' import type { BlockConfig } from '@/blocks/types' import { - findConfiguredModelProvider, getAgentModelOptions, getApiKeyCondition, getModelOptions, @@ -379,28 +378,14 @@ describe('resolveModelProviderId', () => { beforeEach(() => { resolver.mockReset() resolver.mockImplementation(((model: string) => { - if (model.startsWith('openrouter/')) return 'openrouter' if (model === DEFAULT_BLOCK_MODEL) return 'anthropic' throw new Error(`No provider found for model: ${model}`) }) as unknown as typeof getProviderFromModel) }) - it('resolves a gateway model that the base model map deliberately omits', () => { - expect(resolveModelProviderId('openrouter/meta-llama/llama-4-maverick')).toBe('openrouter') - }) - it('uses the default block model when the model is unset or still an unresolved reference', () => { expect(resolveModelProviderId('openrouter/')).toBe('anthropic') expect(resolveModelProviderId(undefined)).toBe('anthropic') - expect(resolver).not.toHaveBeenCalledWith('openrouter/') - }) - - it('looks up sim-auto as the model it falls back to, never as itself', () => { - expect(resolveModelProviderId('sim-auto')).toBe('anthropic') - expect(resolveModelProviderId(' SIM-AUTO ')).toBe('anthropic') - expect(resolver).toHaveBeenCalledWith(DEFAULT_BLOCK_MODEL) - expect(resolver).not.toHaveBeenCalledWith('sim-auto') - expect(resolver).not.toHaveBeenCalledWith(' SIM-AUTO ') }) it('never throws when the resolver rejects the model', () => { @@ -409,29 +394,6 @@ describe('resolveModelProviderId', () => { }) }) -describe('findConfiguredModelProvider', () => { - const resolver = vi.mocked(getProviderFromModel) - - beforeEach(() => { - resolver.mockReset() - resolver.mockImplementation(((model: string) => { - if (model.startsWith('openrouter/')) return 'openrouter' - if (model === 'sim-auto') throw new Error('sim-auto has no provider') - if (model === 'blacklisted-model') throw new Error('blacklisted') - return 'anthropic' - }) as unknown as typeof getProviderFromModel) - }) - - it('keeps the explicit namespace of a model reference', () => { - expect(findConfiguredModelProvider('openrouter/')).toBe('openrouter') - }) - - it('names no provider for sim-auto or a blacklisted model', () => { - expect(findConfiguredModelProvider('sim-auto')).toBeNull() - expect(findConfiguredModelProvider('blacklisted-model')).toBeNull() - }) -}) - describe('withSavedCredential', () => { const picker = { id: 'credential',