Skip to content

feat(emails): send a code email in a message category - #204

Merged
Silthus merged 10 commits into
mainfrom
feat/emails-send-category
Dec 2, 2026
Merged

Silthus merged 10 commits into
mainfrom
feat/emails-send-category

Conversation

@Silthus

@Silthus Silthus commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A code send (the template_key form of emails.send) could only send a transactional email with no message category. A team that moves a workflow's marketing email to a code send loses its category, so the recipient's opt-outs and the unsubscribe headers stop applying.

The send API takes an optional category on a code send, from PostHog/posthog#142574 and PostHog/posthog#142564, both merged and live in both regions. The eight server SDKs treat this spec as their shared contract, so it records the field they agree on.

Merge Danger

Warning

🟡 Merge risk: medium · two-way door at merge: spec text with no runtime code, and all eight SDK PRs are still open. It turns one-way once a public SDK release exposes category to callers.
Impact: medium 👀

  • Eight server SDKs take their category contract from this spec.
    Verification: decent 👀
  • The Gherkin scenarios have no harness bindings, so no SDK ran them.
    Rollback cost: low ✅
    Error detection: N/A ✅
    Alignment: decent 👀
  • The attachment rule names workflow_can_wait and sandbox_fields_unsupported; a project with attachment uploads off gets field_not_accepted first.
  • The test-sender sentence covers the category's effect only; other test-sender refusals apply as without a category.
  • Tier: non-critical (spec text only: no runtime code, no release, two-way door)

Changes

The code form of emails.send takes an optional category: the key of one of the project's message categories, such as newsletter, sent as given and only when the caller sets it. A template send refuses it, because a template sends in its own category. The spec states the server's effect and names the refusal codes category_not_found, marketing_copies_unsupported and sandbox_fields_unsupported, which the existing error rules already cover.

Rejected: a category object with a type and name, because the merged server takes only the key.

No picture: the diff shows it whole.

  • New Send message category: wire shape, the left-out rule (no default), the server's effect for marketing and transactional categories, the test-sender rule, and the refusal codes, including workflow_can_wait for a marketing send with attachments.
  • Send code form, Send request: category joins the code-form inputs next to cc, bcc, attachments, sensitive and tracking from main.
  • Error names: "a coarse class" instead of "a coarse category". (mechanical)
  • acceptance/public/emails.feature: the key on the wire, and a refused category send that keeps its code and is not retried.
  • The change is archived as 2026-11-10-add-emails-send-category; its delta matches the merged spec. (mechanical)

Depends on: PostHog/posthog#142574, PostHog/posthog#142564 (both merged).

Read yourself: Send message category: does each sentence match what the merged server does?

Evidence

What was proven, and what not

  • ✅ openspec validate --specs --strict --no-interactive with @fission-ai/openspec@1.4.1, the version CI pins: 71 passed, 0 failed at 3714ef9.
  • ✅ The diff against main touches only the emails spec, its archived change and the emails feature.
  • ✅ Checked against the merged server: the category field and its help text, and the category_not_found, marketing_copies_unsupported, sandbox_fields_unsupported and workflow_can_wait refusals.
  • ❌ No SDK ran the email scenarios: they have no harness bindings yet.

CI at 3714ef9, read 2026-12-02 07:29 UTC: all 12 checks pass.

SDK PRs that follow this contract: posthog-js#5638, posthog-python#1218, posthog-go#435, posthog-ruby#350, posthog-php#309, posthog-dotnet#378, posthog-elixir#244, posthog-rs#345.

Known issues

  • The refusal outline has no marketing_copies_unsupported row, because its send carries no copies.
  • No Gherkin scenario sends a template with a category; the spec's scenario under Send code form covers it.

Decisions

Question Answer Who Where
What does category hold? The key of an existing category, as a string 👤 Human server
Which send form takes category? The code form only 👤 Human server
Does the switched-off refusal go in the spec? No: a field error with no dedicated code 👤 Human comment
What does "left out" mean for null? The SDK's own unset value 🤖 Agent comment
Does the spec promise a replay after a deleted category? No: the server can refuse a retry before it checks the key 🤖 Agent revert

Involvement: no grilling rounds; Opus 5.5 wrote the spec, first for a category object, then for the merged key string, and merged main after #191 and #280. GPT-6.2 Sol and Opus 5.5 review rounds and final reads, and PostHog Review on the heads.

🤖 Generated with Claude Code

How did you test this code?

Merge card: medium, two-way door · 3 rounds, 4 final reads, 3 past the budget · gaps: judge (🤖 agent d-d4871fda) · 2 known issues · still a draft

Proof What ran Result Commit
Review 1-lens panel (claude-opus-5-5, gpt-6.2-sol), round 1, round 2, final read 1, final read 2, round 3, final read 3, final read 4 18 findings: 14 fixed, 4 rejected, 0 other c5e9e01 to 3714ef9
Proof judge an independent model reads the evidence against the diff ❌ failed at 3714ef9
PR Review rounds Production lines Skipped proofs
#204 3 rounds, 4 final reads, 3 past the budget unknown → 26; docs unknown → 278 judge: The last judge run failed only risk, asking the door line to say the door turns one-way once a public SDK release exposes category. The body now says so. Proof, owed, review, shape and quality passed on 3714ef9; the quality notes are minor wording and stay as Known issues and Alignment gaps. (🤖 agent d-d4871fda)

Not checked: none recorded
Full receipt: https://artifacts.posthog.com/a/uAMWSMcTOlMEG4NfOzcfms

posthog Bot and others added 2 commits November 6, 2026 07:06
posthog-node and posthog-python both shipped sending rendered content
through emails.send, while the spec still said the send API does not
accept that form. Records the code form, its wire body, the
one-form-per-call refusals and the migration header, and archives the
change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 2b5bdd0e-baf9-4886-bf83-0f9b3ea513b1
A code send could only send a transactional email with no message
category, so moving a workflow's marketing email to emails.send lost its
category, and with it the recipient's opt-outs. Records the optional
category on the code form that the send API and the eight server SDKs
now share: the built-in "transactional" value or a { key, type, name,
description? } object, its wire shape and left-out rule, the shape-only
local check, and PostHog's refusal codes. Archives the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silthus Silthus self-assigned this Nov 10, 2026
@Silthus

Silthus commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

🤖 Claude Opus 5.5 responding on behalf of Michael

