Skip to content

chore: hook up provisioning_welcome Customer.io template#58820

Merged
MattBro merged 2 commits into
masterfrom
matt/provisioning-welcome-template-id
May 20, 2026
Merged

chore: hook up provisioning_welcome Customer.io template#58820
MattBro merged 2 commits into
masterfrom
matt/provisioning-welcome-template-id

Conversation

@MattBro
Copy link
Copy Markdown
Contributor

@MattBro MattBro commented May 18, 2026

Problem

The welcome email for provisioned users (sent by send_provisioning_welcome in posthog/tasks/email.py:382) was silently dropped in production. EmailMessage(use_http=True, template_name="provisioning_welcome", ...) routes through the Customer.io HTTP sender, which calls get_customer_io_template_id("provisioning_welcome") and raises Unknown template name because that template was never added to CUSTOMER_IO_TEMPLATE_ID_MAP in posthog/email.py. The exception is caught and capture_exception-d at views.py:658-662, so provisioning succeeds with zero user-visible signal that the email failed.

Changes

  • Add "provisioning_welcome": "67" to CUSTOMER_IO_TEMPLATE_ID_MAP.
  • Add a regression test that walks every .py under posthog/ (skipping test_*.py and test/ dirs) via ast and asserts every EmailMessage(use_http=True, template_name="X") has "X" in the map. Stops the same silent-failure pattern from recurring when future transactional emails are added — covers posthog/tasks/email.py, posthog/temporal/proxy_service/common.py, posthog/approvals/notifications.py, and anything new.

Template 67 is Welcome to PostHog - set your password in the EU Customer.io workspace. Variables match what send_provisioning_welcome passes (link, site_url, preheader, partner_name, cloud).

image

How did you test this code?

Agent author. Tests run:

  • pytest posthog/test/test_email.py::TestEmail::test_all_http_templates_are_registered_in_customer_io_map — passes locally.
  • Used the cio CLI to send a live transactional message via template 67 to matt@posthog.com with the exact payload shape send_provisioning_welcome produces. Delivery confirmed (id ROjhBwUAAZ47Xh8nfKVYBN2BYD_FVg==, state sent).

Publish to changelog?

No.

🤖 Agent context

Co-authored by Claude (Opus 4.7). Surfaced in a session triaging security ticket #669 (CIMD pre-account-takeover). Three stacked PRs are planned to land:

  • PR A (this PR): hook up the Customer.io template so the welcome email actually sends.
  • PR B: flip is_email_verified to True on password reset (proves email ownership via the unique token from the reset link).
  • PR C: credential review interstitial on first post-provisioning login so users can revoke any partner-issued API key they don't recognize.

A and B have no code dependency; both are conceptually prerequisites for C. Stacked via Graphite. Decisions made: chose an AST-parse regression test over an enumerated list of template names so the check stays correct when new transactional emails are added; placed the test in posthog/test/test_email.py rather than posthog/tasks/test/test_email.py since the assertion is about CUSTOMER_IO_TEMPLATE_ID_MAP (defined in posthog/email.py).

CUSTOMER_IO_TEMPLATE_ID_MAP was missing an entry for the
"provisioning_welcome" template name used by send_provisioning_welcome
(posthog/tasks/email.py:382). The Customer.io HTTP sender raised
"Unknown template name", and the Celery task swallowed it via
capture_exception, so the welcome email silently failed for every
provisioned user.

Verified the template exists in the EU workspace (transactional
message id 67, "Welcome to PostHog - set your password") and that
template variables match what send_provisioning_welcome passes
(link, site_url, preheader, partner_name, cloud).

Add a regression test that parses posthog/tasks/email.py and asserts
every EmailMessage(use_http=True, template_name="X") has "X" in
CUSTOMER_IO_TEMPLATE_ID_MAP, so the same silent-failure mode doesn't
recur when future transactional emails are added.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

🎭 Playwright didn't run on this PR — your changes touch code that could affect E2E behavior, but Playwright is opt-in via label now to keep CI cost down.

Add the run-playwright label if you want an E2E sweep before merging — CI will pick it up automatically.

Most PRs don't need this. Real regressions still get caught on master and fix-forward.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
posthog/test/test_email.py:337-340
The AST scan is scoped only to `posthog/tasks/email.py`, but `posthog/temporal/proxy_service/common.py` also contains `EmailMessage(use_http=True, template_name="proxy_provisioned", ...)` with a literal template name. If someone adds a new HTTP transactional email in that file (or any other future file in the `posthog/` tree) and forgets the map entry, the test will silently pass. Widening the scan to all `.py` files under `posthog/` catches the same silent-failure pattern everywhere.

```suggestion
        import posthog.tasks.email as email_tasks

        repo_root = Path(email_tasks.__file__).parent.parent
        sources = list(repo_root.glob("posthog/**/*.py"))
```

Reviews (1): Last reviewed commit: "chore: hook up provisioning_welcome Cust..." | Re-trigger Greptile

Comment thread posthog/test/test_email.py Outdated
…code

posthog/temporal/proxy_service/common.py and posthog/approvals/notifications.py also call EmailMessage(use_http=True, template_name=...), so a future new transactional email added anywhere under posthog/ (not just posthog/tasks/email.py) would slip past the regression assert. Walk the whole package, skip test_*.py and test/ dirs so synthetic test templates don't have to be mapped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@rafaeelaudibert rafaeelaudibert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is good!

Feedback on the email: suggest using the MCP too.

@MattBro MattBro merged commit 2fe6110 into master May 20, 2026
306 of 308 checks passed
@MattBro MattBro deleted the matt/provisioning-welcome-template-id branch May 20, 2026 14:00
@deployment-status-posthog
Copy link
Copy Markdown

deployment-status-posthog Bot commented May 20, 2026

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-05-20 14:34 UTC Run
prod-us ✅ Deployed 2026-05-20 14:55 UTC Run
prod-eu ✅ Deployed 2026-05-20 15:07 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants