Skip to content

feat(emails): send one email to many recipients with emails.batch - #1291

Open
Silthus wants to merge 38 commits into
feat/email-scheduled-sendfrom
feat/email-batch
Open

Silthus wants to merge 38 commits into
feat/email-scheduled-sendfrom
feat/email-batch

Conversation

@Silthus

@Silthus Silthus commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Sending the same email to up to 100 people now takes one call and one request: emails.batch(recipients=[...], template_id=...), one email per recipient, with template_data per recipient for a template. Today a caller loops over send, one request per recipient. The server route, POST /api/messaging/send/email_batch/, comes in PostHog/posthog#138258 and PostHog/posthog#138025, behind workflows-email-batch-sends.

Stacked on #1240 (scheduled_at), since both change posthog/emails.py.

Impact

A batch replaces a loop of single sends for digests, invites and announcements, and keeps each recipient's result readable. The SDK carries no flag of its own; the server flag decides who can send batches, and a project without it answers 404, which the client names.

What changes

  • emails.batch() on Emails and AsyncEmails, in the template form (template_id, shared template_data, per-recipient template_data) and the code form (template_key and the content send takes). A batch takes no cc, bcc, attachments or scheduled_at; the client refuses them, a recipient without to, an unknown recipient field and two recipients with one key before any request, naming the recipient's position.
  • One request per call: a batch takes at most 100 recipients and sends them in one request. More than 100 raises ValueError before anything is sent. The SDK checks only the count: PostHog refuses a body it finds too large with 413 content_too_large, which comes back as EmailBatchError with PostHog's own fix, "Split the recipients into smaller batches." (the SDK's fallback, when PostHog sends no usable fix text, says to split, or to send less data for a lone recipient). A 400 content_too_large means the shared content or data is too large; its message says what to send less of, and it gets no split advice.
  • One email per recipient, even on retries: each recipient carries an idempotency_key, given or made by the client, that every retry reuses. A key must never be reused for another email: a send with an earlier email's key replays that email instead of sending this one, and BatchRecipient's docstring says so. Each attempt waits 45 seconds, or the client's timeout when longer, since the server waits up to 30 seconds on its email pipeline.
  • A result per recipient: queued, failed or unconfirmed, in the order of recipients, with message_id, replayed and error.
    • A slot answered delivery_unavailable, idempotency_key_in_flight or api_error is unconfirmed, since PostHog may still queue it; any other slot error is failed.
    • Once an attempt got no answer (a network error, a 5xx, an in-flight 409 or an answer without a result per recipient), any later refusal leaves the recipient unconfirmed: that attempt may have queued it. The error is the last answer.
  • A request that fails as a whole raises EmailBatchError with every recipient's result: failed with the request's error, or unconfirmed once an attempt got no answer. A whole-call 409 idempotency_key_in_flight, on a 409 only, leaves every recipient unconfirmed, since another request may still send them; so does a 409 whose body is lost or has no readable code, which may be that answer. The client reads nothing back after the POST: an unconfirmed recipient keeps its idempotency_key, and its error's fix says to send it again with the same key within 24 hours of the first request that used it, which replays the email if it went out and sends it once if it didn't.
  • 409 batch_unavailable is not retried, is named validation_error, and its fix says to send each email with send(). A 404, with or without PostHog's error body, says the template doesn't exist or batch sends are off for the project, with the same send() fix.
  • A client shut down while a batch waits to retry sends no retry and raises EmailBatchError client_closed. The docs say to pass stored keys when a batch may be cut off and run again, so the rerun replays what went out.
  • Warnings come back once on SendBatchResult.warnings and are logged once.

No cross-SDK spec in PostHog/sdk-specs covers batch sends yet. The new public names (emails.batch, BatchRecipient, BatchEmailResult, SendBatchResult, EmailBatchError and the three statuses) are open to the Python API review, and posthog-node should match them.

Warning

🟡 Merge risk: medium, 🔴 at full rollout · two-way at merge, one-way door once released: the public names emails.batch, BatchRecipient, BatchEmailResult, SendBatchResult, EmailBatchError and the three statuses

  • Merge reaches no one: batch is new, no existing call changes, and the server flag is on for an internal project only. Once a maintainer approves the release, posthog and posthoganalytics on PyPI fix the names above, so the Python API review comes first.
  • send and get keep their request bytes, timeout and parse: _template is factored out with the same key order, which test_a_template_send_keeps_its_request_bytes pins, and only batch sets the new per-request timeout.
  • The template form on Cloud US delivered one real batch of two, each with its own values (see How did you test it). Cloud EU sends the same request but had no live run.
  • The code form (html with subject and a template_key) builds its own request body and runs on fakes only: no live run on either region.
  • The failure paths, a lost answer, a 5xx, an in-flight slot, a 413 and a shutdown before a retry, run on fakes only. A bug there is silent, a second email or none with no error. At merge every batch row reaches no one, since this merges into the stacked base and publishing needs an approved release, which is low; the batch adds well over 400 production lines while those rows stay uncovered, which raises it to medium. At full rollout the silent harm reaches some callers, which is high.
  • Switch-off: the server flag workflows-email-batch-sends, which answers 404 while off. None in the SDK: fix forward.
  • Tier: non-critical
Path Who takes it Base HEAD
send and get every SDK email call as on #1240 same request bytes, timeout and parse; the existing send tests cover them
batch callers who opt in, once the server flag is on for their project AttributeError up to 100 recipients in one request, a result per recipient; more than 100 raise ValueError before any request
batch on a project without the flag none can today AttributeError EmailBatchError not_found, no email sent
batch after a lost answer, a 5xx or an in-flight slot batch callers on a flaky network or during a pipeline outage AttributeError keeps the recipient unconfirmed with its key and says to resend with the same key; covered by fakes only, not on real Cloud. A caller who resends without the same key, or ignores unconfirmed, gets a second email or none
batch on Cloud US, template form callers who opt in AttributeError one real batch of two delivered at the one-request head, each with its own values, 101 recipients refused with no request, and a 6 MiB batch refused with 413 (see How did you test it)
batch on Cloud EU EU callers who opt in AttributeError same request as US; the live run covered US only
batch code form, either region callers who opt in with their own HTML AttributeError builds its own request body; unit tests on fakes only, no live run

Known issues

  • major: posthog/emails.py:2047 [base] A sync batch request admitted before shutdown() can still reach the transport after shutdown() returns: admission is a flag check and shutdown() doesn't wait for email work, as with send() on main (_start then the request). Reviewers rated it minor to blocker across reads. Closing it means shutdown() waits for email calls in flight, for every email call, in its own PR.

Rollout

  • Stages: merge; the server flag on for an internal project (done), then staged to more projects on the server side; then the SDK release, with a maintainer's approval, once customers can use the server route. posthog-node ships the same names.
  • Decided: the Python API review comes before the release, and the release waits until customers can use batch sends.
  • Watch: no alert pages on batch sends. Watch the share of failed in the server's email status rows, per project, through each flag stage; batch route 5xx, 409 batch_unavailable and 404s from projects that should have the flag; and emails with the same template and recipient a few seconds apart, which would mean a resend without the stored key.

💚 How did you test it?

Unit tests in posthog/test/test_emails_batch.py through a fake requests adapter and httpx.MockTransport: the request body of each form; refusals before any request, 101 recipients among them, sync and async; 100 recipients in one request, sync and async; a 413 content_too_large raised with PostHog's fix, and the SDK's fallback to split or send less when PostHog sends none; a body over 4 MiB going out whole in one request; a 400 content_too_large getting no split advice; a 429 after a lost answer leaving every recipient unconfirmed; the per-attempt timeout; a lost answer or a 503 followed by a refused slot staying unconfirmed; a whole-call 429, alone and after a 503; exhausted network errors leaving every recipient unconfirmed with its key and no read, sync and async; 409 batch_unavailable not retried; a 404 without a code; an answer without a result per recipient; an error code that isn't text; a whole-call in-flight 409, alone, before a 429 and after a 503; a 409 with a lost body, a body that isn't JSON or a code that isn't text, leaving recipients unconfirmed; and the in-flight code on another status; the last answer as the error after three attempts; a successful batch with an unconfirmed slot sending nothing more, sync and async; warnings once; an in-flight slot staying unconfirmed; a shutdown during a retry's wait, sync and async, and after a 503, leaving recipients unconfirmed; every unconfirmed error, whole-call or per recipient, carrying the same-key fix; a disabled client and a custom host; and the async client. Locally: ruff format --check, ruff check and the email tests pass; CI runs mypy with the baseline, the full pytest suite, make public_api_check and .github/scripts/check_strict_types.sh.

