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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Section, Text } from '@react-email/components'
import { baseStyles } from '@/components/emails/_styles'
import { EmailButton, EmailLayout } from '@/components/emails/components'

interface DeprecatedModelEmailProps {
recipientName?: string
workflowName: string
model: string
/** Deep link to the workflow. Absent when the workspace is unknown. */
workflowLink?: string
}

/**
* Sent when a workflow runs a model its provider has retired, so the owner can
* switch it before more runs fail.
*/
export function DeprecatedModelEmail({
recipientName,
workflowName,
model,
workflowLink,
}: DeprecatedModelEmailProps) {
return (
<EmailLayout preview={`${workflowName} uses a retired model`} showUnsubscribe={true}>
<Text style={baseStyles.greeting}>{recipientName ? `Hi ${recipientName},` : 'Hi,'}</Text>

<Text style={baseStyles.paragraph}>
Your workflow {workflowName} uses {model}, which its provider has retired. Blocks that call
it will fail until you pick a different model.
</Text>

<Section style={baseStyles.infoBox}>
<Text style={baseStyles.infoBoxTitle}>What to do</Text>
<Text style={baseStyles.infoBoxList}>
Open the workflow, select a current model in each block that uses {model}, and deploy
again if the workflow is deployed.
</Text>
</Section>

{workflowLink ? <EmailButton href={workflowLink}>Open workflow</EmailButton> : null}

<div style={baseStyles.divider} />

<Text style={baseStyles.footnote}>
Sent to the workflow's owner and workspace admins, at most once a month per workflow.
</Text>
</EmailLayout>
)
}

export default DeprecatedModelEmail
1 change: 1 addition & 0 deletions apps/sim/components/emails/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { PermissionAccessRequestEmail } from '@/components/emails/notifications/permission-access-request-email'
export { DeprecatedModelEmail } from './deprecated-model-email'
export { ScheduleDisabledEmail } from './schedule-disabled-email'
export {
type SubprocessorChange,
Expand Down
10 changes: 10 additions & 0 deletions apps/sim/components/emails/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
WorkspaceInvitationEmail,
} from '@/components/emails/invitations'
import {
DeprecatedModelEmail,
PermissionAccessRequestEmail,
ScheduleDisabledEmail,
type SubprocessorChange,
Expand Down Expand Up @@ -176,6 +177,15 @@ export async function renderScheduleDisabledEmail(params: {
return await render(ScheduleDisabledEmail(params))
}

export async function renderDeprecatedModelEmail(params: {
recipientName?: string
workflowName: string
model: string
workflowLink?: string
}): Promise<string> {
return await render(DeprecatedModelEmail(params))
}

export async function renderSubprocessorChangeEmail(params: {
recipientName?: string
changes: SubprocessorChange[]
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/components/emails/subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type EmailSubjectType =
| 'abandoned-checkout'
| 'free-tier-exhausted'
| 'schedule-disabled'
| 'deprecated-model'
| 'subprocessor-change'
| 'onboarding-followup'
| 'welcome'
Expand Down Expand Up @@ -79,6 +80,8 @@ export function getEmailSubject(type: EmailSubjectType): string {
return `You've run out of free credits on Sim`
case 'schedule-disabled':
return `A schedule was turned off on Sim`
case 'deprecated-model':
return `A workflow uses a retired model on Sim`
case 'subprocessor-change':
return `Upcoming change to Sim sub-processors`
case 'onboarding-followup':
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/executor/handlers/agent/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import type {
UserFile,
} from '@/executor/types'
import { collectBlockData } from '@/executor/utils/block-data'
import { noticeDeprecatedModel } from '@/executor/utils/deprecated-model-notice'
import { stringifyJSON } from '@/executor/utils/json'
import {
BLOCK_MODEL_CREDENTIAL_FIELDS,
Expand Down Expand Up @@ -2929,6 +2930,7 @@ export class AgentBlockHandler implements BlockHandler {
): Promise<BlockOutput | StreamingExecution> {
const providerId = providerRequest.provider
const model = providerRequest.model
noticeDeprecatedModel(ctx, model)

try {
const credentials: BlockModelCredentials = (await savedCredentials) ?? {}
Expand Down
31 changes: 31 additions & 0 deletions apps/sim/executor/handlers/generic/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ import { mcpRunOperationTool } from '@/tools/mcp/run-operation'
import type { ToolConfig } from '@/tools/types'
import { getTool } from '@/tools/utils'

const { mockNotifyDeprecatedModelUsed } = vi.hoisted(() => ({
mockNotifyDeprecatedModelUsed: vi.fn(),
}))

vi.mock('@/lib/workflows/notifications/deprecated-model', () => ({
notifyDeprecatedModelUsed: (...args: unknown[]) => mockNotifyDeprecatedModelUsed(...args),
}))

const mockGetBlock = vi.mocked(getBlock)
const mockGetTool = vi.mocked(getTool)
const mockExecuteTool = executeTool as Mock
Expand Down Expand Up @@ -96,6 +104,29 @@ describe('GenericBlockHandler', () => {
mockExecuteTool.mockResolvedValue({ success: true, output: { customResult: 'OK' } })
})

describe('deprecated model notice', () => {
beforeEach(() => {
mockNotifyDeprecatedModelUsed.mockReset().mockResolvedValue(undefined)
})

it('notifies when a tool-backed block runs a deprecated model', async () => {
await handler.execute(mockContext, mockBlock, { model: 'claude-sonnet-4-0' })

expect(mockNotifyDeprecatedModelUsed).toHaveBeenCalledWith({
workflowId: 'test-workflow-id',
model: 'claude-sonnet-4-0',
})
})

it('stays silent for a dry run or workflow test', async () => {
await handler.execute({ ...mockContext, sideEffects: {} } as ExecutionContext, mockBlock, {
model: 'claude-sonnet-4-0',
})

expect(mockNotifyDeprecatedModelUsed).not.toHaveBeenCalled()
})
})

describe('Flow field values', () => {
const writes: unknown[] = []

Expand Down
4 changes: 4 additions & 0 deletions apps/sim/executor/handlers/generic/handler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { isDeepStrictEqual } from 'node:util'
import { createLogger } from '@sim/logger'
import { toStringOrNull } from '@sim/utils/coerce'
import { toError } from '@sim/utils/errors'
import { isPlainRecord } from '@sim/utils/object'
import { adoptToolFailure } from '@/lib/core/errors/failure-log'
import { getBlock } from '@/blocks/index'
import { isMcpTool } from '@/executor/constants'
import type { BlockHandler, BlockNodeMetadata, ExecutionContext } from '@/executor/types'
import { noticeDeprecatedModel } from '@/executor/utils/deprecated-model-notice'
import { readStatusCode } from '@/executor/utils/errors'
import { mayBeJsonText } from '@/executor/utils/json'
import { prepareResolvedSecretProjectedInputs } from '@/executor/utils/resolved-secret-input-projection'
Expand Down Expand Up @@ -310,6 +312,8 @@ export class GenericBlockHandler implements BlockHandler {
}
}

noticeDeprecatedModel(ctx, toStringOrNull(finalInputs.model))

try {
const result = await executeTool(
block.config.tool,
Expand Down
44 changes: 44 additions & 0 deletions apps/sim/executor/utils/deprecated-model-notice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'

const { mockNotifyDeprecatedModelUsed } = vi.hoisted(() => ({
mockNotifyDeprecatedModelUsed: vi.fn(),
}))

vi.mock('@/lib/workflows/notifications/deprecated-model', () => ({
notifyDeprecatedModelUsed: (...args: unknown[]) => mockNotifyDeprecatedModelUsed(...args),
}))

import type { ExecutionContext } from '@/executor/types'
import { noticeDeprecatedModel } from '@/executor/utils/deprecated-model-notice'

const DEPRECATED_MODEL = 'claude-sonnet-4-0'

describe('noticeDeprecatedModel', () => {
beforeEach(() => {
mockNotifyDeprecatedModelUsed.mockReset().mockResolvedValue(undefined)
})

it('notifies when a live run calls a deprecated model', () => {
noticeDeprecatedModel({ workflowId: 'wf-1' } as ExecutionContext, DEPRECATED_MODEL)

expect(mockNotifyDeprecatedModelUsed).toHaveBeenCalledWith({
workflowId: 'wf-1',
model: DEPRECATED_MODEL,
})
})

it('stays silent for a dry run or workflow test', () => {
noticeDeprecatedModel(
{ workflowId: 'wf-1', sideEffects: {} } as ExecutionContext,
DEPRECATED_MODEL
)

expect(mockNotifyDeprecatedModelUsed).not.toHaveBeenCalled()
})

it('stays silent for a current model', () => {
noticeDeprecatedModel({ workflowId: 'wf-1' } as ExecutionContext, 'claude-sonnet-5-5')

expect(mockNotifyDeprecatedModelUsed).not.toHaveBeenCalled()
})
})
18 changes: 18 additions & 0 deletions apps/sim/executor/utils/deprecated-model-notice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { notifyDeprecatedModelUsed } from '@/lib/workflows/notifications/deprecated-model'
import type { ExecutionContext } from '@/executor/types'
import { getModelSunsetStatus } from '@/providers/models'

/**
* Starts the deprecated-model email for a block's model call, without awaiting it:
* Agent, Router and Evaluator calls, and tool-backed blocks with a `model` input
* (Translate's `llm_chat`).
* Runs with a side-effect policy (dry runs, workflow tests) never send it.
*/
export function noticeDeprecatedModel(
ctx: ExecutionContext,
model: string | null | undefined
): void {
if (!model || !ctx.workflowId || ctx.sideEffects) return
if (getModelSunsetStatus(model) !== 'deprecated') return
void notifyDeprecatedModelUsed({ workflowId: ctx.workflowId, model })
}
3 changes: 3 additions & 0 deletions apps/sim/executor/utils/provider-request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createLogger } from '@sim/logger'
import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'
import type { ExecutionContext } from '@/executor/types'
import { noticeDeprecatedModel } from '@/executor/utils/deprecated-model-notice'
import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
import { executeProviderRequest } from '@/providers'
import type { ProviderRequest, ProviderResponse } from '@/providers/types'
Expand Down Expand Up @@ -40,6 +41,8 @@ export async function executeBlockProviderRequest({
}
}

noticeDeprecatedModel(ctx, request.model)

/**
* No `executionContext`: it is only inherited by model-emitted tool calls, and the route
* this replaces never carried one. The whole context is omitted when there is no registry
Expand Down
118 changes: 118 additions & 0 deletions apps/sim/lib/workflows/notifications/deprecated-model.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { queueTableRows, resetDbChainMock, schemaMock, urlsMockFns } from '@sim/testing'
import { emailMailerMock, emailMailerMockFns } from '@sim/testing/mocks/email-mailer.mock'
import { emailTemplatesMock, emailTemplatesMockFns } from '@sim/testing/mocks/email-templates.mock'
import { permissionsMock, permissionsMockFns } from '@sim/testing/mocks/permissions.mock'
import { redisConfigMockFns, resetRedisConfigMock } from '@sim/testing/mocks/redis-config.mock'
import { beforeEach, describe, expect, it, vi } from 'vitest'

vi.mock('@/lib/messaging/email/mailer', () => emailMailerMock)
vi.mock('@/components/emails', () => emailTemplatesMock)
vi.mock('@/lib/workspaces/permissions/utils', () => permissionsMock)

import { notifyDeprecatedModelUsed } from '@/lib/workflows/notifications/deprecated-model'

const sendEmailSpy = emailMailerMockFns.mockSendEmail
const acquireLockMock = redisConfigMockFns.mockAcquireLock
const extendLockMock = redisConfigMockFns.mockExtendLock
const releaseLockMock = redisConfigMockFns.mockReleaseLock

const WORKFLOW_ROW = { name: 'Support triage', userId: 'owner-1', workspaceId: 'ws-1' }
const OWNER = { email: 'owner@example.com', name: 'Ada' }
const NOTICE = { workflowId: 'wf-1', model: 'claude-sonnet-4-5' }

describe('notifyDeprecatedModelUsed', () => {
beforeEach(() => {
resetDbChainMock()
resetRedisConfigMock()
sendEmailSpy.mockReset().mockResolvedValue({ success: true })
emailTemplatesMockFns.mockRenderDeprecatedModelEmail.mockResolvedValue('<html></html>')
urlsMockFns.mockGetBaseUrl.mockReturnValue('https://app.sim.ai')
permissionsMockFns.mockGetUsersWithPermissions.mockResolvedValue([
{ userId: 'u-a', email: 'admin@example.com', name: 'Admin', permissionType: 'admin' },
{ userId: 'u-w', email: 'writer@example.com', name: 'Writer', permissionType: 'write' },
])
})

it('emails the owner and workspace admins once the notice is claimed', async () => {
queueTableRows(schemaMock.workflow, [WORKFLOW_ROW])
queueTableRows(schemaMock.user, [OWNER])

await notifyDeprecatedModelUsed(NOTICE)

expect(sendEmailSpy.mock.calls.map(([options]) => (options as { to: string }).to)).toEqual([
'owner@example.com',
'admin@example.com',
])
expect(extendLockMock).toHaveBeenCalledWith(
'deprecated-model-notice:v1:wf-1:claude-sonnet-4-5',
expect.any(String),
30 * 24 * 60 * 60
)
expect(releaseLockMock).not.toHaveBeenCalled()
})

it('releases the claim so a later run retries when no email is delivered', async () => {
queueTableRows(schemaMock.workflow, [WORKFLOW_ROW])
queueTableRows(schemaMock.user, [OWNER])
sendEmailSpy.mockResolvedValue({ success: false, message: 'provider down' })

await notifyDeprecatedModelUsed(NOTICE)

expect(releaseLockMock).toHaveBeenCalledWith(
'deprecated-model-notice:v1:wf-1:claude-sonnet-4-5',
acquireLockMock.mock.calls[0][1]
)
expect(extendLockMock).not.toHaveBeenCalled()
})

it('keeps the monthly claim when only some recipients were reached', async () => {
queueTableRows(schemaMock.workflow, [WORKFLOW_ROW])
queueTableRows(schemaMock.user, [OWNER])
sendEmailSpy
.mockResolvedValueOnce({ success: true })
.mockResolvedValueOnce({ success: false, message: 'provider down' })

await notifyDeprecatedModelUsed(NOTICE)

expect(extendLockMock).toHaveBeenCalledTimes(1)
expect(releaseLockMock).not.toHaveBeenCalled()
})

it('re-claims the month when the sending claim lapsed mid-send', async () => {
queueTableRows(schemaMock.workflow, [WORKFLOW_ROW])
queueTableRows(schemaMock.user, [OWNER])
extendLockMock.mockResolvedValue(false)

await notifyDeprecatedModelUsed(NOTICE)

expect(acquireLockMock).toHaveBeenLastCalledWith(
'deprecated-model-notice:v1:wf-1:claude-sonnet-4-5',
acquireLockMock.mock.calls[0][1],
30 * 24 * 60 * 60
)
})

it('sends nothing while an earlier notice for the same workflow and model is live', async () => {
acquireLockMock.mockResolvedValue(false)
queueTableRows(schemaMock.workflow, [WORKFLOW_ROW])

await notifyDeprecatedModelUsed(NOTICE)

expect(sendEmailSpy).not.toHaveBeenCalled()
})

it('never throws into the model call when Redis fails', async () => {
acquireLockMock.mockRejectedValue(new Error('redis down'))

await expect(notifyDeprecatedModelUsed(NOTICE)).resolves.toBeUndefined()
expect(sendEmailSpy).not.toHaveBeenCalled()
})

it('sends nothing when the workflow no longer exists', async () => {
queueTableRows(schemaMock.workflow, [])

await notifyDeprecatedModelUsed(NOTICE)

expect(sendEmailSpy).not.toHaveBeenCalled()
})
})
Loading
Loading