Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(workflows): flag a deleted broadcast sender on the content step (#111606)

Daniel Marchuk63484939c6eb
diff --git a/products/workflows/frontend/Broadcasts/broadcastSender.test.ts b/products/workflows/frontend/Broadcasts/broadcastSender.test.ts
index 25e680ab5bff..52feb6c285db 100644
--- a/products/workflows/frontend/Broadcasts/broadcastSender.test.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastSender.test.ts
@@ -1,6 +1,6 @@
import type { IntegrationType } from '~/types'
-import { SENDERS_LOAD_FAILED_ERROR, getSenderLaunchError } from './broadcastWizardLogic'
+import { DELETED_SENDER_ERROR, SENDERS_LOAD_FAILED_ERROR, getSenderLaunchError } from './broadcastWizardLogic'
const sender = (id: number, verified: boolean): IntegrationType => ({
id,
@@ -18,14 +18,18 @@ describe('getSenderLaunchError', () => {
['an unverified sender', 1, [sender(1, false)], false, "Verify the sender's domain before sending"],
['senders still loading', 1, null, true, 'Checking the email sender. Try again in a moment.'],
['senders failed to load', 1, null, false, SENDERS_LOAD_FAILED_ERROR],
+ ['a sender that was deleted', 7, [sender(1, true)], false, DELETED_SENDER_ERROR],
+ ['a deleted sender in the rotation', [1, 7], [sender(1, true)], false, DELETED_SENDER_ERROR],
[
- 'a sender that was deleted',
- 7,
- [sender(1, true)],
+ 'an unverified sender in the rotation',
+ [1, 2],
+ [sender(1, true), sender(2, false)],
false,
- 'The chosen email sender no longer exists. Pick another one on the content step.',
+ "Verify the sender's domain before sending",
],
- ])('blocks launch for %s', (_, integrationId, integrations, integrationsLoading, expected) => {
- expect(getSenderLaunchError(integrationId, integrations, integrationsLoading)).toBe(expected)
+ ['a verified rotation', [1, 2], [sender(1, true), sender(2, true)], false, null],
+ ])('blocks launch for %s', (_, ids, integrations, integrationsLoading, expected) => {
+ const from = Array.isArray(ids) ? { integrationId: ids[0], integrationIds: ids } : { integrationId: ids }
+ expect(getSenderLaunchError(from, integrations, integrationsLoading)).toBe(expected)
})
})
diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts
index 8b9876eaf360..48fd619f6de4 100644
--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts
@@ -1,13 +1,15 @@
import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'
import type { HogFlowApi } from 'products/workflows/frontend/generated/api.schemas'
-import { DEFAULT_BROADCAST_EMAIL, broadcastWizardLogic } from './broadcastWizardLogic'
+import { DEFAULT_BROADCAST_EMAIL, DELETED_SENDER_ERROR, broadcastWizardLogic } from './broadcastWizardLogic'
const LOCAL_AUDIENCE: AnyPropertyFilter[] = [
{ key: 'plan', value: ['pro'], operator: PropertyOperator.Exact, type: PropertyFilterType.Person },
@@ -79,6 +81,10 @@ describe('broadcastWizardLogic', () => {
useMocks({
get: {
'/api/projects/:team_id/hog_flows/:id/': () => [200, latest],
+ '/api/projects/:team_id/integrations/': {
+ results: [{ id: 1, kind: 'email', config: { verified: true } }],
+ count: 1,
+ },
},
post: {
'/api/projects/:team_id/hog_flows/user_blast_radius/': () => [200, { affected: 0, total: 0 }],
@@ -302,12 +308,6 @@ describe('broadcastWizardLogic', () => {
updatedAt: editedElsewhere ? '2026-09-24T10:00:09Z' : '2026-09-24T10:00:00Z',
})
useMocks({
- get: {
- '/api/projects/:team_id/integrations/': {
- results: [{ id: 1, kind: 'email', config: { verified: true } }],
- count: 1,
- },
- },
post: {
'/api/projects/:team_id/hog_flows/user_blast_radius/': () => [
200,
@@ -334,6 +334,32 @@ describe('broadcastWizardLogic', () => {
}
)
+ it.each([
+ { sender: 'a sender that still exists', integrationId: 1, integrationIds: undefined, expected: [] },
+ { sender: 'a deleted sender', integrationId: 7, integrationIds: undefined, expected: [DELETED_SENDER_ERROR] },
+ {
+ sender: 'a deleted sender in the rotation',
+ integrationId: 1,
+ integrationIds: [1, 7],
+ expected: [DELETED_SENDER_ERROR],
+ },
+ ])('flags $sender on the content step and once on review', async ({ integrationId, integrationIds, expected }) => {
+ integrationsLogic.mount()
+ await expectLogic(integrationsLogic, () => {
+ integrationsLogic.actions.loadIntegrations()
+ }).toDispatchActions(['loadIntegrationsSuccess'])
+
+ logic.actions.setEmail({
+ ...DEFAULT_BROADCAST_EMAIL,
+ from: { ...DEFAULT_BROADCAST_EMAIL.from, integrationId, integrationIds },
+ subject: 'Spring sale',
+ html: '<p>Hi</p>',
+ })
+
+ expect(logic.values.stepValidationErrors.content).toEqual(expected)
+ expect(logic.values.stepValidationErrors.review).toEqual(expected)
+ })
+
it('resumes a saved draft on the step in its URL and drops the step from the URL', async () => {
latest = savedBroadcast({ name: 'Spring sale', subject: '', updatedAt: '2026-09-24T10:00:00Z' })
router.actions.push('/broadcasts/broadcast-1', { step: 'content', other: 'kept' })
diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
index 8a5674a58e97..fe60f956ed93 100644
--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
@@ -90,7 +90,7 @@ export type BroadcastScheduleMode = 'now' | 'later' | 'recurring'
// `template-email` hog function template's default input shape.
export interface BroadcastEmailValue {
to: { email: string; name?: string }
- from: { integrationId?: number | null }
+ from: { integrationId?: number | null; integrationIds?: number[] }
replyTo?: string
cc?: string
bcc?: string
@@ -967,6 +967,9 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
if (!email.from?.integrationId) {
errors.content.push('Choose an email sender')
+ } else if (integrations && getMissingSenderIds(email.from, integrations).length > 0) {
+ // Shown on the content step, where the sender is picked, rather than first at launch.
+ errors.content.push(DELETED_SENDER_ERROR)
}
if (!email.subject) {
errors.content.push('Add a subject line')
@@ -987,8 +990,8 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
}
errors.review = [...errors.recipients, ...errors.goal, ...errors.content, ...errors.schedule]
- const senderError = getSenderLaunchError(email.from?.integrationId, integrations, integrationsLoading)
- if (senderError) {
+ const senderError = getSenderLaunchError(email.from, integrations, integrationsLoading)
+ if (senderError && !errors.review.includes(senderError)) {
errors.review.push(senderError)
}
@@ -1748,27 +1751,49 @@ async function patchWithoutClobbering(
}
export const SENDERS_LOAD_FAILED_ERROR = "Couldn't load your email senders. Reload them to launch."
+export const DELETED_SENDER_ERROR = 'The chosen sender was deleted. Choose another sender.'
/**
* Why the chosen sender can't send yet, if it can't. A draft can be written with any sender, but a
* launch whose sender is unverified, deleted, or not yet known would fail every email it sends.
*/
export function getSenderLaunchError(
- integrationId: number | null | undefined,
+ from: BroadcastEmailValue['from'] | undefined,
integrations: IntegrationType[] | null,
integrationsLoading: boolean
): string | null {
- if (!integrationId) {
+ const senderIds = getSenderIds(from)
+ if (senderIds.length === 0) {
return null
}
if (!integrations) {
return integrationsLoading ? 'Checking the email sender. Try again in a moment.' : SENDERS_LOAD_FAILED_ERROR
}
- const sender = integrations.find((integration) => integration.kind === 'email' && integration.id === integrationId)
- if (!sender) {
- return 'The chosen email sender no longer exists. Pick another one on the content step.'
+ if (getMissingSenderIds(from, integrations).length > 0) {
+ return DELETED_SENDER_ERROR
}
- return sender.config?.verified === true ? null : "Verify the sender's domain before sending"
+ const allVerified = senderIds.every(
+ (id) =>
+ integrations.find((integration) => integration.kind === 'email' && integration.id === id)?.config
+ ?.verified === true
+ )
+ return allVerified ? null : "Verify the sender's domain before sending"
+}
+
+export function getSenderIds(from: BroadcastEmailValue['from'] | undefined): number[] {
+ if (from?.integrationIds?.length) {
+ return from.integrationIds
+ }
+ return from?.integrationId ? [from.integrationId] : []
+}
+
+export function getMissingSenderIds(
+ from: BroadcastEmailValue['from'] | undefined,
+ integrations: IntegrationType[]
+): number[] {
+ return getSenderIds(from).filter(
+ (id) => !integrations.some((integration) => integration.kind === 'email' && integration.id === id)
+ )
}
// Serializes the wizard state into the HogFlow the broadcast is stored as: a batch trigger
diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
index 3d148159a8c2..cb95137ddb59 100644
--- a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
@@ -12,7 +12,13 @@ import { IntegrationType } from '~/types'
import { EmailSetupModal } from '../../Channels/EmailSetup/EmailSetupModal'
import { buildSampleGlobals } from '../../Workflows/hogflows/steps/components/HogFlowFunctionConfiguration'
import { UtmTagFields } from '../../Workflows/hogflows/steps/components/UtmTagFields'
-import { BroadcastEmailValue, DEFAULT_BROADCAST_EMAIL, broadcastWizardLogic } from '../broadcastWizardLogic'
+import {
+ BroadcastEmailValue,
+ DEFAULT_BROADCAST_EMAIL,
+ broadcastWizardLogic,
+ getMissingSenderIds,
+ getSenderIds,
+} from '../broadcastWizardLogic'
export function BroadcastContentStep(): JSX.Element {
const { broadcast, email, name, stepValidationErrors, selectedSender, emailSettings } =
@@ -26,13 +32,34 @@ export function BroadcastContentStep(): JSX.Element {
const hasSenders = !!integrations?.some((integration) => integration.kind === 'email')
const senderUnverified = !!selectedSender && selectedSender.config?.verified !== true
+ // A deleted sender would otherwise show as its bare id, so the picker leaves it out.
+ const missingSenderIds = integrations ? getMissingSenderIds(email.from, integrations) : []
+ const remainingSenderIds = getSenderIds(email.from).filter((id) => !missingSenderIds.includes(id))
+ const editorValue = missingSenderIds.length
+ ? {
+ ...email,
+ from: {
+ ...email.from,
+ integrationId: remainingSenderIds[0],
+ integrationIds: remainingSenderIds.length > 1 ? remainingSenderIds : undefined,
+ },
+ }
+ : email
// Closing the modal after Continue also keeps the sender it created or verified.
const closeSenderSetup = (integrationId?: number): void => {
setSenderSetup(null)
if (integrationId) {
loadIntegrations()
- setEmail({ ...email, from: { ...email.from, integrationId } })
+ setEmail({
+ ...email,
+ from: {
+ ...email.from,
+ integrationId,
+ integrationIds:
+ senderSetup !== 'new' && remainingSenderIds.length > 1 ? remainingSenderIds : undefined,
+ },
+ })
}
}
@@ -96,7 +123,7 @@ export function BroadcastContentStep(): JSX.Element {
type="native_email"
templating="liquid"
liveChanges
- value={email as unknown as EmailTemplate}
+ value={editorValue as unknown as EmailTemplate}
defaultValue={DEFAULT_BROADCAST_EMAIL as unknown as EmailTemplate}
onChange={(value) => setEmail(value as unknown as BroadcastEmailValue)}
variables={buildSampleGlobals({ type: 'batch' }, null)}