Live run on PostHog Cloud US, through this branch at the one-request head: 101 recipients raised ValueError with no request sent; a batch with 6 MiB of shared data got PostHog's 413 content_too_large with its own split fix, and nothing went out; then one real batch of two recipients in the template form, with per-recipient values and keys, went out as one request. PostHog answered both queued, both status rows read delivered within two seconds, and both emails arrived, each with its own values.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Claude Code (Opus 5.5) wrote this test-first against the server PRs' request and answer shapes. Reviews run through a review panel; while Codex was down, its lenses ran on Claude.

Question Answer Who Where
Uncertainty once an attempt got no answer, a later refusal leaves the recipient unconfirmed, with the last answer as its error; a later queued settles it. Rejected: trusting the later refusal 👍 spec v8
No reads by key the batch reads nothing back after its POSTs; an unconfirmed recipient keeps its key, and the caller resends with it, which replays the email if it went out. Rejected: reading each unconfirmed recipient by its key, which only filled in a message id and kept growing edge cases in review. Diverges from spec v8's lost-id reads; Node and Ruby drop them too 👍 cross-SDK batch contract
Whole-call in-flight 409 idempotency_key_in_flight, on a 409 only, leaves every recipient unconfirmed. Rejected: failed, since another request may still send them 👍 cross-SDK batch contract
One request per call at most 100 recipients, one request; more than 100 is a local error, and server refusals such as 413 content_too_large come back as the error. Rejected: splitting into requests of 100 recipients and 4 MiB, with not_attempted and results merged across requests 👍 cross-SDK batch contract
batch_unavailable name validation_error, as for template_outdated: the server types it invalid_request. Rejected: the spec's other-409 name concurrent_idempotent_requests, which the server never uses for it 🤖 this PR
Answer without a result per recipient api_error, the request's recipients unconfirmed, not retried. Rejected: retrying it 🤖 this PR

🤖 Generated with Claude Code

How did you test this code?

Proof What ran Result Commit
live-run One real emails.batch of two at 7e16914 on PostHog Cloud US, after a 101-recipient call and a 6 MiB batch 101 raised ValueError with no request; the 6 MiB batch got 413 content_too_large with PostHog's split fix; the one request queued both, both delivered and arrived with their own values f34867e (reused from 7e16914)
Review 3-lens panel (claude-opus-5-5, gpt-6.2-sol), round 1, final read 1, final read 2, final read 3, final read 4, final read 5, final read 6, final read 7, final read 8, final read 9, final read 10, final read 11, final read 12, final read 13, final read 14, final read 15 97 findings: 63 fixed, 34 rejected, 0 other aa54c41 to 74e8874
Proof judge an independent model reads the evidence against the diff not yet run at f34867e

End table: no gate at HEAD yet. Run hedge proof gate, then hedge proof receipt.

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

emails.batch() sends a template or rendered content to many recipients,
one email each. The client splits the recipients into requests of at most
100 recipients and 4 MiB of JSON, sends them one after another, and waits
45 seconds for each answer. Each recipient carries an idempotency key that
every retry reuses.

Each recipient gets a result: queued, failed, unconfirmed or
not_attempted. A recipient whose answer was lost stays unconfirmed until a
later answer queues it; a later refusal is kept as later_error. When a
request fails as a whole, the batch stops, reads each unconfirmed email by
its key, and raises EmailBatchError with every result. A 409
batch_unavailable is not retried.

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

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

Benchmarks completed. No changes flagged for review.

Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.