Decision lines for this change:

  • 👤 What does category hold? The key of an existing message category, as a plain string. The merged server (feat(messaging): name a message category on a code send posthog#142574) takes only the key, so the earlier category object with a type and name is gone.
  • 👤 Which send form takes category? The code form only. A template sends in its own category, so a template send refuses it.
  • 👤 Does the switched-off refusal go in the spec? No. While a project's categories are switched off, PostHog answers with a field error that has no dedicated code, so it is not part of the lasting contract.
  • 🤖 What does "left out" mean for null? The SDK's own unset value. posthog-node uses undefined and refuses null (feat(node): send email in a message category with emails.send posthog-js#5638), while the other seven SDKs treat their nil, None or null as unset.
  • 🤖 Where do the category error codes live? Under the existing Error fields, Error names and Retryable responses rules, which already keep each code unchanged, map it to validation_error and never retry it.
  • 🤖 Does the spec promise a replay after a deleted category? No. The server can refuse a retry before it checks the key, so the sentence was reverted in 3714ef9.

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed c5e9e01: 1 Should fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

Comment thread openspec/specs/emails/spec.md Resolved
A code send whose template key matches a stored template sends in that
template's category and upserts nothing, so the upsert rule now says
when it applies. Send code form lists the message category among its
inputs and states that a template send refuses it. The one length check
an SDK may make is named, and the category refusal scenarios run on a
code-form send, the only send that can carry a category.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 2b877d4: no findings.

Silthus and others added 2 commits November 10, 2026 08:20
Send code form said a template key is never a stored template, which now
contradicted the category rule for a key that matches one; it points to
Send message category. The match rule reads as PostHog's behavior, not an
SDK duty, and the empty-key allowance reads as one list. The code-form
refusal outline covers every category code a code send can get.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unsubscribe_link_required example now sends HTML without the
placeholder, so no row shows PostHog refusing a body that meets the
rule. Send code form says a template key need not name a stored
template, which no longer reads against the stored-template caveat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 4aa35ae: no findings.

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed d89ab4e: no findings.

Silthus and others added 2 commits November 27, 2026 05:21
The merged send API takes `category` as the key of an existing message
category on a code send. Drop the category object, the built-in
transactional value, the upsert and template-key rules, and the codes the
server never shipped. Add `category_not_found`,
`marketing_copies_unsupported` and `sandbox_fields_unsupported`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A transactional category goes out from the PostHog test sender with the
sandbox_sender warning, and a marketing category is refused with
sandbox_fields_unsupported, as the merged send view and the pipeline's
sandbox code send do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gory

# Conflicts:
#	acceptance/public/emails.feature
#	openspec/changes/archive/2026-11-06-add-emails-code-form/proposal.md
#	openspec/changes/archive/2026-11-06-add-emails-code-form/specs/emails/spec.md
#	openspec/specs/emails/spec.md

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 63c6282: no findings.

…deleted category

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed e654706: no findings.

The server can refuse a retry before it checks the idempotency key, so
the sentence promised more than PostHog does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silthus
Silthus marked this pull request as ready for review December 2, 2026 07:45
@Silthus
Silthus requested a review from a team as a code owner December 2, 2026 07:45

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 3714ef9: no findings.

@Silthus
Silthus merged commit b318554 into main Dec 2, 2026
12 checks passed
@Silthus
Silthus deleted the feat/emails-send-category branch December 2, 2026 08:56
Silthus added a commit that referenced this pull request Dec 2, 2026
… sends

Merges #204 (send a code email in a message category). The code form's
surface and wire rows carry both `category` and `scheduledAt`, and a
scheduled code-form send takes the message category, as PostHog's send
route accepts `category` with `scheduled_at`. The batch route refuses
`category`, so the code form on `batch` stays under Not covered with the
message category among the fields that route refuses. The archived
scheduled-and-batch delta and proposal match the merged spec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silthus added a commit that referenced this pull request Dec 2, 2026
* revert(emails): remove the message category from code sends

Code-sent emails are staying strictly transactional, so message
category support on code sends is being reverted. Removes the Send
message category requirement, the category input from Send code form
and Send request, and the category scenarios from the acceptance
feature. Keeps the archived 2026-11-10-add-emails-send-category change
as history and archives 2026-12-02-remove-emails-send-category.

Reverts b318554 (#204).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(emails): record the scheduled send change in the removal delta

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(emails): keep the test sender rule for category-free code sends

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(emails): keep an acceptance case for the test sender refusal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): say the test sender sends only to organization members

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): order the test sender's field and recipient checks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): name both sandbox codes and when a recipient is refused

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): tell the intake refusal from the check before delivery

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): name the later not_member status and test the 422 refusal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): cover the unfinished intake check and both sandbox scenarios

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): an unfinished member check leaves the other intake checks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): promise only the intake refusal and the check before delivery

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): require SDKs that published category to refuse it locally

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): null category is unset, list every SDK that published it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): keep null as unset only where an SDK already did

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(emails): add the local category refusal case and error precedence

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(emails): assert retired category error details and note unbound feature

* test(emails): pass an attachment in the category refusal case

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): give the refusal case real attachment bytes, fix the summary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): native field names, empty and null category cases

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(emails): cut the unbound retired-category acceptance case

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(emails): field checks come first, deprecation warnings as errors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant