Skip to content

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

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

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

Conversation

@Silthus

@Silthus Silthus commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

A Ruby app that sends the same transactional email to many people, such as a launch note or an invoice run, has to call emails.send once per recipient. That means one request each, with its own retry and replay handling in the app.

This PR adds emails.batch, stacked on #370. It ports emails.batch from Python (PostHog/posthog-python#1291), the reference, and Node (PostHog/posthog-js#5847).

result = posthog.emails.batch(
  template_id: '<template UUID>',
  recipients: [
    { to: 'ada@example.com', idempotency_key: 'launch:ada', template_data: { name: 'Ada' } },
    { to: 'alan@example.com', idempotency_key: 'launch:alan', template_data: { name: 'Alan' } }
  ]
)
result.results.reject { |email| email.status == 'queued' } # send these again with the same keys

Impact

Ruby apps send one email to many recipients in one call, with a result per recipient. The server's batch send event shows whether Ruby senders use it once batch sends are on.

Caution

🔴 Merge risk: high · one-way door once the gem is published: emails.batch, Emails::BatchResult, Emails::BatchEmailResult and EmailBatchError become public API

  • Calls to emails.batch: new entry point. They send real emails to every recipient in one request, so a bug in keys or result mapping is silent harm: an email sent twice, or one reported as sent that wasn't. The specs cover it against WebMock. Live on PostHog Cloud US at HEAD: a batch of two with a same-key rerun, the 413 and 400 size refusals, and one key used by feat(emails): schedule a send with scheduled_at #370's emails.send and this PR's emails.batch, each from its own checkout, in both orders, each returning the first call's message ID with replayed: true.
  • Uncovered live: the code form (template_key with rendered content), a batch where PostHog queues some recipients and refuses others, retries and unconfirmed recipients (a 409 in flight or without a readable body, a 5xx, a lost answer), and a retry refused after an attempt that may have queued the batch. They run only against WebMock and the mutants; the recipients stay unconfirmed with the same-key advice, and the message says when an earlier attempt may have queued them. A missed bug there reports an email that went out as failed, and a rerun with a new key sends it twice.
  • Oversized batches: the client builds the whole request body before it sends, and PostHog may answer 413 before it checks whether batch sends are on. The size is the caller's own content times at most 100 recipients; the switch-off can't stop that memory use or that 413. The client holds one serialized copy of the batch through its retries, and two while it builds the body. A worker with little memory can still be killed by a batch of very large content before PostHog answers.
  • Shared transport: the request helper gained a read-timeout argument whose default is the client's timeout, so emails.send, its attachment uploads and emails.get keep their waits. The shadow diff covers send and get; attachment uploads run only in the unchanged email specs.
  • Error names: a 409 batch_unavailable is named validation_error for every method, as in Python. The published spec's error table predates batch and names other 409s concurrent_idempotent_requests; emails.send and emails.get never receive batch_unavailable.
  • Warnings: a failed batch never calls the logger, and EmailBatchError#warnings holds the reply's warnings. A logger that raises a StandardError after a batch that went through doesn't lose the results; an Interrupt or a caller's Timeout::Error still propagates. Uncovered: a caller's own deadline of another StandardError class, raised into the thread while the logger writes, is dropped, and the call returns its results.
  • emails.send and emails.get: unchanged. A stubbed shadow diff of 14 inputs against feat(emails): schedule a send with scheduled_at #370's head matches every request, result, error and log line, and the existing email specs pass unchanged.
  • Switch-off: the server's batch sends. With them off, PostHog answers 409 batch_unavailable or 404, and the SDK raises EmailBatchError with every recipient failed, never sending one by one on its own. When an earlier attempt of the same call may have queued the batch, such as a 503 just before the switch went off, its recipients stay unconfirmed with the same-key advice instead.
  • Tier: critical (c: one-way door on public SDK API; g: real sends to recipients)

