Skip to content

feat(rails): send Action Mailer mail through PostHog - #329

Closed
Silthus wants to merge 19 commits into
feat/emails-integration-optionfrom
feat/rails-action-mailer-delivery
Closed

Silthus wants to merge 19 commits into
feat/emails-integration-optionfrom
feat/rails-action-mailer-delivery

Conversation

@Silthus

@Silthus Silthus commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A Rails app that sends mail through Action Mailer can't pick PostHog as its provider. To send through PostHog today it has to replace each mailer call with PostHog.emails.send and lose deliver_later, previews and mailer tests.

Part of PostHog/michaelr-context#43. Stacks on #328, the integration: option this PR passes; merge that first.

Merge Danger

Warning

🟡 Merge risk: medium · two-way door at merge, one-way once posthog-rails releases this changeset: delivery_method :posthog, its X-PostHog-* header vocabulary, its refusal codes and its two error classes become a public contract, and each mail an app sends through it is sent

  • Apps that set delivery_method = :posthog change: each mail goes out as one PostHog email through the SDK, or raises UnsupportedMailError before any request when PostHog can't carry part of it. On feat(emails): name the integration that sends an email #328 the same setting raises, so no app sends this way at merge; after the release, only apps that opt in do.
  • Every other posthog-rails app that loads Action Mailer runs one new line per mail: the mailer's mail call records <mailer>-<action> on the message. Its mail is unchanged, covered by the booted-app spec "leaves an app on another delivery method sending as before", which passes on feat(emails): name the integration that sends an email #328's head and here and fails a mutant that trims recipients in that hook. Apps without Action Mailer load none of it ("boots without Action Mailer").
  • Uncovered: the opted-in send against the live send API. The specs run the real SDK against WebMock, and the handler proof runs real Rails 7.2 and 6.1 jobs; a field the server reads differently from those stubs would send a wrong email to the app's recipient, which no one sees. The launch train's real send covers it.
  • Switch-off: the app's own config.action_mailer.delivery_method: setting it back stops every send before the mapper runs. The mail hook has none; it is covered above.
  • Tier: critical (f: the changeset publishes posthog-rails; g: it sends the app's email to its recipients)

Rollout

Summary

# config/environments/production.rb
config.action_mailer.delivery_method = :posthog
config.action_mailer.posthog_settings = { default_template_key: 'transactional' } # optional

deliver_now and deliver_later then send each mail as one PostHog email through the client PostHog.init made (it needs secret_key).

  • Mapping. Exactly one To address. Recipient display names are dropped, the From display name is kept, with the quotes it needs ("Doe, Jane" <jane@example.com>). HTML and text bodies, cc, bcc, reply-to and attachments go through; attachments upload through the SDK, and an inline attachment sends its Content-ID as written.
  • Options. Reserved headers set the send's options, and are read, not sent:
    • X-PostHog-Distinct-Id, X-PostHog-Template-Key and X-PostHog-Idempotency-Key.
    • X-PostHog-Track-Opens, X-PostHog-Track-Clicks and X-PostHog-Capture-Engagement set tracking; X-PostHog-Sensitive sets sensitive. Each takes true or false. Click tracking with open tracking off is refused, since PostHog needs the pixel to track clicks.
    • Without X-PostHog-Sensitive, a mail takes the setting of the PostHog template with its key, and is sensitive when no template has it.
  • Template key. An explicit X-PostHog-Template-Key, else <mailer>-<action> such as user_mailer-welcome (made safe: Admin::UserMailer#welcome_email becomes admin-user_mailer-welcome_email, at most 256 characters), else default_template_key, else action-mailer.
  • Refusals, before any request. These raise PostHog::Rails::UnsupportedMailError with refusal set to the code. Nothing is dropped silently.
    • Two To addresses (multiple_to), or two From addresses.
    • An inline file without a content ID (inline_without_cid), or an attachment without a filename.
    • Any header outside the ones Mail writes itself, on the message or on any part (unsupported_header); a non-normal priority (unsupported_priority).
    • A Content-Type parameter PostHog would drop, or a text attachment in a charset other than UTF-8 or US-ASCII.
    • A part other than one HTML body, one text body and attachments, such as a calendar invite or a signed message, or bodies that aren't two sections of one multipart/alternative (unsupported_part). Only multipart/mixed, alternative and related containers are opened.
    • An envelope that differs from the headers (envelope_mismatch), a template header (template_unsupported), or an invalid explicit key (invalid_template_key).
    • A mail the SDK's own checks refuse, such as one without a subject (invalid_mail).
  • Errors. A send PostHog refuses raises PostHog::Rails::DeliveryError with status, code, detail, attr, retry_after and retryable?. The SDK's own retries run first, with one idempotency key.
  • Both errors honour raise_delivery_errors; with it off, the error goes to PostHog::Logging.logger, since Mail drops it.
  • After a send, mail.message_id is PostHog's message ID, ready for PostHog.emails.get.
  • Every send carries X-PostHog-Integration: action-mailer/<posthog-rails version>.

Changeset: posthog-rails minor. actionmailer joins the development dependencies only; the gem still depends on railties alone.

Evidence

  • Red on feat(emails): name the integration that sends an email #328's head: the new spec fails to load, because there is no posthog.action_mailer initializer. Each review fix started as a failing test.
  • Green on this head (ed1a910): the lane gate on Ruby 3.3, bundle exec rspec 2610 examples, 0 failures (49 pending, the OpenTelemetry-bundle specs); bundle exec rubocop no offenses; bundle exec rake public_api:check passes, with the delivery method in the snapshot.
  • Test seams: the HTTP requests the real SDK makes, stubbed with WebMock, or the error Mail raises with no request.
    • The adapter contract's conformance cases that apply to Action Mailer: 01 to 11, 13, 14 and 16, built as real Mail::Messages and delivered with mail.deliver. Case 12 (tags) is refused, as Action Mailer has no slot for it; 15 and 17 are for adapters that carry templates.
    • One test per row of the contract's error table, and a spec that fails when retryable? and the SDK's own retries disagree, across every status and code.
    • Booted Rails apps (Rails::Application#initialize! in a subprocess): deliver_now with key user_mailer-welcome and posthog_settings, deliver_later carrying the mail's idempotency key, an app on another delivery method, and an app without Action Mailer.
  • Handler proof (at 95a00a9; ed1a910 adds only a test): the docs' rescue_from handler, run on Rails 7.2 and Rails 6.1 jobs against a fake API. A 400 sends once, a 503 retries to five sends, a refused mail sends nothing; each is logged and reported, and no job is left.
  • MIME shapes: the trees Action Mailer 7.2 builds for text, HTML, attachments and inline parts, which the mapper's container rules follow.
  • Live run: owed. The launch train sends one real email from this head. A send from 9449b6e, before the review rounds, returned 202 with PostHog's message ID; this head changes the request since then, so it doesn't count.
  • Cross-version: owed. The same send runs this SDK against the production send API.

Seams: the X-PostHog-Integration value is read by the send API's instrumentation (PostHog/posthog#130017, still open, so production ignores it today). The reserved header names, the tracking mapping and the refusal codes are shared with the Nodemailer, Symfony and Laravel adapters.

Agent context

Decisions

Question Answer Who Where
How do open and click tracking map? tracking.opens and tracking.clicks, sensitive passed through, never capture_engagement beside them 👤 Human map
How do attachments send? Through the SDK's upload 👤 Human map
Is category in scope? No 👤 Human map
Who proves the live send? The launch train, one real send per SDK branch; no send from this thread 👤 Human ticket
Where do per-mail PostHog options go? Reserved X-PostHog-* headers, read and never sent 👍 Accepted default ticket
What names a mail? Explicit key, then <mailer>-<action>, then default_template_key, then action-mailer 👍 Accepted default ticket
What happens to mail PostHog can't carry? Refused with a named code before any request, never dropped 👍 Accepted default ticket
How does the delivery method learn the mailer action? The mailer's mail call records <mailer>-<action> on the message; Mail itself only knows the mailer class 🤖 Agent ticket
How does retryable? stay in step with the SDK? A spec compares it with the SDK's own retries, instead of a new public EmailError#retryable? in the SDK 🤖 Agent ticket
What happens to a mail the SDK's checks refuse? Raised as UnsupportedMailError invalid_mail, like every other refusal 🤖 Agent ticket
What happens with raise_delivery_errors off? Mail drops the error, so the delivery method logs it first 🤖 Agent ticket
Click tracking with open tracking off? Refused as unsupported_header before any request 🤖 Agent ticket
Does it owe a prod-shape proof? No: its inputs are each app's own mailers, which no PostHog store holds; the conformance cases and the MIME shapes cover them 🤖 Agent ticket
What happens to an attachment's charset? UTF-8 and US-ASCII go out as the MIME type; any other charset is refused 🤖 Agent ticket
What is the mail's message ID after a send? PostHog's message ID 🤖 Agent ticket

Involvement: no grilling or prototype rounds; three cross-model review rounds and four final reads (GPT-6.1 Sol), ReviewHog; proof captured, live run owed to the launch train.

Taken over in place from the earlier thread on the same ticket; its commits and authorship are kept.

🤖 Generated with Claude Code

`config.action_mailer.delivery_method = :posthog` sends each mail as
one PostHog email through the client PostHog.init made, for
deliver_now and deliver_later. The delivery method registers in
Action Mailer's load hook, so apps without Action Mailer load none of
it.

Each mail maps to one send or a named refusal before any request:
one To address, bare recipient addresses, the From display name,
HTML and text bodies, attachments with inline content IDs, and the
reserved X-PostHog-* headers for the send options, which never go
out. Mail is named <mailer>-<action> unless it sets a template key.
Refusals raise PostHog::Rails::UnsupportedMailError and failed sends
PostHog::Rails::DeliveryError with retryable?, both honouring
raise_delivery_errors. Every send carries
X-PostHog-Integration: action-mailer/<posthog-rails version>.

Ticket: PostHog/michaelr-context#43

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

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

posthog-ruby-sync Compliance Report

Date: 2026-11-13T07:34:07.451014+00:00
Duration: 56118ms

⚠️ Some Tests Failed

39/47 tests passed, 8 failed


Capture Tests

⚠️ 23/30 tests passed, 7 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 10ms
Format Validation.Event Has Uuid ✅ 7ms
Format Validation.Event Has Lib Properties ✅ 7ms
Format Validation.Distinct Id Is String ✅ 9ms
Format Validation.Token Is Present ✅ 7ms
Format Validation.Custom Properties Preserved ✅ 8ms
Format Validation.Event Has Timestamp ✅ 8ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 8ms
Retry Behavior.Retries On 503 ✅ 5326ms
Retry Behavior.Does Not Retry On 400 ❌ 7ms
Retry Behavior.Does Not Retry On 401 ❌ 5ms
Retry Behavior.Respects Retry After Header ✅ 8017ms
Retry Behavior.Implements Backoff ❌ 252ms
Retry Behavior.Retries On 500 ✅ 5144ms
Retry Behavior.Retries On 502 ✅ 5148ms
Retry Behavior.Retries On 504 ✅ 5168ms
Retry Behavior.Max Retries Respected ❌ 560ms
Deduplication.Generates Unique Uuids ✅ 18ms
Deduplication.Preserves Uuid On Retry ✅ 5113ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10332ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5122ms
Deduplication.No Duplicate Events In Batch ✅ 18ms
Deduplication.Different Events Have Different Uuids ✅ 10ms
Compression.Sends Gzip When Enabled ✅ 7ms
Batch Format.Uses Proper Batch Structure ✅ 6ms
Batch Format.Flush With No Events Sends Nothing ✅ 3ms
Batch Format.Multiple Events Batched Together ❌ 18ms
Error Handling.Does Not Retry On 403 ❌ 5ms
Error Handling.Does Not Retry On 413 ❌ 5ms
Error Handling.Retries On 408 ✅ 5115ms

Failures

retry_behavior.does_not_retry_on_400

500, message='Internal Server Error', url='http://sdk-adapter:8080/capture'

retry_behavior.does_not_retry_on_401

500, message='Internal Server Error', url='http://sdk-adapter:8080/capture'

retry_behavior.implements_backoff

500, message='Internal Server Error', url='http://sdk-adapter:8080/capture'

retry_behavior.max_retries_respected

500, message='Internal Server Error', url='http://sdk-adapter:8080/capture'

batch_format.multiple_events_batched_together

Expected 1 requests, got 5

error_handling.does_not_retry_on_403

500, message='Internal Server Error', url='http://sdk-adapter:8080/capture'

error_handling.does_not_retry_on_413

500, message='Internal Server Error', url='http://sdk-adapter:8080/capture'

Feature_Flags Tests

⚠️ 16/17 tests passed, 1 failed

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

Failures

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['distinct_id', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

posthog-ruby-async Compliance Report

Date: 2026-11-13T07:34:46.661443+00:00
Duration: 98339ms

⚠️ Some Tests Failed

46/47 tests passed, 1 failed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 107ms
Format Validation.Event Has Uuid ✅ 106ms
Format Validation.Event Has Lib Properties ✅ 107ms
Format Validation.Distinct Id Is String ✅ 105ms
Format Validation.Token Is Present ✅ 106ms
Format Validation.Custom Properties Preserved ✅ 106ms
Format Validation.Event Has Timestamp ✅ 106ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 8ms
Retry Behavior.Retries On 503 ✅ 5310ms
Retry Behavior.Does Not Retry On 400 ✅ 2107ms
Retry Behavior.Does Not Retry On 401 ✅ 2108ms
Retry Behavior.Respects Retry After Header ✅ 8013ms
Retry Behavior.Implements Backoff ✅ 15722ms
Retry Behavior.Retries On 500 ✅ 5210ms
Retry Behavior.Retries On 502 ✅ 5209ms
Retry Behavior.Retries On 504 ✅ 5212ms
Retry Behavior.Max Retries Respected ✅ 15622ms
Deduplication.Generates Unique Uuids ✅ 109ms
Deduplication.Preserves Uuid On Retry ✅ 5210ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10416ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5213ms
Deduplication.No Duplicate Events In Batch ✅ 110ms
Deduplication.Different Events Have Different Uuids ✅ 106ms
Compression.Sends Gzip When Enabled ✅ 105ms
Batch Format.Uses Proper Batch Structure ✅ 105ms
Batch Format.Flush With No Events Sends Nothing ✅ 4ms
Batch Format.Multiple Events Batched Together ✅ 110ms
Error Handling.Does Not Retry On 403 ✅ 2108ms
Error Handling.Does Not Retry On 413 ✅ 2109ms
Error Handling.Retries On 408 ✅ 5208ms

Feature_Flags Tests

⚠️ 16/17 tests passed, 1 failed

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

Failures

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['distinct_id', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']

@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 9449b6e: 2 Should fix.

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

Keep the quotes a From display name needs, such as
"Doe, Jane" <jane@example.com>, by formatting the address with Mail.
Walk only multipart/mixed, alternative and related containers, and
refuse any other multipart part, such as a signed message or a
multipart attachment, with unsupported_part. Ignore only Content-Type
and Content-Transfer-Encoding at the top level, so a header such as
Content-Language is refused instead of dropped.

Ticket: PostHog/michaelr-context#43

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

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed cbeae2a: 2 Should fix.

Refuse a body part header PostHog can't carry, and an attachment that has no
filename. Send an inline attachment's Content-ID as written.

Refs PostHog/michaelr-context#43

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

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

This is review round 3 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.

PostHog takes an attachment's MIME type alone. Send the UTF-8 that Mail
writes, and refuse any other charset.

Refs PostHog/michaelr-context#43

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

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

This is review round 4 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.

PostHog sends a body or an attachment by its MIME type. A body keeps only
charset, and an attachment only charset, name, and filename.

Refs PostHog/michaelr-context#43

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

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 662acf0: no findings.

Silthus and others added 2 commits November 5, 2026 13:10
Refs PostHog/michaelr-context#43

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

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 97588f8: 2 Should fix.

This is review round 5 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.


# Mail's own attachment? looks for a filename, but a Content-Disposition of attachment needs none.
def attached?(part)
part.attachment? || part.content_disposition.to_s.downcase.start_with?('attachment')

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.

P2 · Classify inline resources before mapping them as bodies

For a related HTML message with a filename-less inline text/plain resource, Mail's attachment? and this predicate return false. content sends the resource as the plain-text body and drops its Content-ID, breaking the HTML's cid: reference instead of refusing the mail. Recognize inline resources during classification so the filename check runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e3b6bf: a part with a Content-ID is a resource the HTML refers to, never a body, so one without a filename is refused with unsupported_part before any request. Test: "refuses an inline resource without a filename instead of sending it as a body". A body part marked inline without a Content-ID still goes out as a body.

refuse('unsupported_part', "PostHog can't send the #{part.charset} charset of #{part.filename}")
end
file = { filename: part.filename, content_type: part.mime_type, content: part.body.decoded.b }
return file unless part.inline?

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.

P2 · Preserve Content-ID on related resources without inline disposition

A multipart/related image with a filename and Content-ID but no Content-Disposition is a valid CID resource. Mail's inline? returns false, so attachment sends its bytes without content_id, leaving the HTML's reference unresolved. Preserve the identifier for related resources regardless of disposition, or refuse content the API cannot preserve.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e3b6bf: the mapper sends a resource's Content-ID whenever the part has one, whatever its Content-Disposition, and still refuses an inline part without one. Test: "sends the content ID of a related resource that has no Content-Disposition".

Silthus and others added 3 commits November 13, 2026 04:47
…livery

Brings posthog-ruby#325's upload flow up through #328. Attachments now
upload to file storage and the send names them by SHA-256, so the
Action Mailer specs check the bytes storage received for each file the
send names, against a fake upload route and storage.

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

A multipart/related part with a Content-ID is a resource the HTML
refers to, never a body: one without a filename is refused, and one
without an inline Content-Disposition keeps its Content-ID.

DeliveryError#retryable? now follows the rule PostHog::Emails retries
by: a used-up upload quota is permanent, and file storage's 500, 502
and 504 pass like its 503.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PostHog's send API refuses a template_key over 256 characters since
PostHog/posthog#134247. An explicit X-PostHog-Template-Key over 256 is
refused before any request, and a derived <mailer>-<action> key is cut
to 256.

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

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

SDK performance: posthog-ruby

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
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 111.42 µs/op 111.36 µs/op <0.1% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 29.28 MiB 29.3 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 30.14 MiB 30.14 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling 5.32 MiB 5.32 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 29.84 MiB 30.13 MiB 1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 25.6 µs/op 25.68 µs/op 0.3% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 30.12 MiB 30.36 MiB 0.8% more 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 111.7 µs/op 111.75 µs/op <0.1% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 34.51 MiB 34.48 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 37.52 MiB 37.46 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling 9.19 MiB 9.19 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 35.48 MiB 35.27 MiB 0.6% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 42.65 µs/op 42.3 µs/op 0.8% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 37.51 MiB 37.4 MiB 0.3% 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.02 ms/op 1.02 ms/op <0.1% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 29.28 MiB 29.31 MiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 29.65 MiB 29.69 MiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling 5.32 MiB 5.32 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 29.65 MiB 29.69 MiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 38.24 µs/op 37.83 µs/op 1.1% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 29.65 MiB 29.69 MiB 0.1% 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 No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 1.02 ms/op 1.02 ms/op <0.1% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 34.48 MiB 34.46 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.56 MiB 37.57 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling 9.19 MiB 9.19 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 34.62 MiB 34.57 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 43.6 µs/op 44.5 µs/op 2.1% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 37.47 MiB 37.45 MiB <0.1% less memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 10.97 µs/op 11.87 µs/op 8.2% more time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 10.97 µs/op 11.87 µs/op 8.2% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 11.42 µs/op 11.3 µs/op 1.1% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 11.42 µs/op 11.3 µs/op 1.1% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 343.04 count/op 343.04 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 129.6 µs/op 129.25 µs/op 0.3% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 129.6 µs/op 129.25 µs/op 0.3% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 3,324.19 count/op 3,324.19 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 1.25 ms/op 1.25 ms/op 0.4% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 1.25 ms/op 1.25 ms/op 0.4% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 33,114.44 count/op 33,114.66 count/op <0.1% more Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 13.32 ms/op 13.31 ms/op 0.1% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 13.32 ms/op 13.31 ms/op 0.1% less time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 38.09 MiB 38.12 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 40.96 MiB 40.74 MiB 0.5% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling 8.02 MiB 8.02 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 40.31 MiB 40.27 MiB 0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 40.7 MiB 40.43 MiB 0.6% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 39.92 MiB 39.96 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 41.53 MiB 41.54 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling 9.53 MiB 9.53 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 39.71 MiB 39.75 MiB 0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 41.29 MiB 41.36 MiB 0.2% more 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 12.27 µs/op 12.26 µs/op 0.1% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 12.27 µs/op 12.26 µs/op 0.1% less 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 19.36 µs/op 19.84 µs/op 2.5% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 19.36 µs/op 19.84 µs/op 2.5% 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 23.83 µs/op 23.91 µs/op 0.3% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 23.82 µs/op 23.91 µs/op 0.3% more 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 32.27 µs/op 32.37 µs/op 0.3% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 32.27 µs/op 32.37 µs/op 0.3% more 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 27.91 µs/op 27.85 µs/op 0.2% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 27.91 µs/op 27.84 µs/op 0.2% 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 14.56 µs/op 14.05 µs/op 3.5% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 14.56 µs/op 14.05 µs/op 3.5% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 99.01 count/op 99.01 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 42.71 µs/op 42.94 µs/op 0.5% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 42.71 µs/op 42.93 µs/op 0.5% 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 11.8 µs/op 11.42 µs/op 3.2% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 11.8 µs/op 11.41 µs/op 3.2% 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 14.42 µs/op 14.37 µs/op 0.4% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 14.42 µs/op 14.37 µs/op 0.4% 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 6f87535453ade7b0476df89e4a6a9cf1d7257740 → ed1a910cc0d9331a6251bf20f01e8977326a7cc3.

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 9 commits November 13, 2026 05:05
…lobal load hook

The spec ran the Railtie's initializer, which left its :action_mailer
load hook registered for the whole suite. A spec that runs that load
hook on a stand-in class then called add_delivery_method on it. The
spec now does what the hook does on ActionMailer::Base; 'a Rails app'
still boots the Railtie's own hook.

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

Action Mailer encodes a mail before it delivers it, and encoding gives
every inline part a Content-ID, so a Content-ID no longer makes a part a
file. Two bodies must share their nearest multipart/alternative, since
PostHog sends them as alternatives. The SDK's argument checks raise
UnsupportedMailError invalid_mail, and with raise_delivery_errors off
the error goes to the log, since Mail drops it. A spec holds
DeliveryError#retryable? to the SDK's own retry rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Booting an app in development writes tmp/local_secret.txt into the
working directory, which nothing ignores, so a run of the suite left a
secret in the checkout for the next commit to pick up.

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

Two bodies go out as alternatives only when the nearest container they
share is multipart/alternative, so alternative[mixed[text, html]] is
refused too. Body kinds are checked first, so an image without a
filename is refused by its MIME type. The retry drift spec now sends
each failure through a client that retries once, instead of calling the
SDK's private rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…into fix-329-r1

# Conflicts:
#	posthog-rails/lib/posthog/rails/railtie.rb
#	public_api_snapshot.txt
#	scripts/public_api_snapshot.rb
X-PostHog-Track-Opens, X-PostHog-Track-Clicks and
X-PostHog-Capture-Engagement set tracking.opens, tracking.clicks and
tracking.engagement, and X-PostHog-Sensitive sets sensitive. Each takes
true or false, and none is sent. The adapter never sends
capture_engagement, so a send can't carry it next to tracking.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silthus Silthus closed this Nov 14, 2026
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.

1 participant