: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(workflows): tell a hard bounce from a soft one (#105359)
jake sciottod05fae69e174
diff --git a/frontend/src/taxonomy/core-filter-definitions-by-group.json b/frontend/src/taxonomy/core-filter-definitions-by-group.jsonindex 71c7b0bc2c13..8015c443138c 100644--- a/frontend/src/taxonomy/core-filter-definitions-by-group.json+++ b/frontend/src/taxonomy/core-filter-definitions-by-group.json@@ -3427,7 +3427,7 @@"label": "Workflow email marked as spam"},"$workflows_email_bounced": {- "description": "Fires when a workflow email bounces.",+ "description": "Fires when a workflow email bounces. The `$bounce_type` property holds `hard` when the address will never accept mail (it is also added to the suppression list), `soft` when the failure is temporary such as a full mailbox, and `unknown` when the provider could not tell. `$bounce_sub_type` holds the provider's own reason, such as \"MailboxFull\". Bounces recorded before these properties shipped carry neither.","label": "Workflow email bounced"},"$workflows_email_delivered": {diff --git a/nodejs/src/cdp/services/messaging/helpers/ses.test.ts b/nodejs/src/cdp/services/messaging/helpers/ses.test.tsindex ef55ca12829f..d5c5301a6598 100644--- a/nodejs/src/cdp/services/messaging/helpers/ses.test.ts+++ b/nodejs/src/cdp/services/messaging/helpers/ses.test.ts@@ -495,6 +495,9 @@ describe('SesWebhookHandler', () => {// Hard bounces emit both the catch-all metric and the AWS-comparable hard-only oneexpect(result.metrics?.map((m) => m.metricName)).toEqual(['email_bounced', 'email_bounced_hard'])expect(result.metrics?.[0].distinctId).toBe('user-123')+ // Without this the engagement event says only "bounced", and a sender cannot tell a dead+ // address from a full mailbox.+ expect(result.metrics?.[0].properties).toMatchObject({ $bounce_type: 'hard' })expect(result.hardBounceRecipients).toEqual([{ teamId: '1', emailAddresses: ['[email protected]'], diagnostic: 'bad' },])@@ -521,6 +524,8 @@ describe('SesWebhookHandler', () => {// Transient bounces must NOT emit email_bounced_hard — AWS's account rate excludes themexpect(result.metrics?.map((m) => m.metricName)).toEqual(['email_bounced', 'email_bounced_transient'])expect(result.metrics?.[0].distinctId).toBe('user-123')+ // A transient bounce reported as hard would read as a dead address and understate recovery.+ expect(result.metrics?.[0].properties).toMatchObject({ $bounce_type: 'soft' })expect(result.hardBounceRecipients).toEqual([])expect(result.transientBounceRecipients).toEqual([{ teamId: '1', emailAddresses: ['[email protected]'], diagnostic: 'temp' },diff --git a/nodejs/src/cdp/services/messaging/helpers/ses.ts b/nodejs/src/cdp/services/messaging/helpers/ses.tsindex 5a02a95227b3..7d7e7741ea8b 100644--- a/nodejs/src/cdp/services/messaging/helpers/ses.ts+++ b/nodejs/src/cdp/services/messaging/helpers/ses.ts@@ -166,6 +166,14 @@ const BOUNCE_TYPE_TO_METRIC_NAME: Record<'Permanent' | 'Transient' | 'UndeterminUndetermined: 'email_bounced_undetermined',}+// The words senders use, rather than the provider's. This lands on a customer-facing event, where+// "Permanent" reads as a severity rather than as the reason the address will never accept mail.+const BOUNCE_TYPE_TO_EVENT_PROPERTY: Record<'Permanent' | 'Transient' | 'Undetermined', string> = {+ Permanent: 'hard',+ Transient: 'soft',+ Undetermined: 'unknown',+}+const EVENT_TYPE_TO_METRIC_NAME: Partial<Record<SesEventRecord['eventType'], MinimalAppMetric['metric_name']>> = {Open: 'email_opened',Click: 'email_link_clicked',@@ -742,6 +750,14 @@ export class SesWebhookHandler {timestamp = rec.delivery.timestamp} else if ('bounce' in rec && rec.bounce) {timestamp = rec.bounce.timestamp+ // Whether the address will ever accept mail again. A hard bounce is also written+ // to the suppression list below; a soft one is not, so the two need telling apart+ // to read a bounce rate at all.+ properties.$bounce_type = BOUNCE_TYPE_TO_EVENT_PROPERTY[rec.bounce.bounceType]+ if (rec.bounce.bounceSubType) {+ // The provider's own reason (e.g. "MailboxFull", "NoEmail", "Suppressed").+ properties.$bounce_sub_type = rec.bounce.bounceSubType+ }} else if ('complaint' in rec && rec.complaint) {timestamp = rec.complaint.timestampif (rec.complaint.complaintFeedbackType) {diff --git a/posthog/taxonomy/taxonomy.py b/posthog/taxonomy/taxonomy.pyindex 4c74934c4a66..625a673c7bb0 100644--- a/posthog/taxonomy/taxonomy.py+++ b/posthog/taxonomy/taxonomy.py@@ -570,7 +570,7 @@ CORE_FILTER_DEFINITIONS_BY_GROUP: dict[str, dict[str, CoreFilterDefinition]] = {},"$workflows_email_bounced": {"label": "Workflow email bounced",- "description": "Fires when a workflow email bounces.",+ "description": 'Fires when a workflow email bounces. The `$bounce_type` property holds `hard` when the address will never accept mail (it is also added to the suppression list), `soft` when the failure is temporary such as a full mailbox, and `unknown` when the provider could not tell. `$bounce_sub_type` holds the provider\'s own reason, such as "MailboxFull". Bounces recorded before these properties shipped carry neither.',},"$workflows_email_blocked": {"label": "Workflow email marked as spam",diff --git a/products/workflows/frontend/Workflows/EmailMetricsSummary.tsx b/products/workflows/frontend/Workflows/EmailMetricsSummary.tsxindex 9ea6c5576796..6263425b6711 100644--- a/products/workflows/frontend/Workflows/EmailMetricsSummary.tsx+++ b/products/workflows/frontend/Workflows/EmailMetricsSummary.tsx@@ -9,7 +9,7 @@ import { percentage } from 'lib/utils/numbers'import { WorkflowMetricCard } from './WorkflowMetricCard'import {EMAIL_METRIC_INVOCATION_FILTERS,- EmailMetric,+ EmailMetricName,METRIC_COLORS,WORKFLOW_EMAIL_METRICS,} from './workflowMetricsSummaryLogic'@@ -29,7 +29,7 @@ export function EmailMetricsSummary({compact,}: {logicKey: string- onMetricClick?: (metricKey: EmailMetric) => void+ onMetricClick?: (metricKey: EmailMetricName) => voidcompact?: boolean}): JSX.Element {const { appMetricsTrendsLoading, appMetricsTrends, getSingleTrendSeries } = useValues(appMetricsLogic({ logicKey }))diff --git a/products/workflows/frontend/Workflows/WorkflowMetrics.tsx b/products/workflows/frontend/Workflows/WorkflowMetrics.tsxindex 89b6cae41cd6..24bb3eea687a 100644--- a/products/workflows/frontend/Workflows/WorkflowMetrics.tsx+++ b/products/workflows/frontend/Workflows/WorkflowMetrics.tsx@@ -23,7 +23,11 @@ import { PushMetricsSummary } from './PushMetricsSummary'import { WorkflowLogicProps, workflowLogic } from './workflowLogic'import { WorkflowMetricCard } from './WorkflowMetricCard'import { WorkflowMetricsSummary } from './WorkflowMetricsSummary'-import { type EmailMetric, METRIC_COLORS, buildEmailMetricInvocationSearchParams } from './workflowMetricsSummaryLogic'+import {+ type EmailMetricName,+ METRIC_COLORS,+ buildEmailMetricInvocationSearchParams,+} from './workflowMetricsSummaryLogic'const HedgehogGreek = pngHoggie(greekPng)@@ -126,7 +130,7 @@ function WorkflowRunMetrics(props: WorkflowLogicProps): JSX.Element {)// Drill an email metric into the invocations behind it over the current window.- const onEmailMetricClick = (metricKey: EmailMetric): void => {+ const onEmailMetricClick = (metricKey: EmailMetricName): void => {if (!props.id) {return}diff --git a/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx b/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsxindex 96cdf368227d..55f40c1d23d3 100644--- a/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx+++ b/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx@@ -14,6 +14,7 @@ import { EmailLinksTable } from './EmailLinksTable'import { WorkflowMetricCard } from './WorkflowMetricCard'import {type EmailMetric,+ type EmailMetricName,type EmailMetricRow,METRIC_COLORS,type PushMetricRow,@@ -50,7 +51,7 @@ function trackedEngagementColumn(value: number, row: EmailMetricRow): JSX.Elemeninterface WorkflowMetricsSummaryProps extends WorkflowMetricsSummaryLogicProps {onSelectAction?: (actionId: string) => void/** Drill a per-email metric into its filtered logs (only bounced/blocked have a log filter). */- onMetricClick?: (metricKey: EmailMetric) => void+ onMetricClick?: (metricKey: EmailMetricName) => void}export function WorkflowMetricsSummary({@@ -129,14 +130,29 @@ export function WorkflowMetricsSummary({// A prevented bounce is skipped before the provider sees it, so it is not part of// `sent` and its rate reads against everything the step attempted to send.const attempted = row.sent + row.bouncePrevented- const issues = [+ const classifiedBounces = row.bouncedHard + row.bouncedSoft + row.bouncedUnknown+ const bounceIssues: { label: string; value: number; metric: EmailMetricName }[] = [+ { label: 'hard bounced', value: row.bouncedHard, metric: 'email_bounced_hard' },+ { label: 'soft bounced', value: row.bouncedSoft, metric: 'email_bounced_transient' },+ {+ label: 'bounced, type unknown',+ value: row.bouncedUnknown,+ metric: 'email_bounced_undetermined',+ },+ // The rollup and its per-type rows are written together, so this is normally+ // zero. Showing any remainder keeps the tags adding up to the rollup.{label: 'bounced',- value: row.bounced,+ value: Math.max(0, row.bounced - classifiedBounces),+ metric: 'email_bounced',+ },+ ]+ const issues = [+ ...bounceIssues.map((bounce) => ({+ ...bounce,total: row.sent,type: 'danger' as const,- metric: 'email_bounced' as EmailMetric,- },+ })),{label: 'marked as spam',value: row.markedAsSpam,diff --git a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.ts b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.tsindex bb74f47a8b20..73b2bcd83ced 100644--- a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.ts+++ b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.ts@@ -2,6 +2,7 @@ import { AppMetricsTimeSeriesResponse } from 'lib/components/AppMetrics/appMetriimport {type EmailMetric,+ type EmailMetricName,buildEmailMetricInvocationSearchParams,buildEmailMetricRows,buildPushMetricRows,@@ -93,11 +94,23 @@ describe('buildEmailMetricInvocationSearchParams', () => {// Each metric drills into the Invocations tab via the unified search box (`inv_search`), narrowed// to the level that distinguishes it: bounced/marked-as-spam at WARN/ERROR, bounce prevented// ("Skipping send") at INFO.- it.each<[EmailMetric, Record<string, string>]>([+ it.each<[EmailMetricName, Record<string, string>]>([['email_bounced',{ inv_date_from: dateFrom, inv_date_to: dateTo, inv_search: 'bounce', inv_log_levels: 'WARN,ERROR' },],+ [+ 'email_bounced_hard',+ { inv_date_from: dateFrom, inv_date_to: dateTo, inv_search: 'Permanent bounce', inv_log_levels: 'ERROR' },+ ],+ [+ 'email_bounced_transient',+ { inv_date_from: dateFrom, inv_date_to: dateTo, inv_search: 'Transient bounce', inv_log_levels: 'WARN' },+ ],+ [+ 'email_bounced_undetermined',+ { inv_date_from: dateFrom, inv_date_to: dateTo, inv_search: 'Undetermined bounce', inv_log_levels: 'WARN' },+ ],['email_blocked',{ inv_date_from: dateFrom, inv_date_to: dateTo, inv_search: 'Complaint', inv_log_levels: 'WARN,ERROR' },@@ -163,6 +176,8 @@ describe('buildEmailMetricRows', () => {email_opened: 40,email_link_clicked: 12,email_bounced: 6,+ email_bounced_hard: 4,+ email_bounced_transient: 2,email_bounce_prevented: 2,email_blocked: 4,email_untracked: 7,@@ -177,6 +192,9 @@ describe('buildEmailMetricRows', () => {opened: 40,linkClicked: 12,bounced: 6,+ bouncedHard: 4,+ bouncedSoft: 2,+ bouncedUnknown: 0,bouncePrevented: 2,markedAsSpam: 4,untracked: 7,diff --git a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.tsindex 6f2c2e950b12..e89687bc2d00 100644--- a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts+++ b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts@@ -120,6 +120,15 @@ export type EmailMetric =| 'email_suspended'| 'email_paused'+// The bounce rollup's per-type rows. They are fetched and shown as a breakdown of Bounced rather+// than as metrics of their own, so they stay out of `EmailMetric`, whose keys are enumerated to+// render one tile and one series each.+export type EmailMetricName =+ | EmailMetric+ | 'email_bounced_hard'+ | 'email_bounced_transient'+ | 'email_bounced_undetermined'+export type PushMetric = 'push_sent' | 'push_skipped' | 'push_failed' | 'push_opened'export type PushMetricRow = {@@ -139,6 +148,11 @@ export type EmailMetricRow = {opened: numberlinkClicked: numberbounced: number+ // The rollup above split by whether the address will ever accept mail again. Hard bounces are+ // suppressed and cost sender reputation; soft ones are temporary. They sum to `bounced`.+ bouncedHard: number+ bouncedSoft: number+ bouncedUnknown: numberbouncePrevented: number// Spam complaints. Stored under the email_blocked metric name for continuity with// historical data (see the SES webhook handler's Complaint mapping).@@ -362,9 +376,12 @@ export const WORKFLOW_PUSH_METRICS: Record<// two SES events emit differently-worded messages ("Rendering failure …" vs "Message rejected by// SES …") with no shared substring to match on.export const EMAIL_METRIC_INVOCATION_FILTERS: Partial<- Record<EmailMetric, { search: string; levels: LogEntryLevel[] }>+ Record<EmailMetricName, { search: string; levels: LogEntryLevel[] }>> = {email_bounced: { search: 'bounce', levels: ['WARN', 'ERROR'] },+ email_bounced_hard: { search: 'Permanent bounce', levels: ['ERROR'] },+ email_bounced_transient: { search: 'Transient bounce', levels: ['WARN'] },+ email_bounced_undetermined: { search: 'Undetermined bounce', levels: ['WARN'] },// MX-validation skips log "Skipping send: …" at INFO (see HogFunctionHandler in the plugin server).email_bounce_prevented: { search: 'Skipping send', levels: ['INFO'] },email_blocked: { search: 'Complaint', levels: ['WARN', 'ERROR'] },@@ -378,7 +395,7 @@ export const EMAIL_METRIC_INVOCATION_FILTERS: Partial<// Build the router search params that point the Invocations tab at the runs behind the given email// metric over the metrics view's current timeframe.export function buildEmailMetricInvocationSearchParams(- metricKey: EmailMetric,+ metricKey: EmailMetricName,dateFrom: string,dateTo: string): Record<string, string> | null {@@ -400,13 +417,16 @@ const SUMMARY_METRIC_KEYS = (Object.keys(WORKFLOW_SUMMARY_METRICS) as WorkflowSu(key) => key !== 'in_progress')-const EMAIL_METRICS: EmailMetric[] = [+const EMAIL_METRICS: EmailMetricName[] = ['email_sent','email_delivered','email_opened','email_failed','email_link_clicked','email_bounced',+ 'email_bounced_hard',+ 'email_bounced_transient',+ 'email_bounced_undetermined','email_bounce_prevented','email_blocked','email_untracked',@@ -497,7 +517,7 @@ export interface workflowMetricsSummaryLogicValues {emailLinkTotalsByActionId: Record<string, EmailLinkRow[]>emailLinkTotalsByActionIdLoading: booleanemailMetricsRows: EmailMetricRow[]- emailTotalsByActionId: Record<string, Partial<Record<EmailMetric, number>>>+ emailTotalsByActionId: Record<string, Partial<Record<EmailMetricName, number>>>emailTotalsByActionIdLoading: booleanhasConversionGoal: booleaninProgressTotal: number@@ -627,10 +647,10 @@ export interface workflowMetricsSummaryLogicActions {errorObject?: any}loadEmailTotalsSuccess: (- emailTotalsByActionId: Record<string, Partial<Record<EmailMetric, number>>>,+ emailTotalsByActionId: Record<string, Partial<Record<EmailMetricName, number>>>,payload?: any) => {- emailTotalsByActionId: Record<string, Partial<Record<EmailMetric, number>>>+ emailTotalsByActionId: Record<string, Partial<Record<EmailMetricName, number>>>payload?: any}loadInProgressTotal: (_: any) => any@@ -852,7 +872,7 @@ export interface workflowMetricsSummaryLogicMeta {type: 'function_email'updated_at?: number | undefined} & Record<string, unknown>)[],- emailTotalsByActionId: Record<string, Partial<Record<EmailMetric, number>>>+ emailTotalsByActionId: Record<string, Partial<Record<EmailMetricName, number>>>) => EmailMetricRow[]pushMetricsRows: (pushActions: ({@@ -954,7 +974,7 @@ export const workflowMetricsSummaryLogic = kea<workflowMetricsSummaryLogicType>(})),loaders(({ values }) => ({emailTotalsByActionId: [- {} as Record<string, Partial<Record<EmailMetric, number>>>,+ {} as Record<string, Partial<Record<EmailMetricName, number>>>,{loadEmailTotals: async (_, breakpoint) => {await breakpoint(10)@@ -1315,7 +1335,7 @@ export const workflowMetricsSummaryLogic = kea<workflowMetricsSummaryLogicType>(type: 'function_email'updated_at?: number | undefined} & Record<string, unknown>)[],- emailTotalsByActionId: Record<string, Partial<Record<EmailMetric, number>>>+ emailTotalsByActionId: Record<string, Partial<Record<EmailMetricName, number>>>): EmailMetricRow[] => buildEmailMetricRows(emailActions, emailTotalsByActionId),],@@ -1468,7 +1488,7 @@ export function channelSentLabel({ hasEmail, hasPush }: { hasEmail: boolean; hasexport function buildEmailMetricRows(emailActions: { id: string; name: string }[],- emailTotalsByActionId: Record<string, Partial<Record<EmailMetric, number>>>+ emailTotalsByActionId: Record<string, Partial<Record<EmailMetricName, number>>>): EmailMetricRow[] {return emailActions.map((action) => {const totals = emailTotalsByActionId[action.id] || {}@@ -1486,6 +1506,9 @@ export function buildEmailMetricRows(opened: totals.email_opened ?? 0,linkClicked: totals.email_link_clicked ?? 0,bounced,+ bouncedHard: totals.email_bounced_hard ?? 0,+ bouncedSoft: totals.email_bounced_transient ?? 0,+ bouncedUnknown: totals.email_bounced_undetermined ?? 0,bouncePrevented: totals.email_bounce_prevented ?? 0,markedAsSpam,untracked,@@ -1513,8 +1536,8 @@ export function buildPushMetricRows(function mapEmailMetricsToActions(totalsResponse: AppMetricsTotalsResponse-): Record<string, Partial<Record<EmailMetric, number>>> {- const result: Record<string, Partial<Record<EmailMetric, number>>> = {}+): Record<string, Partial<Record<EmailMetricName, number>>> {+ const result: Record<string, Partial<Record<EmailMetricName, number>>> = {}Object.values(totalsResponse).forEach(({ total, breakdowns }) => {const [instanceId, metricName] = breakdowns@@ -1529,8 +1552,8 @@ function mapEmailMetricsToActions(return result}-function isEmailMetric(metricName: string): metricName is EmailMetric {- return EMAIL_METRICS.includes(metricName as EmailMetric)+function isEmailMetric(metricName: string): metricName is EmailMetricName {+ return EMAIL_METRICS.includes(metricName as EmailMetricName)}function mapPushMetricsToActions(