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.

feat(workflows): warn when a broadcast about the same record was already sent (#114835)

Daniel Marchuk648a97b6ddfd
diff --git a/frontend/src/scenes/cohorts/cohortUtils.tsx b/frontend/src/scenes/cohorts/cohortUtils.tsx
index 9805d22a0842..cbbe7f5ab691 100644
--- a/frontend/src/scenes/cohorts/cohortUtils.tsx
+++ b/frontend/src/scenes/cohorts/cohortUtils.tsx
@@ -747,6 +747,7 @@ export function cohortBroadcastAudience(cohort: Pick<CohortType, 'id' | 'name'>)
return {
properties: cohortAudienceProperties({ id: cohort.id, name: cohort.name }),
source: 'cohort',
+ sourceRecord: `cohort:${cohort.id}`,
draftSource: { source: 'cohort', source_id: String(cohort.id) },
}
}
diff --git a/products/desktop/packages/api-client/src/generated.ts b/products/desktop/packages/api-client/src/generated.ts
index b55a506eb068..0cc898790fdd 100644
--- a/products/desktop/packages/api-client/src/generated.ts
+++ b/products/desktop/packages/api-client/src/generated.ts
@@ -15840,6 +15840,10 @@ export namespace Schemas {
* Mixin for serializers to add user access control fields
*/
origin_product?: (HogFlowOriginProductEnum | NullEnum) | undefined;
+ /**
+ * Mixin for serializers to add user access control fields
+ */
+ source_record?: (string | null) | undefined;
created_at: string;
created_by: UserBasic & unknown;
updated_at: string;
@@ -22591,6 +22595,7 @@ export namespace Endpoints {
optimization_enabled: boolean;
origin_product: "broadcasts" | "loops" | "transactional_emails";
search: string;
+ source_record: string;
status: "active" | "archived" | "draft";
tags: string;
trigger: string;
diff --git a/products/early_access_features/frontend/enrolledPeopleAudience.ts b/products/early_access_features/frontend/enrolledPeopleAudience.ts
index fc8b089f82ab..829db05fa530 100644
--- a/products/early_access_features/frontend/enrolledPeopleAudience.ts
+++ b/products/early_access_features/frontend/enrolledPeopleAudience.ts
@@ -7,6 +7,7 @@ export function enrolledPeopleAudience(earlyAccessFeature: EarlyAccessFeatureTyp
const flagKey = earlyAccessFeature.feature_flag.key
return {
source,
+ sourceRecord: `early_access:${earlyAccessFeature.id}`,
properties: [
{
key: `$feature_enrollment/${flagKey}`,
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.ts b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.ts
index 06831ebe5614..e4fb79a5fb09 100644
--- a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.ts
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.ts
@@ -54,6 +54,7 @@ describe('issueAffectedBroadcastLogic', () => {
expect(pathname).toContain('/broadcasts/new')
expect(searchParams.name).toEqual('We fixed Checkout timeout')
expect(searchParams.source).toEqual('error_tracking_affected')
+ expect(searchParams.source_record).toEqual('error_tracking:issue-1')
expect(parseBroadcastAudiencePrefill(searchParams.audience)).toMatchObject([
{ type: 'cohort', key: 'id', value: 42 },
])
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.ts
index 3fdebe15dea5..cb1d42cd9c8c 100644
--- a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.ts
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.ts
@@ -271,6 +271,7 @@ export const issueAffectedBroadcastLogic = kea<issueAffectedBroadcastLogicType>(
{
properties: cohortAudienceProperties(audienceCohort),
source: values.source,
+ sourceRecord: `error_tracking:${props.issueId}`,
broadcastName: truncate(`We fixed ${props.issueName || 'an error'}`, MAX_NAME_LENGTH),
broadcastEmail: draftMessage({ kind: 'issue_fixed' }),
draftSource: { source: 'error_tracking', source_id: props.issueId },
diff --git a/products/workflows/backend/migrations/0037_hogflow_source_record.py b/products/workflows/backend/migrations/0037_hogflow_source_record.py
new file mode 100644
index 000000000000..b15eea50e5e0
--- /dev/null
+++ b/products/workflows/backend/migrations/0037_hogflow_source_record.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.2.18 on 2026-10-10 03:13
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("workflows", "0036_teamworkflowsconfig_email_utm_defaults"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="hogflow",
+ name="source_record",
+ field=models.CharField(blank=True, max_length=255, null=True),
+ ),
+ ]
diff --git a/products/workflows/backend/migrations/0038_hogflow_team_source_record_idx.py b/products/workflows/backend/migrations/0038_hogflow_team_source_record_idx.py
new file mode 100644
index 000000000000..f22172dffd5b
--- /dev/null
+++ b/products/workflows/backend/migrations/0038_hogflow_team_source_record_idx.py
@@ -0,0 +1,22 @@
+from django.db import migrations, models
+
+from posthog.migration_helpers import SafeAddIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("workflows", "0037_hogflow_source_record"),
+ ]
+
+ operations = [
+ SafeAddIndexConcurrently(
+ model_name="hogflow",
+ index=models.Index(
+ condition=models.Q(source_record__isnull=False),
+ fields=["team", "source_record"],
+ name="hogflow_team_source_record_idx",
+ ),
+ ),
+ ]
diff --git a/products/workflows/backend/migrations/max_migration.txt b/products/workflows/backend/migrations/max_migration.txt
index d122755b7922..2ce22c5893e0 100644
--- a/products/workflows/backend/migrations/max_migration.txt
+++ b/products/workflows/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0036_teamworkflowsconfig_email_utm_defaults
+0038_hogflow_team_source_record_idx
diff --git a/products/workflows/backend/models/hog_flow/hog_flow.py b/products/workflows/backend/models/hog_flow/hog_flow.py
index e22ce6c588d8..453b45903303 100644
--- a/products/workflows/backend/models/hog_flow/hog_flow.py
+++ b/products/workflows/backend/models/hog_flow/hog_flow.py
@@ -212,6 +212,11 @@ class HogFlow(Taggable, UUIDTModel):
indexes = [
models.Index(fields=["status", "team"]),
models.Index(fields=["version", "team"]),
+ models.Index(
+ fields=["team", "source_record"],
+ name="hogflow_team_source_record_idx",
+ condition=models.Q(source_record__isnull=False),
+ ),
]
constraints = [
@@ -232,6 +237,9 @@ class HogFlow(Taggable, UUIDTModel):
origin_product = models.CharField(
max_length=40, choices=hog_flow_origin_product_choices, null=True, blank=True, db_index=False
)
+ # The record another product's "message these people" entry point started this flow from, as
+ # "<kind>:<id>". A later broadcast from the same record warns that this one already went out.
+ source_record = models.CharField(max_length=255, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey("posthog.User", on_delete=models.SET_NULL, null=True, blank=True, related_name="+")
diff --git a/products/workflows/backend/presentation/views/hog_flow.py b/products/workflows/backend/presentation/views/hog_flow.py
index 77530fa7fa9d..6f7b6570b1be 100644
--- a/products/workflows/backend/presentation/views/hog_flow.py
+++ b/products/workflows/backend/presentation/views/hog_flow.py
@@ -3288,6 +3288,15 @@ class HogFlowSerializer(HogFlowMinimalSerializer):
help_text="Product surface that owns this workflow (e.g. `loops` for Desktop loops). Set only when "
"creating a workflow. Filter the list with `?origin_product=`.",
)
+ source_record = serializers.RegexField(
+ r"^[a-z_]+:[A-Za-z0-9_-]+$",
+ max_length=255,
+ required=False,
+ allow_null=True,
+ write_only=True,
+ help_text="The record another product's entry point started this workflow from, as '<kind>:<id>'. "
+ "Set only when creating a workflow. Filter the list with `?source_record=`.",
+ )
name = serializers.CharField(
max_length=400, required=False, allow_null=True, allow_blank=True, help_text="Workflow name."
)
@@ -3601,6 +3610,7 @@ class HogFlowSerializer(HogFlowMinimalSerializer):
"version",
"status",
"origin_product",
+ "source_record",
"created_at",
"created_by",
"updated_at",
@@ -3861,6 +3871,10 @@ class HogFlowUpdateSerializer(HogFlowSerializer):
help_text="Product surface that owns this workflow. This value cannot change after creation.",
)
+ class Meta(HogFlowSerializer.Meta):
+ # Set on create only.
+ fields = [field for field in HogFlowSerializer.Meta.fields if field != "source_record"]
+
def validate(self, data: dict) -> dict:
instance = cast(Optional[WorkflowEditState], self.instance)
submitted_origin_product = self.initial_data.get("origin_product", serializers.empty)
@@ -4954,6 +4968,11 @@ class HogFlowVersionMetricsRequestSerializer(AppMetricsRequestSerializer):
enum=HogFlowOriginProduct.values,
description="Filter to workflows owned by a product surface, e.g. `loops` for Desktop loops.",
),
+ OpenApiParameter(
+ "source_record",
+ OpenApiTypes.STR,
+ description="Filter to workflows started from this record, as '<kind>:<id>', e.g. `early_access:<id>`.",
+ ),
OpenApiParameter(
"trigger",
OpenApiTypes.STR,
diff --git a/products/workflows/backend/services/hog_flow_reads.py b/products/workflows/backend/services/hog_flow_reads.py
index b23bc6f650f8..5a0f1eabb212 100644
--- a/products/workflows/backend/services/hog_flow_reads.py
+++ b/products/workflows/backend/services/hog_flow_reads.py
@@ -203,6 +203,7 @@ WORKFLOW_FIELD_FILTER_PARAMS: Final[tuple[str, ...]] = (
"updated_at",
"status",
"origin_product",
+ "source_record",
"optimization_enabled",
)
@@ -494,7 +495,7 @@ class _WorkflowFilterSet(FilterSet):
model = HogFlow
# `created_by` is filtered by uuid in _list_queryset (the list UI's member picker keys on
# uuid, not pk), so it's deliberately not an exact-match field here.
- fields = ["id", "created_at", "updated_at", "status", "origin_product"]
+ fields = ["id", "created_at", "updated_at", "status", "origin_product", "source_record"]
def filter_optimization_enabled(self, queryset, name: str, value: bool):
# Off keeps its row, so "on" is a row still enabled. Archived workflows drop out: nothing runs there.
diff --git a/products/workflows/backend/tests/api/test_hog_flow.py b/products/workflows/backend/tests/api/test_hog_flow.py
index 9050fd453f71..67afabfea72a 100644
--- a/products/workflows/backend/tests/api/test_hog_flow.py
+++ b/products/workflows/backend/tests/api/test_hog_flow.py
@@ -596,6 +596,32 @@ class TestHogFlowAPI(APIBaseTest):
response = self.client.get(f"/api/projects/{self.team.id}/hog_flows?origin_product=spreadsheets")
assert response.status_code == 400
+ def test_source_record_is_set_on_create_filters_the_list_and_never_changes(self):
+ hog_flow, _ = self._create_hog_flow_with_action(
+ {"template_id": "template-webhook", "inputs": {"url": {"value": "https://example.com"}}},
+ )
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/hog_flows", {**hog_flow, "source_record": "early_access:feature-1"}
+ )
+ assert response.status_code == 201, response.json()
+ flow_id = response.json()["id"]
+ HogFlow.objects.create(team=self.team, name="Other record", created_by=self.user, source_record="cohort:7")
+
+ response = self.client.patch(
+ f"/api/projects/{self.team.id}/hog_flows/{flow_id}", {"source_record": "early_access:feature-2"}
+ )
+ assert response.status_code == 200, response.json()
+ assert HogFlow.objects.get(id=flow_id).source_record == "early_access:feature-1"
+
+ response = self.client.get(f"/api/projects/{self.team.id}/hog_flows?source_record=early_access:feature-1")
+ assert response.status_code == 200, response.json()
+ assert [flow["id"] for flow in response.json()["results"]] == [flow_id]
+
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/hog_flows", {**hog_flow, "source_record": "not a record"}
+ )
+ assert response.status_code == 400
+
def test_list_returns_last_run_for_loops_from_one_lookup(self):
loop = HogFlow.objects.create(team=self.team, name="Loop", created_by=self.user, origin_product="loops")
HogFlow.objects.create(team=self.team, name="Hand built", created_by=self.user)
diff --git a/products/workflows/frontend/Broadcasts/BroadcastPreviousSendBanner.tsx b/products/workflows/frontend/Broadcasts/BroadcastPreviousSendBanner.tsx
new file mode 100644
index 000000000000..f9f51e39a9c3
--- /dev/null
+++ b/products/workflows/frontend/Broadcasts/BroadcastPreviousSendBanner.tsx
@@ -0,0 +1,40 @@
+import { useValues } from 'kea'
+
+import { LemonBanner } from '@posthog/lemon-ui'
+
+import { dayjs } from 'lib/dayjs'
+import { Link } from 'lib/lemon-ui/Link'
+import { pluralize } from 'lib/utils/strings'
+import { urls } from 'scenes/urls'
+
+import { broadcastPreviousSendLogic } from './broadcastPreviousSendLogic'
+
+export function BroadcastPreviousSendBanner({ sourceRecord }: { sourceRecord: string }): JSX.Element | null {
+ const { previousSend, sentCount } = useValues(broadcastPreviousSendLogic({ sourceRecord }))
+ if (!previousSend) {
+ return null
+ }
+ const message =
+ previousSend.state === 'sent' && previousSend.job
+ ? `You already emailed about this on ${dayjs(previousSend.job.created_at).format('MMMM D, YYYY')}${
+ sentCount ? ` (${pluralize(sentCount, 'person', 'people')})` : ''
+ }.`
+ : previousSend.state === 'sending'
+ ? 'A broadcast about this is sending now.'
+ : 'A broadcast about this is already scheduled.'
+ return (
+ <div data-attr="broadcast-previous-send">
+ <LemonBanner type="warning">
+ {message}{' '}
+ <Link
+ to={urls.broadcast(previousSend.broadcastId)}
+ target="_blank"
+ data-attr="broadcast-previous-send-link"
+ >
+ View that broadcast
+ </Link>
+ .
+ </LemonBanner>
+ </div>
+ )
+}
diff --git a/products/workflows/frontend/Broadcasts/BroadcastWizard.tsx b/products/workflows/frontend/Broadcasts/BroadcastWizard.tsx
index 64013090446e..1c4bc15eab6e 100644
--- a/products/workflows/frontend/Broadcasts/BroadcastWizard.tsx
+++ b/products/workflows/frontend/Broadcasts/BroadcastWizard.tsx
@@ -13,6 +13,7 @@ import {
realtimeCohortSendBlockedReason,
} from '../Workflows/hogflows/steps/realtimeCohortStatus'
import { manageDisabledReason } from './broadcastLifecycle'
+import { BroadcastPreviousSendBanner } from './BroadcastPreviousSendBanner'
import { BroadcastSceneHeader } from './BroadcastSceneHeader'
import { broadcastWizardLogic } from './broadcastWizardLogic'
import { BroadcastWizardStepper } from './BroadcastWizardStepper'
@@ -30,7 +31,7 @@ export function BroadcastWizard(): JSX.Element {
const realtimeCohort = blastRadius?.realtime_cohort
const { setStep, prevStep, continueStep, launchBroadcast, archiveBroadcast, openInWorkflowEditor } =
useActions(broadcastWizardLogic)
- const { broadcastId, broadcast } = useValues(broadcastWizardLogic)
+ const { broadcastId, broadcast, sourceRecord } = useValues(broadcastWizardLogic)
useBroadcastAgentPanel()
const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
@@ -111,6 +112,8 @@ export function BroadcastWizard(): JSX.Element {
</div>
</div>
+ {sourceRecord && <BroadcastPreviousSendBanner sourceRecord={sourceRecord} />}
+
<div>
{currentStep === 'recipients' && <BroadcastRecipientsStep />}
{currentStep === 'goal' && <BroadcastGoalStep />}
diff --git a/products/workflows/frontend/Broadcasts/broadcastAudiencePrefill.ts b/products/workflows/frontend/Broadcasts/broadcastAudiencePrefill.ts
index 0d66f226dd40..7f21a0ff8233 100644
--- a/products/workflows/frontend/Broadcasts/broadcastAudiencePrefill.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastAudiencePrefill.ts
@@ -12,12 +12,15 @@ import { EMAIL_PREFILL_PARAM, MessageDraft } from '../MessageAudience/messageDra
export const AUDIENCE_PREFILL_PARAM = 'audience'
export const NAME_PREFILL_PARAM = 'name'
export const SOURCE_PREFILL_PARAM = 'source'
+export const SOURCE_RECORD_PREFILL_PARAM = 'source_record'
export interface BroadcastPrefill {
properties: AnyPropertyFilter[]
name?: string
/** The product surface the person came from, reported on the launch event. */
source?: string
+ /** The record the email is about, as "<kind>:<id>". Saved on the broadcast so a later one can warn it was already sent. */
+ sourceRecord?: string
email?: MessageDraft
draftSource?: EmailDraftRequestApi
}
@@ -26,6 +29,7 @@ export function urlForNewBroadcastWithAudience({
properties,
name,
source,
+ sourceRecord,
email,
draftSource,
}: BroadcastPrefill): string {
@@ -33,6 +37,7 @@ export function urlForNewBroadcastWithAudience({
[AUDIENCE_PREFILL_PARAM]: JSON.stringify(properties),
...(name ? { [NAME_PREFILL_PARAM]: name } : {}),
...(source ? { [SOURCE_PREFILL_PARAM]: source } : {}),
+ ...(sourceRecord ? { [SOURCE_RECORD_PREFILL_PARAM]: sourceRecord } : {}),
...(email ? { [EMAIL_PREFILL_PARAM]: JSON.stringify(email) } : {}),
...(draftSource ? { [DRAFT_SOURCE_PARAM]: JSON.stringify(draftSource) } : {}),
}).url
@@ -108,3 +113,9 @@ function toAudienceFilter(filter: unknown): AnyPropertyFilter | null {
value: value as string | number | boolean | (string | number | boolean)[],
} as AnyPropertyFilter
}
+
+const SOURCE_RECORD_PATTERN = /^[a-z_]+:[A-Za-z0-9_-]+$/
+
+export function parseSourceRecordPrefill(raw: unknown): string | undefined {
+ return typeof raw === 'string' && raw.length <= 255 && SOURCE_RECORD_PATTERN.test(raw) ? raw : undefined
+}
diff --git a/products/workflows/frontend/Broadcasts/broadcastPreviousSendLogic.test.ts b/products/workflows/frontend/Broadcasts/broadcastPreviousSendLogic.test.ts
new file mode 100644
index 000000000000..8419f9a5e2a5
--- /dev/null
+++ b/products/workflows/frontend/Broadcasts/broadcastPreviousSendLogic.test.ts
@@ -0,0 +1,98 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { initKeaTests } from '~/test/init'
+
+import { hogFlowsBatchJobsList, hogFlowsList, hogFlowsSchedulesList } from 'products/workflows/frontend/generated/api'
+
+import { broadcastPreviousSendLogic } from './broadcastPreviousSendLogic'
+import { loadRunMetricTotals } from './broadcastsLogic'
+
+jest.mock('products/workflows/frontend/generated/api', () => ({
+ hogFlowsList: jest.fn(),
+ hogFlowsBatchJobsList: jest.fn(),
+ hogFlowsSchedulesList: jest.fn(),
+}))
+jest.mock('./broadcastsLogic', () => ({ loadRunMetricTotals: jest.fn() }))
+
+const mockList = jest.mocked(hogFlowsList)
+const mockJobs = jest.mocked(hogFlowsBatchJobsList)
+const mockSchedules = jest.mocked(hogFlowsSchedulesList)
+const mockTotals = jest.mocked(loadRunMetricTotals)
+
+const completed = { id: 'job-1', status: 'completed', created_at: '2026-10-12T09:00:00Z' }
+
+describe('broadcastPreviousSendLogic', () => {
+ beforeEach(() => {
+ initKeaTests()
+ jest.clearAllMocks()
+ mockSchedules.mockResolvedValue([])
+ mockTotals.mockResolvedValue({ email_sent: 12 })
+ })
+
+ it.each([
+ { case: 'nothing went out about the record', flows: [], jobs: {}, expected: null, sentCount: null },
+ {
+ case: 'only a draft exists',
+ flows: [{ id: 'draft-1', status: 'draft' }],
+ jobs: {},
+ expected: null,
+ sentCount: null,
+ },
+ {
+ case: 'an archived broadcast already sent',
+ flows: [{ id: 'flow-1', status: 'archived' }],
+ jobs: { 'flow-1': [completed] },
+ expected: { broadcastId: 'flow-1', state: 'sent', job: completed },
+ sentCount: 12,
+ },
+ {
+ case: 'a run is queued but nobody got the email yet',
+ flows: [{ id: 'flow-1', status: 'active' }],
+ jobs: { 'flow-1': [{ id: 'job-2', status: 'queued', created_at: '2026-10-20T09:00:00Z' }] },
+ expected: { broadcastId: 'flow-1', state: 'scheduled', job: null },
+ sentCount: null,
+ },
+ {
+ case: 'a newer broadcast is sending and an older one already sent',
+ flows: [
+ { id: 'flow-2', status: 'active' },
+ { id: 'flow-1', status: 'active' },
+ ],
+ jobs: { 'flow-2': [{ id: 'job-3', status: 'active' }], 'flow-1': [completed] },
+ expected: { broadcastId: 'flow-1', state: 'sent', job: completed },
+ sentCount: 12,
+ },
+ {
+ case: 'a failed run is the only history',
+ flows: [{ id: 'flow-1', status: 'active' }],
+ jobs: { 'flow-1': [{ id: 'job-4', status: 'failed' }] },
+ expected: null,
+ sentCount: null,
+ },
+ ])('reports the earlier broadcast when $case', async ({ flows, jobs, expected, sentCount }) => {
+ mockList.mockResolvedValue({ results: flows } as never)
+ mockJobs.mockImplementation(async (_, id) => ((jobs as Record<string, unknown[]>)[id] ?? []) as never)
+
+ const logic = broadcastPreviousSendLogic({ sourceRecord: 'early_access:feature-1' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(mockList.mock.calls[0][1]).toEqual({ source_record: 'early_access:feature-1', limit: 5 })
+ expect(logic.values.previousSend).toEqual(expected)
+ expect(logic.values.sentCount).toEqual(sentCount)
+ logic.unmount()
+ })
+
+ it('reports a broadcast scheduled for later that has not run', async () => {
+ mockList.mockResolvedValue({ results: [{ id: 'flow-1', status: 'active' }] } as never)
+ mockJobs.mockResolvedValue([])
+ mockSchedules.mockResolvedValue([{ status: 'active' }] as never)
+
+ const logic = broadcastPreviousSendLogic({ sourceRecord: 'cohort:7' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.previousSend).toEqual({ broadcastId: 'flow-1', state: 'scheduled', job: null })
+ logic.unmount()
+ })
+})
diff --git a/products/workflows/frontend/Broadcasts/broadcastPreviousSendLogic.ts b/products/workflows/frontend/Broadcasts/broadcastPreviousSendLogic.ts
new file mode 100644
index 000000000000..351996d90aa1
--- /dev/null
+++ b/products/workflows/frontend/Broadcasts/broadcastPreviousSendLogic.ts
@@ -0,0 +1,157 @@
+import { MakeLogicType, afterMount, connect, kea, key, listeners, path, props } from 'kea'
+import { loaders } from 'kea-loaders'
+
+import { projectLogic } from 'scenes/projectLogic'
+import { teamLogic } from 'scenes/teamLogic'
+
+import type { TeamPublicType, TeamType } from '~/types'
+
+import { hogFlowsBatchJobsList, hogFlowsList, hogFlowsSchedulesList } from 'products/workflows/frontend/generated/api'
+import type { HogFlowBatchJobApi } from 'products/workflows/frontend/generated/api.schemas'
+
+import { loadRunMetricTotals } from './broadcastsLogic'
+
+export interface BroadcastPreviousSendLogicProps {
+ /** The record the new broadcast is about, as "<kind>:<id>". */
+ sourceRecord: string
+}
+
+export type PreviousSendState = 'sent' | 'sending' | 'scheduled'
+
+export interface PreviousSend {
+ broadcastId: string
+ state: PreviousSendState
+ /** The run that went out, for its date and count. Null when nothing has run yet. */
+ job: HogFlowBatchJobApi | null
+}
+
+/** Broadcasts about one record are few, so the newest handful covers the history worth warning about. */
+const RECENT_BROADCASTS = 5
+const PENDING_JOB_STATES = new Set(['waiting', 'queued', 'active'])
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface broadcastPreviousSendLogicValues {
+ currentProjectId: number | null // projectLogic
+ currentTeam: TeamPublicType | TeamType | null // teamLogic
+ previousSend: PreviousSend | null
+ previousSendLoading: boolean
+ sentCount: number | null
+ sentCountLoading: boolean
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface broadcastPreviousSendLogicActions {
+ loadPreviousSend: () => any
+ loadPreviousSendFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadPreviousSendSuccess: (
+ previousSend: PreviousSend | null,
+ payload?: any
+ ) => {
+ previousSend: PreviousSend | null
+ payload?: any
+ }
+ loadSentCount: (job: HogFlowBatchJobApi) => HogFlowBatchJobApi
+ loadSentCountFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadSentCountSuccess: (
+ sentCount: number | null,
+ payload?: HogFlowBatchJobApi
+ ) => {
+ sentCount: number | null
+ payload?: HogFlowBatchJobApi
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface broadcastPreviousSendLogicMeta {
+ key: string
+}
+
+export type broadcastPreviousSendLogicType = MakeLogicType<
+ broadcastPreviousSendLogicValues,
+ broadcastPreviousSendLogicActions,
+ BroadcastPreviousSendLogicProps,
+ broadcastPreviousSendLogicMeta
+>
+
+export const broadcastPreviousSendLogic = kea<broadcastPreviousSendLogicType>([
+ path(['products', 'workflows', 'frontend', 'Broadcasts', 'broadcastPreviousSendLogic']),
+ props({} as BroadcastPreviousSendLogicProps),
+ key((props) => props.sourceRecord),
+ connect(() => ({
+ values: [projectLogic, ['currentProjectId'], teamLogic, ['currentTeam']],
+ })),
+
+ loaders(({ props, values }) => ({
+ previousSend: [
+ null as PreviousSend | null,
+ {
+ loadPreviousSend: async (): Promise<PreviousSend | null> => {
+ const projectId = String(values.currentProjectId)
+ // Filtered by record only: archived broadcasts still emailed people, and a status filter
+ // would evaluate every workflow in the project before the record narrows it.
+ const page = await hogFlowsList(projectId, {
+ source_record: props.sourceRecord,
+ limit: RECENT_BROADCASTS,
+ })
+ let pending: PreviousSend | null = null
+ for (const flow of (page.results ?? []).filter((flow) => flow.status !== 'draft')) {
+ const jobs = await hogFlowsBatchJobsList(projectId, flow.id)
+ const sent = jobs.find((job) => job.status === 'completed')
+ if (sent) {
+ return { broadcastId: flow.id, state: 'sent', job: sent }
+ }
+ const running = jobs.find((job) => PENDING_JOB_STATES.has(job.status ?? ''))
+ if (!pending && running) {
+ pending = {
+ broadcastId: flow.id,
+ state: running.status === 'active' ? 'sending' : 'scheduled',
+ job: null,
+ }
+ }
+ if (!pending && !jobs.length && flow.status === 'active') {
+ const schedules = await hogFlowsSchedulesList(projectId, flow.id)
+ if (schedules.some((schedule) => schedule.status === 'active')) {
+ pending = { broadcastId: flow.id, state: 'scheduled', job: null }
+ }
+ }
+ }
+ return pending
+ },
+ },
+ ],
+ sentCount: [
+ null as number | null,
+ {
+ loadSentCount: async (job: HogFlowBatchJobApi): Promise<number | null> => {
+ const totals = await loadRunMetricTotals(job, values.currentTeam?.timezone ?? 'UTC')
+ return totals.email_sent ?? null
+ },
+ },
+ ],
+ })),
+
+ listeners(({ actions }) => ({
+ // The count reads app metrics, which can be slow, so the warning shows before it arrives.
+ loadPreviousSendSuccess: ({ previousSend }) => {
+ if (previousSend?.state === 'sent' && previousSend.job) {
+ actions.loadSentCount(previousSend.job)
+ }
+ },
+ })),
+
+ afterMount(({ actions }) => {
+ actions.loadPreviousSend()
+ }),
+])
diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
index b839d5121387..a831852054cf 100644
--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
@@ -99,7 +99,9 @@ import {
type BroadcastPrefill,
NAME_PREFILL_PARAM,
parseBroadcastAudiencePrefill,
+ parseSourceRecordPrefill,
SOURCE_PREFILL_PARAM,
+ SOURCE_RECORD_PREFILL_PARAM,
} from './broadcastAudiencePrefill'
import {
confirmArchiveBroadcast,
@@ -315,6 +317,7 @@ export interface broadcastWizardLogicValues {
scheduleTimezone: string | null
selectedSender: IntegrationType | null
sendAt: string | null
+ sourceRecord: string | null
stepValidationErrors: Record<BroadcastWizardStep, string[]>
summaryStatus: BroadcastStatus
summaryTab: BroadcastSummaryTab
@@ -899,6 +902,12 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
prefillFromLink: (_, { prefill }) => prefill.source ?? null,
},
],
+ sourceRecord: [
+ null as string | null,
+ {
+ prefillFromLink: (_, { prefill }) => prefill.sourceRecord ?? null,
+ },
+ ],
audienceCohortLaunchErrors: [
[] as AudienceCohortLaunchError[],
{
@@ -2220,6 +2229,7 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
[AUDIENCE_PREFILL_PARAM]: audience,
[NAME_PREFILL_PARAM]: name,
[SOURCE_PREFILL_PARAM]: source,
+ [SOURCE_RECORD_PREFILL_PARAM]: sourceRecordParam,
[EMAIL_PREFILL_PARAM]: emailParam,
[DRAFT_SOURCE_PARAM]: draftSourceParam,
} = router.values.searchParams
@@ -2229,6 +2239,7 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
audience !== undefined ||
name !== undefined ||
source !== undefined ||
+ sourceRecordParam !== undefined ||
emailParam !== undefined ||
draftSourceParam !== undefined
if (fromLink) {
@@ -2236,6 +2247,7 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
properties: properties ?? [],
name: typeof name === 'string' ? name : undefined,
source: typeof source === 'string' ? source : undefined,
+ sourceRecord: parseSourceRecordPrefill(sourceRecordParam),
email: email ?? undefined,
}
// Not setAudienceProperties: opening /broadcasts/new must not create a draft.
@@ -2321,7 +2333,10 @@ function seedTeamUtmDefaults(
}
async function createDraft(projectId: string, values: broadcastWizardLogicType['values']): Promise<HogFlowApi> {
- const created = await hogFlowsCreate(projectId, buildBroadcastPayload(values) as any)
+ const created = await hogFlowsCreate(projectId, {
+ ...buildBroadcastPayload(values),
+ ...(values.sourceRecord ? { source_record: values.sourceRecord } : {}),
+ } as any)
// pinned: analytics event name
posthog.capture('broadcast draft created', { broadcast_id: created.id, entry_source: values.entrySource })
return created
diff --git a/products/workflows/frontend/Broadcasts/broadcastsLogic.ts b/products/workflows/frontend/Broadcasts/broadcastsLogic.ts
index a743a2c52051..5629cf14e4e8 100644
--- a/products/workflows/frontend/Broadcasts/broadcastsLogic.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastsLogic.ts
@@ -183,7 +183,7 @@ export function getBroadcastStatus(
// A batch send's email metrics are recorded against the batch job, not the flow, so the row counts
// come from the latest run rather than the flow-scoped totals endpoint.
-async function loadRunMetricTotals(job: HogFlowBatchJobApi, timezone: string): Promise<Record<string, number>> {
+export async function loadRunMetricTotals(job: HogFlowBatchJobApi, timezone: string): Promise<Record<string, number>> {
const created = dayjs(job.created_at)
const response = await loadAppMetricsTotals(
{
diff --git a/products/workflows/frontend/MessageAudience/messageAudience.ts b/products/workflows/frontend/MessageAudience/messageAudience.ts
index 16f1437d7db9..3721a945c79e 100644
--- a/products/workflows/frontend/MessageAudience/messageAudience.ts
+++ b/products/workflows/frontend/MessageAudience/messageAudience.ts
@@ -25,6 +25,8 @@ export interface MessageAudience {
workflowTrigger?: WorkflowTriggerConfig
broadcastEmail?: MessageDraft
workflowEmail?: MessageDraft
+ /** The record the email is about, as "<kind>:<id>". A later broadcast about it warns that it was already sent. */
+ sourceRecord?: string
draftSource?: EmailDraftRequestApi
}
@@ -46,6 +48,7 @@ export function messageAudienceUrl(audience: MessageAudience, destination: Messa
properties: audience.properties,
name: audience.broadcastName,
source: audience.source,
+ sourceRecord: audience.sourceRecord,
email: audience.broadcastEmail,
draftSource: audience.draftSource,
})
diff --git a/products/workflows/frontend/generated/api.schemas.ts b/products/workflows/frontend/generated/api.schemas.ts
index 8497f8a8dcf9..5d8878679569 100644
--- a/products/workflows/frontend/generated/api.schemas.ts
+++ b/products/workflows/frontend/generated/api.schemas.ts
@@ -689,6 +689,13 @@ export interface HogFlowApi {
* * `broadcasts` - Broadcasts
* * `transactional_emails` - Transactional emails */
origin_product?: HogFlowOriginProductEnumApi | null
+ /**
+ * The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`.
+ * @maxLength 255
+ * @nullable
+ * @pattern ^[a-z_]+:[A-Za-z0-9_-]+$
+ */
+ source_record?: string | null
readonly created_at: string
readonly created_by: UserBasicApi
readonly updated_at: string
@@ -2859,6 +2866,10 @@ export type HogFlowsListParams = {
* Case-insensitive search. Matches workflow name, description and tag names first; only when nothing matches those, it matches step names and the subject line, preheader and body text of email steps, in both the live workflow and its pending draft.
*/
search?: string
+ /**
+ * Filter to workflows started from this record, as '<kind>:<id>', e.g. `early_access:<id>`.
+ */
+ source_record?: string
/**
* * `draft` - Draft
* * `active` - Active
diff --git a/products/workflows/frontend/generated/api.zod.ts b/products/workflows/frontend/generated/api.zod.ts
index 5242ef11b070..565ec0562f9a 100644
--- a/products/workflows/frontend/generated/api.zod.ts
+++ b/products/workflows/frontend/generated/api.zod.ts
@@ -512,6 +512,9 @@ export const hogFlowsCreateBodyTagsItemMax = 255
export const hogFlowsCreateBodyTagsMax = 10
+export const hogFlowsCreateBodySourceRecordMax = 255
+
+export const hogFlowsCreateBodySourceRecordRegExp = new RegExp('^[a-z_]+:[A-Za-z0-9_-]+$')
export const hogFlowsCreateBodyTriggerMaskingOneTtlMin = 60
export const hogFlowsCreateBodyTriggerMaskingOneTtlMax = 94608000
@@ -561,6 +564,14 @@ export const HogFlowsCreateBody = /* @__PURE__ */ zod
.describe(
'Product surface that owns this workflow (e.g. `loops` for Desktop loops). Set only when creating a workflow. Filter the list with `?origin_product=`.\n\n\* `loops` - Loops\n\* `broadcasts` - Broadcasts\n\* `transactional_emails` - Transactional emails'
),
+ source_record: zod
+ .string()
+ .max(hogFlowsCreateBodySourceRecordMax)
+ .regex(hogFlowsCreateBodySourceRecordRegExp)
+ .nullish()
+ .describe(
+ "The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`."
+ ),
trigger_masking: zod
.union([
zod.object({
@@ -1933,6 +1944,9 @@ export const hogFlowsInvocationsCreateBodyConfigurationOneTagsItemMax = 255
export const hogFlowsInvocationsCreateBodyConfigurationOneTagsMax = 10
+export const hogFlowsInvocationsCreateBodyConfigurationOneSourceRecordMax = 255
+
+export const hogFlowsInvocationsCreateBodyConfigurationOneSourceRecordRegExp = new RegExp('^[a-z_]+:[A-Za-z0-9_-]+$')
export const hogFlowsInvocationsCreateBodyConfigurationOneCreatedByOneDistinctIdMax = 200
export const hogFlowsInvocationsCreateBodyConfigurationOneCreatedByOneFirstNameMax = 150
@@ -2006,6 +2020,14 @@ export const HogFlowsInvocationsCreateBody = /* @__PURE__ */ zod.object({
.describe(
'Product surface that owns this workflow (e.g. `loops` for Desktop loops). Set only when creating a workflow. Filter the list with `?origin_product=`.\n\n\* `loops` - Loops\n\* `broadcasts` - Broadcasts\n\* `transactional_emails` - Transactional emails'
),
+ source_record: zod
+ .string()
+ .max(hogFlowsInvocationsCreateBodyConfigurationOneSourceRecordMax)
+ .regex(hogFlowsInvocationsCreateBodyConfigurationOneSourceRecordRegExp)
+ .nullish()
+ .describe(
+ "The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`."
+ ),
created_at: zod.iso.datetime({ offset: true }),
created_by: zod.object({
id: zod.number(),
@@ -2865,6 +2887,9 @@ export const hogFlowsBulkDeleteCreateBodyTagsItemMax = 255
export const hogFlowsBulkDeleteCreateBodyTagsMax = 10
+export const hogFlowsBulkDeleteCreateBodySourceRecordMax = 255
+
+export const hogFlowsBulkDeleteCreateBodySourceRecordRegExp = new RegExp('^[a-z_]+:[A-Za-z0-9_-]+$')
export const hogFlowsBulkDeleteCreateBodyTriggerMaskingOneTtlMin = 60
export const hogFlowsBulkDeleteCreateBodyTriggerMaskingOneTtlMax = 94608000
@@ -2919,6 +2944,14 @@ export const HogFlowsBulkDeleteCreateBody = /* @__PURE__ */ zod
.describe(
'Product surface that owns this workflow (e.g. `loops` for Desktop loops). Set only when creating a workflow. Filter the list with `?origin_product=`.\n\n\* `loops` - Loops\n\* `broadcasts` - Broadcasts\n\* `transactional_emails` - Transactional emails'
),
+ source_record: zod
+ .string()
+ .max(hogFlowsBulkDeleteCreateBodySourceRecordMax)
+ .regex(hogFlowsBulkDeleteCreateBodySourceRecordRegExp)
+ .nullish()
+ .describe(
+ "The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`."
+ ),
trigger_masking: zod
.union([
zod.object({
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 637cf2d06aae..1748bde0d6bc 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -58630,6 +58630,13 @@ export namespace Schemas {
* * `broadcasts` - Broadcasts
* * `transactional_emails` - Transactional emails */
origin_product?: HogFlowOriginProductEnum | null;
+ /**
+ * The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`.
+ * @maxLength 255
+ * @nullable
+ * @pattern ^[a-z_]+:[A-Za-z0-9_-]+$
+ */
+ source_record?: string | null;
readonly created_at: string;
readonly created_by: UserBasic;
readonly updated_at: string;
@@ -133666,6 +133673,10 @@ export namespace Schemas {
* Case-insensitive search. Matches workflow name, description and tag names first; only when nothing matches those, it matches step names and the subject line, preheader and body text of email steps, in both the live workflow and its pending draft.
*/
search?: string;
+ /**
+ * Filter to workflows started from this record, as '<kind>:<id>', e.g. `early_access:<id>`.
+ */
+ source_record?: string;
/**
* * `draft` - Draft
* * `active` - Active
diff --git a/services/mcp/src/generated/workflows/api.ts b/services/mcp/src/generated/workflows/api.ts
index c2df918743b9..da4c35722ec3 100644
--- a/services/mcp/src/generated/workflows/api.ts
+++ b/services/mcp/src/generated/workflows/api.ts
@@ -45,6 +45,10 @@ export const HogFlowsListQueryParams = () => zod.object({
.describe(
'Case-insensitive search. Matches workflow name, description and tag names first; only when nothing matches those, it matches step names and the subject line, preheader and body text of email steps, in both the live workflow and its pending draft.'
),
+ source_record: zod
+ .string()
+ .optional()
+ .describe("Filter to workflows started from this record, as '<kind>:<id>', e.g. `early_access:<id>`."),
status: zod
.enum(['active', 'archived', 'draft'])
.optional()
@@ -85,6 +89,9 @@ export const hogFlowsCreateBodyTagsItemMax = 255
export const hogFlowsCreateBodyTagsMax = 10
+export const hogFlowsCreateBodySourceRecordMax = 255
+
+export const hogFlowsCreateBodySourceRecordRegExp = new RegExp('^[a-z_]+:[A-Za-z0-9_-]+$')
export const hogFlowsCreateBodyTriggerMaskingOneTtlMin = 60
export const hogFlowsCreateBodyTriggerMaskingOneTtlMax = 94608000
@@ -134,6 +141,14 @@ export const HogFlowsCreateBody = () => zod
.describe(
'Product surface that owns this workflow (e.g. `loops` for Desktop loops). Set only when creating a workflow. Filter the list with `?origin_product=`.\n\n\* `loops` - Loops\n\* `broadcasts` - Broadcasts\n\* `transactional_emails` - Transactional emails'
),
+ source_record: zod
+ .string()
+ .max(hogFlowsCreateBodySourceRecordMax)
+ .regex(hogFlowsCreateBodySourceRecordRegExp)
+ .nullish()
+ .describe(
+ "The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`."
+ ),
trigger_masking: zod
.union([
zod.object({
diff --git a/services/mcp/src/tools/generated/workflows.ts b/services/mcp/src/tools/generated/workflows.ts
index fad7f4dc2794..fc1f0f2e86fb 100644
--- a/services/mcp/src/tools/generated/workflows.ts
+++ b/services/mcp/src/tools/generated/workflows.ts
@@ -39,6 +39,9 @@ const broadcastsCreate = (): ToolBase<ReturnType<typeof BroadcastsCreateSchema>,
if (params.origin_product !== undefined) {
body['origin_product'] = params.origin_product
}
+ if (params.source_record !== undefined) {
+ body['source_record'] = params.source_record
+ }
if (params.trigger_masking !== undefined) {
body['trigger_masking'] = params.trigger_masking
}
@@ -120,6 +123,9 @@ const workflowsCreate = (): ToolBase<ReturnType<typeof WorkflowsCreateSchema>, W
if (params.origin_product !== undefined) {
body['origin_product'] = params.origin_product
}
+ if (params.source_record !== undefined) {
+ body['source_record'] = params.source_record
+ }
if (params.trigger_masking !== undefined) {
body['trigger_masking'] = params.trigger_masking
}
@@ -390,6 +396,7 @@ const workflowsList = (): ToolBase<
optimization_enabled: params.optimization_enabled,
origin_product: params.origin_product,
search: params.search,
+ source_record: params.source_record,
status: params.status,
tags: params.tags,
trigger: params.trigger,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/broadcasts-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/broadcasts-create.json
index 06ca3b6b5085..0f8493b4345f 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/broadcasts-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/broadcasts-create.json
@@ -554,6 +554,19 @@
],
"description": "Product surface that owns this workflow (e.g. `loops` for Desktop loops). Set only when creating a workflow. Filter the list with `?origin_product=`.\n\n* `loops` - Loops\n* `broadcasts` - Broadcasts\n* `transactional_emails` - Transactional emails"
},
+ "source_record": {
+ "anyOf": [
+ {
+ "maxLength": 255,
+ "pattern": "^[a-z_]+:[A-Za-z0-9_-]+$",
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`."
+ },
"status": {
"description": "draft (no execution), active (live), archived (disabled).\n\n* `draft` - Draft\n* `active` - Active\n* `archived` - Archived",
"enum": ["draft", "active", "archived"],
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create.json
index 06ca3b6b5085..0f8493b4345f 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create.json
@@ -554,6 +554,19 @@
],
"description": "Product surface that owns this workflow (e.g. `loops` for Desktop loops). Set only when creating a workflow. Filter the list with `?origin_product=`.\n\n* `loops` - Loops\n* `broadcasts` - Broadcasts\n* `transactional_emails` - Transactional emails"
},
+ "source_record": {
+ "anyOf": [
+ {
+ "maxLength": 255,
+ "pattern": "^[a-z_]+:[A-Za-z0-9_-]+$",
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "The record another product's entry point started this workflow from, as '<kind>:<id>'. Set only when creating a workflow. Filter the list with `?source_record=`."
+ },
"status": {
"description": "draft (no execution), active (live), archived (disabled).\n\n* `draft` - Draft\n* `active` - Active\n* `archived` - Archived",
"enum": ["draft", "active", "archived"],
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-list.json
index 71d1e66fd5c4..55a7ccd9804f 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-list.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-list.json
@@ -42,6 +42,10 @@
"description": "Case-insensitive search. Matches workflow name, description and tag names first; only when nothing matches those, it matches step names and the subject line, preheader and body text of email steps, in both the live workflow and its pending draft.",
"type": "string"
},
+ "source_record": {
+ "description": "Filter to workflows started from this record, as '<kind>:<id>', e.g. `early_access:<id>`.",
+ "type": "string"
+ },
"status": {
"description": "* `draft` - Draft\n* `active` - Active\n* `archived` - Archived",
"enum": ["active", "archived", "draft"],