View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation 133.67 KiB/op 133.67 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.53 count/op 1,345.53 count/op <0.1% fewer Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 143.45 µs/op 134.86 µs/op 6% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.78 MiB 37.73 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.23 MiB 40.19 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.23 MiB 40.19 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 145.38 µs/op 134.3 µs/op 7.6% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.51 MiB 40.5 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 185.76 KiB/op 185.76 KiB/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,337.57 count/op 1,337.57 count/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 173.04 µs/op 167.63 µs/op 3.1% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.3 MiB 41.47 MiB 0.4% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.1 MiB 47.27 MiB 0.4% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.1 MiB 47.27 MiB 0.4% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 166.48 µs/op 158.35 µs/op 4.9% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.51 MiB 51.67 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.74 KiB/op 138.74 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.42 count/op 1,390.45 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 153.85 µs/op 160.34 µs/op 4.2% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.68 MiB 37.7 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.85 MiB 37.87 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.85 MiB 37.87 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 152.44 µs/op 160.43 µs/op 5.2% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.5 MiB 40.5 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 190.92 KiB/op 190.92 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.37 count/op 1,382.36 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 173.65 µs/op 177.07 µs/op 2% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.13 MiB 41.33 MiB 0.5% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.6 MiB 41.82 MiB 0.5% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.19 MiB 41.4 MiB 0.5% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 165 µs/op 168.92 µs/op 2.4% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.51 MiB 41.73 MiB 0.5% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 105.58 µs/op 111.64 µs/op 5.7% more time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 106.89 µs/op 115.33 µs/op 7.9% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 107.28 µs/op 105.54 µs/op 1.6% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 113.49 µs/op 110.74 µs/op 2.4% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 225.43 KiB/op 225.43 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,279.42 count/op 2,279.42 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 82.46 µs/op 83.5 µs/op 1.3% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 82.46 µs/op 83.51 µs/op 1.3% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.17 MiB/op 2.17 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 22,413.69 count/op 22,413.69 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 775.44 µs/op 779.19 µs/op 0.5% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 775.48 µs/op 779.24 µs/op 0.5% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 21.63 MiB/op 21.63 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 223,655.44 count/op 223,655.44 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 7.75 ms/op 7.75 ms/op <0.1% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 7.75 ms/op 7.75 ms/op <0.1% less time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.91 MiB 43.86 MiB 0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.2 MiB 44.17 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.2 MiB 44.17 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 43.94 MiB 43.92 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43 MiB 42.95 MiB 0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43 MiB 42.96 MiB 0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43 MiB 42.96 MiB 0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 42.83 MiB 43.27 MiB 1% more memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.74 KiB/op 15.74 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 162.77 count/op 162.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 9.69 µs/op 9.86 µs/op 1.8% more time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 9.69 µs/op 9.86 µs/op 1.8% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 24.6 KiB/op 24.6 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 239.28 count/op 239.28 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 13.69 µs/op 13.87 µs/op 1.3% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 13.7 µs/op 13.87 µs/op 1.3% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 39.81 KiB/op 39.81 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 388.27 count/op 388.27 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 19.24 µs/op 19.39 µs/op 0.8% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 19.24 µs/op 19.39 µs/op 0.8% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 60.59 KiB/op 60.59 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 584.27 count/op 584.27 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 28.07 µs/op 27.97 µs/op 0.4% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 28.07 µs/op 27.97 µs/op 0.4% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 59.22 KiB/op 59.22 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 567.77 count/op 567.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 26.28 µs/op 26.37 µs/op 0.4% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 26.27 µs/op 26.37 µs/op 0.4% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.04 KiB/op 19.04 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 192.27 count/op 192.27 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 10.98 µs/op 11.03 µs/op 0.5% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 10.98 µs/op 11.03 µs/op 0.5% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 20.66 KiB/op 20.66 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 197.77 count/op 197.77 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 11.54 µs/op 11.54 µs/op <0.1% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 11.54 µs/op 11.54 µs/op <0.1% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.89 KiB/op 14.89 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 152.77 count/op 152.77 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 9.02 µs/op 9.03 µs/op <0.1% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 9.02 µs/op 9.03 µs/op <0.1% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.9 KiB/op 15.9 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 166.77 count/op 166.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 10.07 µs/op 10.06 µs/op <0.1% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 10.07 µs/op 10.07 µs/op <0.1% less time Not flagged

Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals.

