Skip to content

Commit cf797cc

Browse files
authored
fix(models): send deprecated-model notices only for models Sim runs, including Pi (#10602)
* fix(models): send deprecated-model notices only for models Sim runs, including Pi * fix(models): notice a Pi model only once Pi accepts it, cover guardrails model scope
1 parent b9629de commit cf797cc

5 files changed

Lines changed: 85 additions & 3 deletions

File tree

‎apps/sim/executor/handlers/generic/handler.test.ts‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ describe('GenericBlockHandler', () => {
107107
describe('deprecated model notice', () => {
108108
beforeEach(() => {
109109
mockNotifyDeprecatedModelUsed.mockReset().mockResolvedValue(undefined)
110+
mockGetTool.mockReturnValue(mockTool)
110111
})
111112

112-
it('notifies when a tool-backed block runs a deprecated model', async () => {
113+
it('notifies when a block running a Sim model uses a deprecated one', async () => {
114+
mockBlock.config = { tool: 'llm_chat', params: {} }
115+
113116
await handler.execute(mockContext, mockBlock, { model: 'claude-sonnet-4-0' })
114117

115118
expect(mockNotifyDeprecatedModelUsed).toHaveBeenCalledWith({
@@ -118,7 +121,42 @@ describe('GenericBlockHandler', () => {
118121
})
119122
})
120123

124+
it('stays silent when a third-party tool takes a model id it runs itself', async () => {
125+
mockBlock.config = { tool: 'modal_chat_completion', params: {} }
126+
127+
await handler.execute(mockContext, mockBlock, { model: 'claude-sonnet-4-0' })
128+
129+
expect(mockNotifyDeprecatedModelUsed).not.toHaveBeenCalled()
130+
})
131+
132+
it('notifies for a Guardrails hallucination check, which runs the model', async () => {
133+
mockBlock.config = { tool: 'guardrails_validate', params: {} }
134+
135+
await handler.execute(mockContext, mockBlock, {
136+
validationType: 'hallucination',
137+
model: 'claude-sonnet-4-0',
138+
})
139+
140+
expect(mockNotifyDeprecatedModelUsed).toHaveBeenCalledWith({
141+
workflowId: 'test-workflow-id',
142+
model: 'claude-sonnet-4-0',
143+
})
144+
})
145+
146+
it('stays silent for a Guardrails check that runs no model, despite a stale model value', async () => {
147+
mockBlock.config = { tool: 'guardrails_validate', params: {} }
148+
149+
await handler.execute(mockContext, mockBlock, {
150+
validationType: 'pii',
151+
model: 'claude-sonnet-4-0',
152+
})
153+
154+
expect(mockNotifyDeprecatedModelUsed).not.toHaveBeenCalled()
155+
})
156+
121157
it('stays silent for a dry run or workflow test', async () => {
158+
mockBlock.config = { tool: 'llm_chat', params: {} }
159+
122160
await handler.execute({ ...mockContext, sideEffects: {} } as ExecutionContext, mockBlock, {
123161
model: 'claude-sonnet-4-0',
124162
})

‎apps/sim/executor/handlers/generic/handler.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class GenericBlockHandler implements BlockHandler {
312312
}
313313
}
314314

315-
noticeDeprecatedModel(ctx, toStringOrNull(finalInputs.model))
315+
noticeDeprecatedModel(ctx, simRunModel(block.config.tool, finalInputs))
316316

317317
try {
318318
const result = await executeTool(
@@ -398,3 +398,16 @@ export class GenericBlockHandler implements BlockHandler {
398398
}
399399
}
400400
}
401+
402+
/**
403+
* The model a tool runs through Sim's own providers, or null. Other tools with a
404+
* `model` input pass a vendor's model id to that vendor, so a matching catalog id
405+
* there says nothing about a model Sim calls.
406+
*/
407+
function simRunModel(toolId: string | undefined, inputs: Record<string, unknown>): string | null {
408+
if (toolId === 'llm_chat') return toStringOrNull(inputs.model)
409+
if (toolId === 'guardrails_validate' && inputs.validationType === 'hallucination') {
410+
return toStringOrNull(inputs.model)
411+
}
412+
return null
413+
}

‎apps/sim/executor/handlers/pi/handler.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const {
2222
mockResolveSearchKey,
2323
mockBuildSearchTool,
2424
mockBuildSimToolSpecs,
25+
mockNotifyDeprecatedModelUsed,
2526
} = vi.hoisted(() => ({
27+
mockNotifyDeprecatedModelUsed: vi.fn(),
2628
mockRunLocal: vi.fn(),
2729
mockRunCloud: vi.fn(),
2830
mockRunCloudBranch: vi.fn(),
@@ -76,6 +78,9 @@ vi.mock('@/providers/pi-providers', () => ({
7678
resolvePiModelId: mockResolvePiModelId,
7779
}))
7880
vi.mock('@/providers/utils', () => providersUtilsMock)
81+
vi.mock('@/lib/workflows/notifications/deprecated-model', () => ({
82+
notifyDeprecatedModelUsed: mockNotifyDeprecatedModelUsed,
83+
}))
7984
vi.mock('@/blocks/utils', () => ({
8085
parseOptionalNumberInput: (
8186
value: unknown,
@@ -227,6 +232,27 @@ describe('PiBlockHandler', () => {
227232
expect(mockRunCloudReview).not.toHaveBeenCalled()
228233
})
229234

235+
it('notifies the workflow owner when Pi runs a deprecated model', async () => {
236+
mockNotifyDeprecatedModelUsed.mockResolvedValue(undefined)
237+
238+
await handler.execute(ctx(), block, localInputs({ model: 'claude-sonnet-4-0' }))
239+
240+
expect(mockNotifyDeprecatedModelUsed).toHaveBeenCalledWith({
241+
workflowId: 'wf',
242+
model: 'claude-sonnet-4-0',
243+
})
244+
})
245+
246+
it('sends no notice for a deprecated model Pi refuses to run', async () => {
247+
mockNotifyDeprecatedModelUsed.mockResolvedValue(undefined)
248+
mockResolvePiModelId.mockReturnValue(undefined)
249+
250+
await expect(
251+
handler.execute(ctx(), block, localInputs({ model: 'claude-sonnet-4-0' }))
252+
).rejects.toThrow('is not available')
253+
expect(mockNotifyDeprecatedModelUsed).not.toHaveBeenCalled()
254+
})
255+
230256
it('adds successful Function tool cost once to a non-streaming Local Dev result', async () => {
231257
mockBuildSimToolSpecs.mockImplementation(
232258
async (

‎apps/sim/executor/handlers/pi/handler.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import type {
5555
NormalizedBlockOutput,
5656
StreamingExecution,
5757
} from '@/executor/types'
58+
import { noticeDeprecatedModel } from '@/executor/utils/deprecated-model-notice'
5859
import { attachTrustedExecutionCost } from '@/executor/utils/errors'
5960
import { refuseResolvedSecretProjection } from '@/executor/utils/resolved-secret-projection-refusal'
6061
import type { ModelCost } from '@/providers/cost-policy'
@@ -225,6 +226,7 @@ export class PiBlockHandler implements BlockHandler {
225226
`Pi model "${model}" is not available for provider "${providerId}" in the installed Pi catalog. Choose a supported Pi model in the block settings.`
226227
)
227228
}
229+
noticeDeprecatedModel(ctx, model)
228230

229231
const { apiKey, isBYOK } = await resolvePiModelKey({
230232
providerId,

‎apps/sim/lib/workflows/notifications/deprecated-model.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { queueTableRows, resetDbChainMock, schemaMock, urlsMockFns } from '@sim/testing'
22
import { emailMailerMock, emailMailerMockFns } from '@sim/testing/mocks/email-mailer.mock'
33
import { emailTemplatesMock, emailTemplatesMockFns } from '@sim/testing/mocks/email-templates.mock'
4+
import { getMockLogger } from '@sim/testing/mocks/logger.mock'
45
import { permissionsMock, permissionsMockFns } from '@sim/testing/mocks/permissions.mock'
56
import { redisConfigMockFns, resetRedisConfigMock } from '@sim/testing/mocks/redis-config.mock'
67
import { beforeEach, describe, expect, it, vi } from 'vitest'
@@ -108,11 +109,13 @@ describe('notifyDeprecatedModelUsed', () => {
108109
expect(sendEmailSpy).not.toHaveBeenCalled()
109110
})
110111

111-
it('sends nothing when the workflow no longer exists', async () => {
112+
it('releases the claim without an error when the workflow no longer exists', async () => {
112113
queueTableRows(schemaMock.workflow, [])
113114

114115
await notifyDeprecatedModelUsed(NOTICE)
115116

116117
expect(sendEmailSpy).not.toHaveBeenCalled()
118+
expect(releaseLockMock).toHaveBeenCalled()
119+
expect(getMockLogger('DeprecatedModelNotifications').error).not.toHaveBeenCalled()
117120
})
118121
})

0 commit comments

Comments
 (0)