Rollout

  • Stages: feat(emails): schedule a send with scheduled_at #370 first, then the server's batch sends go on for customers, then this gem releases.
  • Decided: one request per call, at most 100 recipients, with the server's refusals as the error (Michael, d-c05485db). A refused retry after an attempt that may have queued the batch leaves it unconfirmed, as in the Elixir SDK (d-99642ec9). A failed batch never calls the logger and carries its warnings on the error (Michael, d-eb82aafc).
  • Watch: the live batch below, then the batch rows in the email status read.

What changes

  • emails.batch(recipients:, ...) takes the template form (template_id, shared template_data) or the code form (template_key, subject, html or text, and the optional sender and tracking fields), the same for every recipient.
  • Each recipient is a Hash, with Symbol or String keys: to, and optionally distinct_id, idempotency_key and, in the template form only, template_data, sent as the recipient's message_data.
  • One call sends exactly one request, of at most 100 recipients. More than 100 raise ArgumentError before any request, with the advice to split them. The client waits at least 45 seconds for the answer; connecting and writing keep the client's timeout.
  • Each recipient without an idempotency_key gets a UUID that every retry reuses. Two recipients with the same key raise ArgumentError before any request.
  • Retries follow emails.send: network errors, 429 and 503 retry with backoff, and the client stops retrying once it is shut down. The error is the last attempt's. Once an attempt may have queued the batch, a refused retry can't confirm it, so its recipients stay unconfirmed. Then EmailBatchError and each recipient's error start their message by saying an earlier attempt may have queued the email, and carry the same-key fix. Only the client's own shutdown before a retry reads as no attempt; a 503 from PostHog that names client_closed still may have queued it.
  • BatchResult#results has one BatchEmailResult per recipient, in order. Its status is one of:
    • queued
    • failed: PostHog refused it, such as a suppressed address, or refused the whole request
    • unconfirmed: an answer was lost or PostHog didn't confirm it, also when a later retry refused it. Its error's fix says to send it again with the same key within 24 hours of the first request that used it, so it goes out once.
  • The client never reads an email back after the batch. An unconfirmed email keeps its key, and a message ID only when PostHog named one.
  • A request that fails as a whole raises EmailBatchError, whose results hold every recipient. The HTTP status decides, not the code: a 4xx refused them, so they are failed with it as their error, unless an earlier attempt may have queued them. A 409 other than batch_unavailable (idempotency_key_in_flight, or one without a readable body), a 5xx, a lost answer and a 2xx without a result for each recipient may have, so they leave them unconfirmed with the same-key fix, whatever fix PostHog sent.
  • PostHog's refusals come back as the error, with PostHog's own fix: 413 content_too_large for a batch too large to take at once, whose fix says to split the recipients into smaller batches (the SDK adds that advice when the reply has none; a batch of one recipient, which can't be split, always gets the advice to make the email smaller); 400 content_too_large for shared content over PostHog's limit, which splitting doesn't change (a recipient whose own template_data is over it comes back failed with content_too_large in its result, while the others go out); batch_unavailable (409, never retried, named validation_error) and 404 with the fix to send each email with emails.send and its key, and the rest as PostHog names them. A field such as recipients__7__to names the recipient's place in the batch. The SDK checks only the recipient count, not the size of a request.
  • A refused recipient keeps its message ID on the result only, so EmailError#message_id still means PostHog may have accepted the email.
  • Warnings are logged once for a batch that goes through, and a logger that raises a StandardError other than Timeout::Error doesn't lose its results. A failed batch never calls the logger: EmailBatchError#warnings, the same field as EmailError#warnings, holds the reply's warnings.
  • A batch takes no cc, bcc, attachments or scheduled_at.

Known issues

  • A batch too large for PostHog, such as large shared content copied for each recipient, fails as a whole with a 413 content_too_large, and nothing goes out. The caller splits it into smaller batches. Shared content over PostHog's limit fails with a 400 content_too_large, and the caller makes it smaller.
  • Without stored keys, a rerun of a batch that failed gets new keys, and can send an email twice. The docs say to pass keys you store.
  • lib/posthog/emails.rb:409: a caller's deadline of a custom StandardError class, raised into the thread while the logger writes an accepted batch's warnings, is dropped, and emails.batch returns the results. Interrupt, Timeout.timeout and Timeout::Error still end the call.

💚 How did you test it?

Test-first, in spec/posthog/emails_batch_spec.rb against WebMock, on Ruby 3.2.2:

  • one request with a result per recipient in order, the body with message_data per recipient, and the secret key as a Bearer token
  • derived UUID keys, kept on a retry after a 503
  • the code form body
  • 100 recipients in one request, and 101 refused with no request
  • per-recipient refusals as failed; unconfirmed answers, unreadable slots and a queued slot without a message ID as unconfirmed with their keys and no status read
  • the reply's warnings logged once; a failed batch never calls the logger and its error carries the warnings; a batch that went through returns its results when the logger raises an IOError, and an Interrupt or Timeout::Error from the logger propagates
  • a whole-request 400 with every recipient failed and the field PostHog named
  • a 413 with PostHog's code and fix, without a JSON body, with an empty code and fix, and with fields that aren't text, each as content_too_large with PostHog's fix or the advice to split, in one request; a one-recipient batch told to make the email smaller after a bare 413 and after PostHog's split fix; a 400 content_too_large kept as PostHog sent it, without split advice
  • batch_unavailable and 404 with their fixes
  • a 409 idempotency_key_in_flight with an empty fix and with PostHog's own fix, and a 409 without a readable body, each leaving every recipient unconfirmed with the same-key fix
  • a connection reset past the retries, an answer without a result for each recipient, a 502 without a code, a 504 with one and a 503 naming client_closed, each leaving every recipient unconfirmed with the error's own message; a 403 without a code, and one naming keys in flight, leaving them failed
  • the last attempt's error after 503 and 503, 503 and 400, and 503 and 429, with the recipients unconfirmed, and after 429 and 400 failed
  • a lost answer followed by a 429, by a bare 413, and by a 2xx refusing one recipient, keeping those recipients unconfirmed with the same-key fix, and the batch error and each recipient's error saying an earlier attempt may have queued them
  • an unconfirmed recipient whose error has no detail from PostHog, saying it may still go out
  • a shutdown through client.shutdown before a retry, leaving the recipients unconfirmed with client_closed after a 503, and failed after a 429
  • the read timeout of at least 45 seconds and the client's connect and write timeouts handed to Net::HTTP; no spec waits them out
  • every bad argument raising ArgumentError before any request

47 mutants of the batch code, one per behavior above, each fail a spec at the head; the log is saved with the proof. bundle exec rubocop and bundle exec rake public_api:check pass.

Memory, measured with 100 recipients of 100 KB template_data: building the request allocates 2x the body, down from 3x, and keeps 1x through the retries, down from 2x. The script and both runs are saved with the proof; the body specs check the bytes.

Live, against PostHog Cloud US at this head, through an internal test template:

  • a batch of two, then the same batch with the same keys: both queued in order with their keys, and the replay returned the same message IDs with replayed: true. PostHog's status reads say both delivered.
  • a one-recipient body over PostHog's request cap: 413 content_too_large with the advice to make the email smaller in place of PostHog's split fix, the recipient failed. Shared content over its limit: 400 content_too_large without a fix, the recipient failed.
  • one key sent with emails.send and then emails.batch, and another the other way round, in one checkout: each second call returned the first call's message ID, and each ID reads delivered. PostHog marked both second calls replayed: false there, since the marker can lag a replay that follows at once; the docs now say so.
  • cross-version, each call in its own container: emails.send from feat(emails): schedule a send with scheduled_at #370's checkout (no batch method) and emails.batch from this head, one key per order. Both orders returned the first call's message ID with replayed: true, and both IDs read delivered.

The mailbox was not checked at this head; at the two heads before, the same runs left one email per recipient and per key.

Shadow diff of the shared send path, #370's head against this head: the same 14 inputs through emails.send and emails.get against the same stubbed replies, from a plain send to a connection reset and an unconfirmed scheduled send with warnings. Every wire request, result, error and log line matches.

📝 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 pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Claude Code (Claude Opus 5.5, claude-opus-5-5) wrote the code as one lane of the cross-SDK transactional email work, porting the Python batch and matching its error codes, retries, replay window and result shape.

Question Answer Who Where
Requests per batch call One request of at most 100 recipients; more is a local error, and PostHog's refusals, such as 413 content_too_large, come back as the error. Replaced chunking into requests of 100 recipients and 4 MiB. 👤 d-c05485db, conductor thread
A retry refused after an attempt that may have queued the batch Its recipients stay unconfirmed with the same-key advice, as in the Elixir SDK. Replaced: the last attempt deciding the status. 👤 d-99642ec9, conductor thread
Logger on a failed batch Never called: EmailBatchError#warnings carries the warnings. Replaced the cause-chain handling of a raising logger. 👤 conductor thread
Reading unconfirmed emails back by key Dropped in every SDK: an unconfirmed email stays so with its key, to send again with it. Replaced reading each one by key at the end of the batch. 👍 conductor thread
Batch for every SDK Build it now, stacked on the scheduled-send PR. 👍 conductor thread
Per-recipient values Each recipient's template_data, sent as message_data. The server's batch recipient takes only to, distinct_id, idempotency_key and message_data, as Python and Node send it. Rejected: a separate event body field the server refuses. 🤖 this PR
Batch contract where Python and Node differ Node and the server set it: a 409 idempotency_key_in_flight is unconfirmed, and batch_unavailable keeps its code with no retry. Rejected: Python's behavior on these. 🤖 conductor thread
A logger that raises after a batch that went through The batch returns its results, so a caller has no reason to resend with new keys; a StandardError from the logger is dropped, and an Interrupt or a caller's Timeout::Error propagates. Replaced: its error propagating, which lost the results. 🤖 PostHog Review thread
A 409 without a readable body Its recipients stay unconfirmed with their keys, since PostHog's only other 409 is batch_unavailable. Rejected: failed. 🤖 conductor thread
Fix for a one-recipient batch refused by a 413 Make the email smaller, in place of PostHog's split fix. Rejected: passing PostHog's split fix through, which can't help one recipient. 🤖 this PR

Involvement: no grilling rounds, no prototypes; one Hedge review panel, four Codex fixes reviews and seventeen Codex final reads, fourteen of them past the review budget on the agent's call; a cross-SDK check against Node and the server; live proof and a stubbed shadow diff captured.

🤖 Generated with Claude Code

How did you test this code?

Merge card: high, one-way door · 5 rounds, 17 final reads · gaps: judge (🤖 agent d-fe6d4dd1) · 3 known issues · 1756 min opened to ready

Proof What ran Result Commit
live-run A live batch of two through the test template, a same-key rerun, status reads, and two refused batches, at this head on PostHog Cloud US Both queued in order with their keys; the rerun returned the same message IDs; both read delivered; the 413 and 400 came back as content_too_large with every recipient failed 6823db2
cross-version emails.send from the #370 checkout at bdda344 and emails.batch from this head, one key per pair, both orders, live on PostHog Cloud US Each pair returned one message ID in both orders, and both read delivered 6823db2
shadow-diff The 14 shared send and status inputs through #370 head and #373 head against the same stubbed replies Every request, result, error and log line matches 6823db2 (reused from ee472cc)
Review 5-lens panel (claude-opus-5-5, gpt-6.2-sol), round 1, round 2, round 3, round 4, round 5, 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, final read 16, final read 17 131 findings: 73 fixed, 58 rejected, 0 other 3b58e48 to 6823db2
Proof judge an independent model reads the evidence against the diff ❌ failed at 6823db2
PR Review rounds Production lines Sanity pass Skipped proofs
#373 5 rounds, 17 final reads 865 → 984 (×1.1); docs 5 → 5 not run judge: The judge repeats findings answered in final reads 10 to 17. The 409 name: emails.send and emails.get never receive batch_unavailable, which PostHog sends only from the batch route, so the shadow diff has no real reply to run. The same-key skip needs a refusal carrying the SDK's own sentence word for word, which PostHog never sends. The custom-StandardError deadline during logging is now named in the callout and Known issues; returning the queued results is the call that keeps keys and stops double sends. The timeout spec checks the values the SDK hands Net::HTTP, since no fake clock drives its socket timeouts, and two mutants need it. (🤖 agent d-fe6d4dd1)

Not checked: The code form (template_key with rendered content) live; A batch where PostHog queues some recipients and refuses others, live; Retries, lost answers and unconfirmed recipients live; they run against WebMock and the mutants; The mailbox at this head; PostHog status reads show every message ID delivered
Full receipt: https://artifacts.posthog.com/a/HBhbFkuVnfi9B8SEWM1K2J

emails.batch sends a template made in PostHog, with template_data per
recipient, or content your code rendered to up to 100 recipients and
4 MiB per request, one request after another, and returns a result per
recipient in order. Each recipient has its own idempotency key, given or
made by the client, that every retry reuses. After a lost answer, the
client reads each email that may have gone out by its key. A request
that fails as a whole stops the batch and raises EmailBatchError with
every recipient's result.

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

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

posthog-ruby-sync Compliance Report

Date: 2026-11-25T11:57:42.296792+00:00
Duration: 94174ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 8ms
Format Validation.Event Has Uuid ✅ 5ms
Format Validation.Event Has Lib Properties ✅ 5ms
Format Validation.Distinct Id Is String ✅ 7ms
Format Validation.Token Is Present ✅ 6ms
Format Validation.Custom Properties Preserved ✅ 6ms
Format Validation.Event Has Timestamp ✅ 5ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 6ms
Retry Behavior.Retries On 503 ✅ 5322ms
Retry Behavior.Does Not Retry On 400 ✅ 2009ms
Retry Behavior.Does Not Retry On 401 ✅ 2009ms
Retry Behavior.Respects Retry After Header ✅ 8015ms
Retry Behavior.Implements Backoff ✅ 15272ms
Retry Behavior.Retries On 500 ✅ 5115ms
Retry Behavior.Retries On 502 ✅ 5114ms
Retry Behavior.Retries On 504 ✅ 5116ms
Retry Behavior.Max Retries Respected ✅ 15504ms
Deduplication.Generates Unique Uuids ✅ 17ms
Deduplication.Preserves Uuid On Retry ✅ 5156ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10359ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5168ms
Deduplication.No Duplicate Events In Batch ✅ 16ms
Deduplication.Different Events Have Different Uuids ✅ 8ms
Compression.Sends Gzip When Enabled ✅ 5ms
Batch Format.Uses Proper Batch Structure ✅ 5ms
Batch Format.Flush With No Events Sends Nothing ✅ 2ms
Batch Format.Synchronous Capture Delivers Each Event Immediately ✅ 13ms
Error Handling.Does Not Retry On 403 ✅ 2006ms
Error Handling.Does Not Retry On 413 ✅ 2008ms
Error Handling.Retries On 408 ✅ 5118ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 10ms
Request Payload.Flags Request Uses V2 Query Param ✅ 8ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 5ms
Request Payload.Flags Request Omits Authorization Header ✅ 5ms
Request Payload.Token In Flags Body Matches Init ✅ 5ms
Request Payload.Groups Round Trip ✅ 5ms
Request Payload.Groups Default To Empty Object ✅ 5ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 5ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 5ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 5ms
Request Lifecycle.No Flags Request On Init Alone ✅ 2ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 4ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 8ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 5ms
Retry Behavior.Retries Flags On 502 ✅ 139ms
Retry Behavior.Retries Flags On 504 ✅ 109ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 7ms

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

posthog-ruby-async Compliance Report

Date: 2026-11-25T11:57:39.481261+00:00
Duration: 98420ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 7ms
Format Validation.Event Has Uuid ✅ 104ms
Format Validation.Event Has Lib Properties ✅ 106ms
Format Validation.Distinct Id Is String ✅ 105ms
Format Validation.Token Is Present ✅ 105ms
Format Validation.Custom Properties Preserved ✅ 105ms
Format Validation.Event Has Timestamp ✅ 105ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 5ms
Retry Behavior.Retries On 503 ✅ 5409ms
Retry Behavior.Does Not Retry On 400 ✅ 2108ms
Retry Behavior.Does Not Retry On 401 ✅ 2107ms
Retry Behavior.Respects Retry After Header ✅ 8113ms
Retry Behavior.Implements Backoff ✅ 15621ms
Retry Behavior.Retries On 500 ✅ 5210ms
Retry Behavior.Retries On 502 ✅ 5211ms
Retry Behavior.Retries On 504 ✅ 5211ms
Retry Behavior.Max Retries Respected ✅ 15618ms
Deduplication.Generates Unique Uuids ✅ 107ms
Deduplication.Preserves Uuid On Retry ✅ 5210ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10415ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5214ms
Deduplication.No Duplicate Events In Batch ✅ 108ms
Deduplication.Different Events Have Different Uuids ✅ 106ms
Compression.Sends Gzip When Enabled ✅ 104ms
Batch Format.Uses Proper Batch Structure ✅ 104ms
Batch Format.Flush With No Events Sends Nothing ✅ 3ms
Batch Format.Multiple Events Batched Together ✅ 108ms
Error Handling.Does Not Retry On 403 ✅ 2106ms
Error Handling.Does Not Retry On 413 ✅ 2110ms
Error Handling.Retries On 408 ✅ 5209ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 106ms
Request Payload.Flags Request Uses V2 Query Param ✅ 105ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 105ms
Request Payload.Flags Request Omits Authorization Header ✅ 105ms
Request Payload.Token In Flags Body Matches Init ✅ 105ms
Request Payload.Groups Round Trip ✅ 105ms
Request Payload.Groups Default To Empty Object ✅ 105ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 104ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 105ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 106ms
Request Lifecycle.No Flags Request On Init Alone ✅ 2ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 103ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 107ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 105ms
Retry Behavior.Retries Flags On 502 ✅ 209ms
Retry Behavior.Retries Flags On 504 ✅ 211ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 106ms

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

SDK performance: posthog-ruby

2 changes worth reviewing: 1 observed improvement, 1 observed regression.

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.

Test Measurement Before PR With PR Change
Capture and deliver events (32-byte payload, steady) Process CPU time per operation 31.1 µs/op 27.78 µs/op 10.7% less time
Refresh 1,000 flag definitions Idle process memory (RSS) 37.66 MiB 40.91 MiB 8.6% more memory
View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 56.27 count/op 56.27 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 107.43 µs/op 107.6 µs/op 0.2% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 28.56 MiB 28.77 MiB 0.7% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 31.54 MiB 31.41 MiB 0.4% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling 5.3 MiB 5.31 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 30.77 MiB 30.64 MiB 0.4% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 16.65 µs/op 17.27 µs/op 3.8% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 31.32 MiB 31.25 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 58.65 count/op 58.65 count/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 107.62 µs/op 107.57 µs/op <0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 33.31 MiB 33.66 MiB 1.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 42.46 MiB 42.2 MiB 0.6% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling 9.17 MiB 9.18 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.72 MiB 40.03 MiB 1.7% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 24.83 µs/op 24.97 µs/op 0.6% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 42.27 MiB 41.97 MiB 0.7% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 58.68 count/op 58.68 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 1.01 ms/op 1.01 ms/op 0.2% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 28.56 MiB 28.7 MiB 0.5% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 30.55 MiB 30.73 MiB 0.6% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling 5.3 MiB 5.31 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 30.55 MiB 30.73 MiB 0.6% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 31.1 µs/op 27.78 µs/op 10.7% less time Worth reviewing: observed improvement
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 30.55 MiB 30.73 MiB 0.6% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 58.68 count/op 58.68 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 1.01 ms/op 1.01 ms/op <0.1% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 33.35 MiB 33.65 MiB 0.9% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.11 MiB 42.08 MiB 2.4% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling 9.17 MiB 9.18 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 39.81 MiB 39.76 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 32.35 µs/op 32.56 µs/op 0.7% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.34 MiB 41.94 MiB 1.4% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 7.33 µs/op 7.52 µs/op 2.5% more time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 7.33 µs/op 7.52 µs/op 2.6% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 7.33 µs/op 7.69 µs/op 4.9% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 7.34 µs/op 7.69 µs/op 4.8% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 343.02 count/op 343.02 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 92.02 µs/op 91.72 µs/op 0.3% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 92.02 µs/op 91.72 µs/op 0.3% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 3,324 count/op 3,323.97 count/op <0.1% fewer Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 884.39 µs/op 882.19 µs/op 0.2% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 884.37 µs/op 882.17 µs/op 0.2% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 33,113.53 count/op 33,113.88 count/op <0.1% more Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 9.28 ms/op 9.55 ms/op 2.9% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 9.28 ms/op 9.55 ms/op 2.9% more time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 39.06 MiB 39.28 MiB 0.6% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 40.4 MiB 40.76 MiB 0.9% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling 8 MiB 8.01 MiB 0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 39.51 MiB 39.22 MiB 0.7% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 40.03 MiB 40.43 MiB 1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 37.66 MiB 40.91 MiB 8.6% more memory Worth reviewing: observed regression
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 45.33 MiB 41.85 MiB 7.7% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling 9.51 MiB 9.52 MiB 0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 44.01 MiB 40.82 MiB 7.3% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 45.25 MiB 41.7 MiB 7.9% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 38 count/op 38 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 7.91 µs/op 7.95 µs/op 0.5% more time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 7.91 µs/op 7.95 µs/op 0.5% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 38 count/op 38 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 10.4 µs/op 10.46 µs/op 0.6% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 10.4 µs/op 10.46 µs/op 0.6% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 55 count/op 55 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 13.53 µs/op 13.42 µs/op 0.8% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 13.53 µs/op 13.42 µs/op 0.8% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 76 count/op 76 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 18.8 µs/op 18.8 µs/op <0.1% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 18.8 µs/op 18.8 µs/op <0.1% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 67 count/op 67 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 16.94 µs/op 16.9 µs/op 0.3% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 16.94 µs/op 16.89 µs/op 0.3% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 34 count/op 34 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 7.94 µs/op 8.02 µs/op 1% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 7.94 µs/op 8.02 µs/op 1% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 99 count/op 99 count/op <0.1% fewer Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 22.76 µs/op 22.81 µs/op 0.2% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 22.76 µs/op 22.81 µs/op 0.2% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 31 count/op 31 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 7.05 µs/op 6.95 µs/op 1.4% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.05 µs/op 6.95 µs/op 1.4% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 37 count/op 37 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 8.81 µs/op 8.83 µs/op 0.2% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 8.81 µs/op 8.83 µs/op 0.2% more 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 bdda3440a5c4e47267014cfe556e9f5a7455e635 → 6823db283274e1076754aee45d41cbe1f4e9f6a6.

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 26 commits November 24, 2026 07:31
…limits

- a status read by key that reads failed keeps the recipient unconfirmed
- a refused recipient's error carries no message ID
- only the wait for a batch answer gets the 45 s floor
- shared content over 4 MiB raises ArgumentError before any request
- build each request body when it goes out
- Ruby's keyword check refuses unknown batch arguments
- the changeset says reruns replay only with stored keys

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

- a status read by key that reads failed keeps an earlier later_error, and its error has no message ID
- shared content too large for a request fails each recipient with content_too_large again, as in Python and Node
- specs pin the 4 MiB boundary to the byte and the three batch timeouts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- the fix names the recipient's template_data or the batch's content, since a single send has its own size limit
- a spec covers shared content too large for any request: every recipient fails with content_too_large, and no request goes out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A request refused with idempotency_key_in_flight leaves its recipients
unconfirmed, also after a later refusal. batch_unavailable keeps its code
and is named a validation_error, not concurrent_idempotent_requests. The
client reads by key every unconfirmed email without a message ID at the end
of each batch, on success too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A status read by key marked the email queued on any status but failed, so an
unreadable slot could turn queued on an archived read. It now adds the ID and
keeps the email unconfirmed. The last retry's error stays each recipient's
later_error again, and the 4 MiB split spec keeps each email under 1.5 MiB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ler's deadline

A 409 idempotency_key_in_flight is now the unconfirmed recipient's error, so
a failed status read by key can give its reason as later_error. A caller's
Timeout::Error deadline during a status read by key now propagates instead
of ending the reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An unconfirmed recipient keeps its idempotency key and no message ID, and
its error's fix says to send it again with the same key.

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

A retry that refuses an unconfirmed recipient no longer replaces the error
that left it unconfirmed, an answer without a result per recipient is its
only error, an in-flight refusal with an empty fix still says to resend
with the same key, and a logger's reused exception names the failed batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Takes #370's logger rule into the shared helper: a logger's error
propagates when it has no cause or the call's error is among its causes,
and an exception object it raised before becomes the cause of the
call's error. Also records a retry's 5xx refusal as the later_error of
a recipient an earlier attempt left unconfirmed.

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

Merges the scheduled-send branch, so a failed send or batch no longer
calls the logger and carries its warnings on EmailError#warnings.
EmailBatchError takes the field from EmailError.

A refusal under 500 now becomes the later_error of a recipient an
earlier attempt may have queued as it arrives, so a final network
error no longer drops it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
emails.batch now sends exactly one request. More than 100 recipients is a
local ArgumentError before anything is sent. Server refusals, such as a 413
too_large, come back as the error for every recipient. The chunk loop,
not_attempted, later_error and the cross-request sizing are gone.

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

A 4xx refused the batch, so its recipients are failed, except a 409 for
keys still in flight. No answer, a 5xx and an unreadable 2xx leave them
unconfirmed whatever code the reply names. A 413 keeps PostHog's own
content_too_large code.

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

After a lost answer, a 5xx or a 409 for keys in flight, a refused retry
can't confirm the recipients: they stay unconfirmed with the same-key
advice, whether the retry refused the request or one recipient. The
in-flight exception needs a 409. A 413 keeps PostHog's own fix, falls
back to the advice to split, and maps an empty code to
content_too_large. A 400 content_too_large stays as PostHog sent it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
client_closed means the client sent no retry, so on its own it says
nothing about what PostHog queued: a 429 then a shutdown stays failed.
A 413 keeps its code and split advice when PostHog's fields aren't
text. The docs say a recipient's own oversized data comes back in its
result, not as the whole-request 400.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retry's refusal no longer reads as if no email was sent when an earlier
attempt may have queued the batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 503 from PostHog that names client_closed may still have queued the batch,
so its recipients stay unconfirmed. Only the error the client raises before a
retry, which sends no request, says nothing about what PostHog queued.

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

Also checks that a request error keeps its own message when that attempt alone
may have queued the batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silthus and others added 4 commits November 24, 2026 21:56
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When only an earlier attempt may have queued the batch, EmailBatchError itself
now says so and carries the same-key fix, not the refusal's 'no email was
sent'. A one-recipient batch refused by a 413 is told to make the email
smaller, even when PostHog's reply advises a split.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also gives the changeset the advice for a one-recipient batch refused as too
large.

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 453ae70: 3 Should fix.

New pushes to this pull request won't start an automatic review. Comment @posthog review to review new changes.

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 lib/posthog/emails.rb Resolved
Comment thread lib/posthog/email_batch.rb Resolved
Comment thread lib/posthog/emails.rb Resolved
Silthus and others added 5 commits November 25, 2026 12:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A logger that raised a StandardError while logging an accepted batch's warnings lost the results and the derived keys, so a resend sent each email twice. An interrupt still propagates.

A 409 without a readable body may be keys in flight, so its recipients stay unconfirmed with their keys. Only batch_unavailable says nothing went out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The body was built from every recipient's JSON joined into a second string and copied into a third, and the recipients' JSON stayed live. It now copies each recipient into a buffer of the exact size and drops its JSON, so a retry holds only the body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Timeout.timeout with Timeout::Error as its class raises it in the thread, so the logger rescue swallowed the caller's deadline. The overview also gives a batch of one recipient the advice to make the email smaller.

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