Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/sim/blocks/blocks/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<variable.x>' })).toBe('anthropic')
})
})
})
4 changes: 1 addition & 3 deletions apps/sim/blocks/blocks/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,7 @@ Return ONLY the JSON array.`,
tools: {
access: [...MODEL_PROVIDER_ACCESS_IDS],
config: {
tool: (params: Record<string, any>) => {
return resolveModelProviderId(params.model)
},
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
params: (params: Record<string, any>) => {
const normalizedFiles = normalizeFileInput(params.files)
const baseParams = normalizedFiles ? { ...params, files: normalizedFiles } : params
Expand Down
38 changes: 0 additions & 38 deletions apps/sim/blocks/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/<variable.vllm>')).toBe('anthropic')
expect(resolveModelProviderId(undefined)).toBe('anthropic')
expect(resolver).not.toHaveBeenCalledWith('openrouter/<variable.vllm>')
})

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', () => {
Expand All @@ -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/<variable.vllm>')).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',
Expand Down
11 changes: 1 addition & 10 deletions apps/sim/lib/core/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. */
Expand Down
19 changes: 19 additions & 0 deletions apps/sim/lib/mothership/request/lifecycle/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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' },
Expand All @@ -633,6 +644,7 @@ describe('createSSEStream terminal error handling', () => {
titleModel: 'gpt-5.4',
requestId: 'req-cancelled',
orchestrateOptions: { userId: 'user-1' },
otelRoot,
})

await drainStream(stream)
Expand All @@ -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 () => {
Expand Down
10 changes: 4 additions & 6 deletions apps/sim/lib/mothership/request/lifecycle/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions apps/sim/lib/mothership/request/session/abort-reason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
}
8 changes: 6 additions & 2 deletions apps/sim/lib/workflows/editing/validation-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).'
)
})
})

Expand All @@ -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).`
)
}
)
})
Expand Down
19 changes: 15 additions & 4 deletions apps/sim/lib/workflows/editing/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading