Repository navigation
feat(messaging): refuse transactional sends the email worker would skip - #123019
Conversation
The CDP transactional email route now checks project suspension, the workflow's email pause and the suppression list before it queues a send, and returns a code for each. Django maps those codes to 422s, and maps a deactivated workflow to transactional_email_paused instead of a 503. The internal transactional email client carries the API error code, and the Self-driving first-report email cancels on recipient_suppressed instead of retrying on every sweep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: a0274fa0-d9be-48bf-b601-f153decf241d
|
😎 Merged successfully - details. |
🤖 CI report
|
| File | Comment lines | Added lines |
|---|---|---|
nodejs/src/cdp/cdp-api.ts |
3 | 34 |
products/messaging/backend/services/transactional_email.py |
2 | 46 |
products/signals/backend/first_report_notification.py |
1 | 4 |
This check does not block merging. It updates on every push and clears when the share drops.
⚠️ Playwright — 1 flaky
🎭 Playwright report · View test results →
- Creating a SQL insight with a variable and overriding it on a dashboard (chromium)
These issues are not necessarily caused by your changes.
Annoyed by this section? Help fix flakies and failures and it will go green!
|
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 77ff839: 1 Should fix.
This Standard review started from the posthog-review label. Comment @posthog review --deep for a Deep review, or @posthog help to see all commands.
See this review and its findings in PostHog Review.
| "The recipient is on this project's suppression list after a hard bounce or a spam complaint, so the " | ||
| "email can't be sent. Remove the address from the suppression list if it can receive email again.", | ||
| ), | ||
| "not_sendable": (TransactionalEmailPaused, "The template's transactional email isn't active."), |
There was a problem hiding this comment.
P2 · Return the refusal code from Node for inactive workflows
When a workflow is deactivated after Django's check, Node returns error: 'Workflow is not an active transactional email', not not_sendable. This new mapping never matches, so the API still returns retryable 503 instead of 400 transactional_email_paused. Return the machine code from Node and make the test exercise that actual response.
There was a problem hiding this comment.
Fixed in 36cf68b: Node now returns { error: 'not_sendable' } for an inactive or non-API workflow, and the Node test asserts that body, so it matches the Django mapping.
…al workflows Django maps a CDP refusal by the `error` code in the body. The inactive-workflow branch returned a sentence, so the mapping to transactional_email_paused never matched and the API fell back to a retryable 503. Generated-By: PostHog Desktop Task-Id: e466108a-be48-4e99-ac1a-d2523810860c
|
Risk: No findings This change makes the transactional email pipeline refuse sends up front (422 with a stable code) for suspension, pause, and suppression instead of accepting them with a 202 the worker then silently skips, and teaches the Django wrapper, internal client, and the signals first-report sweep to react to the new codes. I found no security vulnerabilities introduced: the new checks run after the scoped-JWT and team/workflow scoping on the CDP route, the lookups are parameterized, the idempotency-key release on refusal is correctly guarded against freeing another request's reservation, and the refusal-code mapping cannot turn a non-retryable state into caller-visible confusion beyond what the codes describe. Sentinel reviewed |
There was a problem hiding this comment.
Approved.
Risky API and write-path changes have assurance through owning-team authorship and STRONG familiarity, with focused regression tests. The older bot concern is fixed in the current code and covered by matching Node and Django assertions; no outstanding substantive concerns remain.
- Author wrote 86% of the modified lines and has 64 merged PRs in these paths (familiarity STRONG).
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 150L, 7F substantive, 244L/11F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (244L, 11F, cross-cutting, feat) |
| stamphog 2.6.1 | .stamphog/policy.yml @ 36cf68b · reviewed head 36cf68b |
|
/trunk merge |
Problem
202for an email that never goes out, and has no way to find out.202when sending is suspended for the project, sending is paused for the workflow, or the recipient is on the suppression list.Changes
422with a specificcodeinstead of202for these three cases. Nothing is queued or billed:sending_suspendedsending_pausedrecipient_suppressederrorcode in the body, not by status. A workflow deactivated mid-request now returns400 transactional_email_paused, not a retryable503.posthog/transactional_email.pyexposes the API errorcodeonTransactionalEmailRejected.recipient_suppressed. Before, it retried a rejected send on every sweep, so a suppressed address would loop forever.422description lists the new reasons. No generated files change.How did you test this code?
Test rationale:
cdp-api.serial.test.ts: added oneit.eachwith a case per refusal. It catches a route that queues a send the worker would skip, or one that keeps the idempotency key after a refusal, which would block the fixed retry.afterEach(jest.restoreAllMocks). The quota test's spy leaked into later tests and made them look over quota.test_reports_a_send_the_pipeline_refuses: extended with the new codes andnot_sendable. It catches a CDP refusal that falls through to503.test_confirmed_rejection: one case that catches the API error code being dropped.test_suppressed_recipient_cancels_the_notificationcatches the retry loop on a suppressed recipient.Ran locally: the three Python test modules above, and the
transactional emailblock of the Node test. Not run: the full Node and backend suites, and an end-to-end send through a real worker.Release status
Docs update
A posthog.com docs PR for the transactional email API follows, and it documents these codes.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Agent: PostHog Desktop (Claude Code), Claude Opus 5.5
/improving-drf-endpoints,/writing-tests,/writing-code-comments,/writing-pr-descriptions.master.🤖 Generated with Claude Code
Created with PostHog Desktop