Each shard uses its own runner; compare Before PR against With PR within a row, not across shards.

Compared e94fc426f228afeec2a015c7e8227f7268e15929 → f34867e2a68cb360ce2d5c926ce007e9f75000de.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

Silthus and others added 15 commits November 22, 2026 08:40
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…feat/email-batch

# Conflicts:
#	references/public_api_snapshot.txt
Factoring the template fields out for batches put to before template_id
in a single template send's body. _template now returns its two values,
so each body keeps its own key order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EmailBatchError now carries the warnings of the requests that went out,
and logs them once. A field PostHog names inside a request maps back to
the recipient's position in recipients. Every 404 from the batch route
explains itself in why and fix, as the server's own 404 body has a code
and detail. A code batch without content names batch(). Tests of the
batch path guard one behaviour each.

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

A slot answered idempotency_key_in_flight may still be queued by the other
request, so it reads unconfirmed, as delivery_unavailable does. A batch
checks the client is still open before each later request and stops with
client_closed, the rest not_attempted, instead of sending on a new session.
The docs say to store keys for a batch that may be rerun.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The timeout tests answered after a set time and check that the batch
still reads queued, instead of reading the transport's timeout argument.
The shutdown and app-host tests replace the network layer instead of
reaching into the client's session. The unconfirmed error docs name all
three codes.

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

- Check that the client is still running before each retry of a batch
  request, so a retry after a 429 doesn't go out after shutdown.
- Read a refused recipient's position only from ASCII digits, so an
  attr such as "recipients__²__to" keeps the batch results.
- Say to send only the emails the batch didn't queue, with each
  recipient's idempotency_key, and that a rerun replays within 24 hours.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Check that the client still runs before each read by key after a lost
  answer, so a shutdown stops those reads too. The recipients stay
  unconfirmed.
- Map a refused recipient's position only when it fits the chunk, so a
  huge decimal index can't make int() raise before the batch error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silthus and others added 4 commits November 24, 2026 08:14
…rmed

- a status read by key that reads failed keeps the recipient unconfirmed,
  since PostHog records a refused recipient as a failed email too
- a whole-call 409 idempotency_key_in_flight leaves the chunk unconfirmed
  and reads it by key, as a lost answer does
- 409 batch_unavailable is named validation_error, not
  concurrent_idempotent_requests

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

Match the cross-SDK batch contract: a status read by key fills in only
the message ID and leaves the recipient unconfirmed, and the client reads
every unconfirmed recipient without an ID when the batch ends, on success
as on error.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… an in-flight later_error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silthus and others added 13 commits November 24, 2026 12:12
…ause, and match in-flight only on 409

An unconfirmed recipient stays unconfirmed with its idempotency_key, and
the caller resends with that key, which replays the email if it went out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and document a reused key's refusal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and note racing key reuse

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d a 413 says to split

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
emails.batch now refuses more than 100 recipients before sending and sends
the rest in one request. A server refusal, such as a 413 too_large, comes
back as the error; the 413 fix says to split the recipients. The chunk
loop, not_attempted, later_error, the 4 MiB sizing and the warnings on
EmailBatchError are gone.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… send less, and date the resend window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… lost answer as unconfirmed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at a 400 gets no split advice

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…empty, and pin a shutdown after a 503 as unconfirmed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…through a later refusal, and use a real nested field

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silthus
Silthus marked this pull request as ready for review November 25, 2026 11:27
@Silthus
Silthus requested a review from a team as a code owner November 25, 2026 11:27
@veria-ai

veria-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@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 de81833: no findings. This pull request is large, so the review ran in 4 parts with less depth than usual.

Silthus and others added 2 commits November 25, 2026 12:35
… has no readable code

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

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code looks good; no qualifying findings. Verdict: correct.

This branch has not been deployed

No deployments
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