: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
fix(workflows): show a broadcast whose launch never finished as failed and let it go back to draft (#107553)
Daniel Marchuk4875ecaf5d3e
diff --git a/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx b/products/workflows/frontend/Broadcasts/BroadcastSummary.tsxindex 1cf11ed490de..084b89a8d0d9 100644--- a/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx+++ b/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx@@ -2,7 +2,15 @@ import { BindLogic, useActions, useValues } from 'kea'import { useEffect } from 'react'import { IconArrowLeft, IconChevronDown, IconLetter } from '@posthog/icons'-import { LemonButton, LemonDialog, LemonDivider, LemonInput, LemonTag, LemonTagType } from '@posthog/lemon-ui'+import {+ LemonBanner,+ LemonButton,+ LemonDialog,+ LemonDivider,+ LemonInput,+ LemonTag,+ LemonTagType,+} from '@posthog/lemon-ui'import PropertyFiltersDisplay from 'lib/components/PropertyFilters/components/PropertyFiltersDisplay'import { TZLabel } from 'lib/components/TZLabel'@@ -264,9 +272,10 @@ export function BroadcastSummary(): JSX.Element {const confirmMoveToDraft = (): void => {LemonDialog.open({- title: 'Stop this broadcast and edit it?',- description:- 'The scheduled send stops and the broadcast goes back to draft. Nothing sends until you launch it again.',+ title: pendingSchedule ? 'Stop this broadcast and edit it?' : 'Move this broadcast to draft?',+ description: pendingSchedule+ ? 'The scheduled send stops and the broadcast goes back to draft. Nothing sends until you launch it again.'+ : 'The broadcast goes back to draft, so you can check it and launch it again.',primaryButton: {children: 'Stop and edit',onClick: moveToDraft,@@ -345,6 +354,23 @@ export function BroadcastSummary(): JSX.Element {) : null}</div>+ {summaryStatus === 'failed' && !latestBatchJob && !batchJobsLoading ? (+ <LemonBanner+ type="warning"+ action={+ canMoveToDraft+ ? {+ children: 'Move to draft',+ onClick: confirmMoveToDraft,+ 'data-attr': 'broadcast-unfinished-launch-to-draft',+ }+ : undefined+ }+ >+ This broadcast didn't send, and nothing is scheduled.+ {canMoveToDraft ? ' Move it back to draft to launch it again.' : null}+ </LemonBanner>+ ) : null}<LemonTabsactiveKey={summaryTab}onChange={setSummaryTab}diff --git a/products/workflows/frontend/Broadcasts/broadcastStatus.test.ts b/products/workflows/frontend/Broadcasts/broadcastStatus.test.tsindex 72ca8ea66e06..368243a14eb6 100644--- a/products/workflows/frontend/Broadcasts/broadcastStatus.test.ts+++ b/products/workflows/frontend/Broadcasts/broadcastStatus.test.ts@@ -1,8 +1,11 @@-import type { HogFlowBatchJobApi, HogFlowMinimalApi } from 'products/workflows/frontend/generated/api.schemas'+import type { HogFlowBatchJobApi } from 'products/workflows/frontend/generated/api.schemas'import { getBroadcastStatus } from './broadcastsLogic'-const flow = (status: string): HogFlowMinimalApi => ({ status }) as unknown as HogFlowMinimalApi+const flow = (+ status: string,+ origin_product: string | null = 'broadcasts'+): Parameters<typeof getBroadcastStatus>[0] => ({ status, origin_product })const withJob = (status: string): { latestBatchJob: HogFlowBatchJobApi; totals: Record<string, number> } => ({latestBatchJob: { status } as HogFlowBatchJobApi,totals: {},@@ -20,6 +23,18 @@ describe('getBroadcastStatus', () => {['a run that failed', flow('active'), withJob('failed'), 'failed'],['a run that was cancelled', flow('active'), withJob('cancelled'), 'failed'],['no run yet', flow('active'), { latestBatchJob: null, totals: {} }, 'scheduled'],+ [+ 'no run and no schedule to come',+ flow('active'),+ { latestBatchJob: null, totals: {}, hasPendingSchedule: false },+ 'failed',+ ],+ [+ 'a workflow waiting for a send started through the API',+ flow('active', null),+ { latestBatchJob: null, totals: {}, hasPendingSchedule: false },+ 'scheduled',+ ],['a recurring broadcast between runs',flow('active'),diff --git a/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts b/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.tsindex 6d7972d45c60..239d3f7a4555 100644--- a/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts+++ b/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts@@ -62,7 +62,9 @@ describe('broadcast edits to broadcast-shaped workflows', () => {['a recurring broadcast between runs', 'active', ['active'], ['completed'], undefined, true],['a broadcast whose schedule was paused', 'active', ['paused'], [], undefined, true],['a broadcast sent right away', 'active', [], ['completed'], undefined, false],+ ['a broadcast whose launch never finished', 'active', [], [], undefined, true],['a one-time broadcast that already sent', 'active', ['completed'], ['completed'], undefined, false],+ ['a one-time schedule that never started a run', 'active', ['completed'], [], undefined, true],['a workflow with a sent one-time schedule and another','active',diff --git a/products/workflows/frontend/Broadcasts/broadcastsLogic.ts b/products/workflows/frontend/Broadcasts/broadcastsLogic.tsindex 884862c8124e..febd2ddecfa2 100644--- a/products/workflows/frontend/Broadcasts/broadcastsLogic.ts+++ b/products/workflows/frontend/Broadcasts/broadcastsLogic.ts@@ -103,12 +103,15 @@ export function canMoveToDraft(broadcast: StoppableBroadcast | null,batchJobs: Pick<HogFlowBatchJobApi, 'status'>[] | null): boolean {+ const schedules = broadcast?.schedules ?? []+ const neverSent = batchJobs?.length === 0return (broadcast?.status === 'active' &&// Only a send still to come can be stopped, since relaunching one that went out resends it. The- // wizard models a single schedule, so a relaunch would fold several into one.- broadcast.schedules?.length === 1 &&- broadcast.schedules[0].status !== 'completed' &&+ // wizard models a single schedule, so a relaunch would fold several into one. A launch or a+ // one-time schedule that never started a run sent nothing, so it can go back to draft too.+ schedules.length <= 1 &&+ (neverSent || (schedules.length === 1 && schedules[0].status !== 'completed')) &&batchJobs !== null &&!batchJobs.some((job) => ['waiting', 'queued', 'active'].includes(job.status ?? '')) &&// Even a broadcast's own graph can be edited elsewhere, and the wizard would save over it.@@ -121,7 +124,7 @@ export function isEligibleWorkflow(flow: Pick<HogFlowMinimalApi, 'origin_product}export function getBroadcastStatus(- broadcast: { status?: string | null },+ broadcast: { status?: string | null; origin_product?: string | null },details: BroadcastRowDetails | undefined): BroadcastStatus {if (broadcast.status === 'draft') {@@ -149,7 +152,12 @@ export function getBroadcastStatus(// tells the sender another send is still pending when nothing is coming.return 'failed'}- // Active with no batch job yet: it's waiting on its schedule (or a manual send).+ // Live with no run and nothing scheduled: a launch from the wizard that never finished, so nothing+ // will ever send. A workflow opened here can wait for a send started through the API instead.+ if (details.hasPendingSchedule === false && broadcast.origin_product === 'broadcasts') {+ return 'failed'+ }+ // Active with no batch job yet: it's waiting on its schedule.return 'scheduled'}