Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
posthog-ruby-sync Compliance ReportDate: 2026-11-25T04:01:34.195283+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
posthog-ruby-async Compliance ReportDate: 2026-11-25T04:01:46.038226+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
SDK performance: posthog-rubyBenchmarks 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
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 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
…edentials out of errors Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…8 times Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…head Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s deadline wins Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… warnings Timeout.timeout(seconds, Timeout::Error) raises that class inside the block, so the rescue around warning logging caught it and raised schedule_not_confirmed instead. A Timeout::Error now propagates, and the deadline specs deliver it once the logger has been entered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ace a logger error The send-now cutoff read the clock when the reply arrived, so a slow reply could accept a send-now answer for a time more than a minute ahead. The client now reads the clock once before the first POST, as the Node SDK does. The client can't tell a failing logger from a caller's deadline of any class, so it no longer replaces either: warnings are logged in an ensure, and a logger's own error keeps schedule_not_confirmed as its cause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- a 503 that moves the clock 2 s, then queued with no time, still raises schedule_not_confirmed for a time 61 s ahead - the deadline spec holds the logger on a queue instead of a sleep Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oss retries This reverts commit 8a90d74. The review loop is at its ceiling, so the spec waits for another round, and the PR lists the gap under Known issues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ment through shutdown - restore the spec for a retry that moves the clock, and the queue barrier in the deadline spec - the warning spec asserts Client#shutdown's result, not the private Emails#close - the scheduled_at docs name the one-minute send-now tolerance - the changeset says SendResult's Marshal format changes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ruby keeps the first cause of an exception object raised again, so a logger that reuses one error named an earlier email's ID. Drop the scheduled row of the status pass-through spec, which guards nothing the archived row doesn't. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Setting the cause on the logger's own object rewrote the error an earlier caller already held, and raised circular causes inside that caller's rescue. Raise a copy that names this send instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e copied A reused logger exception whose copy raised surfaced as that TypeError, with an earlier email's ID in its cause chain. Raise this send's schedule_not_confirmed with the logger's error as its cause instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… exception Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A logger's error propagates when it has no cause or this send's error is among its causes. An exception object the logger raised before names an earlier send, so this send's error propagates with it as its cause. No code of the logger's exception runs, so nothing swallows a deadline. 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>
A send that raises schedule_not_confirmed no longer calls the logger. EmailError#warnings holds the reply's warnings instead. A successful send logs them as before, and a failing logger's error propagates as is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
💡 Motivation and Context
PostHog Cloud now schedules transactional emails on the server, but the Ruby SDK has no way to ask for it. A Ruby app that wants a reminder tomorrow has to run its own job queue to send later.
This PR adds
scheduled_attoemails.send, on both forms (template and code), and nothing more: no cancel, move, list or batch. It matches the Node (PostHog/posthog-js#5694) and Python (PostHog/posthog-python#1240) SDKs.Impact
Lets Ruby apps on PostHog Cloud schedule a transactional email up to 7 days ahead without a job queue of their own. The server's send event carries a
scheduledproperty, which shows whether Ruby senders use it once the server flag is on.Caution
🔵 Merge risk: low, 🔴 at release · one-way door once the Client Libraries team approves the gem release:
scheduled_at,SendResult#status,SendResult#scheduled_atandEmailError#message_idbecome public API, and scheduled emails already accepted still go out with the flag offReleaseenvironment before it bumps the version and publishes.scheduled_at, on PostHog Cloud US and EU, once released: new entry point. The client sends the time in UTC to the millisecond, rounded up, and checks the 202 before it returns. A wrong check is silent harm (an email out at the wrong time, or a false error). The specs cover it against WebMock, and one live send covers PostHog Cloud US at f41adaa, whose library this head keeps.schedule_not_confirmedfor an email PostHog accepted. The specs cover it against WebMock; the error carries the message ID and says to read the email before sending again. A missed bug there leaves the caller with an error for an accepted email.scheduled_too_far) against WebMock, but not the flag-off answer itself. A missed bug there sends at the wrong time or raises a falseschedule_not_confirmed.queued, so that email can go out up to a minute early. By design, for clock skew. The client compares the time after rounding it up, so a time exactly a minute ahead can land just past the line and raiseschedule_not_confirmedwith the message ID for an email PostHog queued.scheduled_at: unchanged on the wire, withstatus: "queued"andscheduled_at: niladded to the result. The existing email specs pass unchanged, and the live shadow diff covers PostHog Cloud US.SendResultgains a Struct member, which changes its Marshal format both ways: aSendResultan older gem marshaled, such as one in a Rails cache, doesn't load in this one, and one this gem marshaled doesn't load in an older one. During a rolling upgrade, a process still on the older gem raisesTypeErrorreading a result a newer process cached, until the upgrade finishes. A failed cache read in the caller's app, never a send; cosmetic for a cache that refills. No cross-version run covers it (Michael accepted the gap, d-123a1b48).SendResult, scheduled or not, has four members once released: a pattern match on three elements, such asin [id, replayed, warnings], no longer matches, andto_handto_againscheduled_at. A hash pattern such asin { id: }still matches. The changeset says so.schedule_not_confirmednever calls the logger, and its error carries the reply's warnings onEmailError#warnings. A successful send logs them as before. The specs cover both against WebMock; no live reply carried a warning.scheduled_aton any other host (self-hosted, reverse proxy, custom domain): refused before any request withscheduling_requires_cloud, since an older server would drop the field and send at once.workflows-email-scheduled-sendsflag. With it off, PostHog answers 400 onscheduled_atand the SDK raises it, never sending without the time. Emails already scheduled still go out.Rollout
scheduledrows in the email status read.What changes
emails.send(scheduled_at:)takes aTime(a Rails time with zone too), aDateTime, or an ISO 8601 string with an explicit offset,+01:00or+0100asstrftime('%z')writes it. A string without an offset, a date that the Gregorian calendar lacks, aDate, or a number raisesArgumentErrorbefore any request.scheduled_at, the 202 has to confirm the time:status: "scheduled"with exactly the sent instant returnsstatus: "scheduled"andscheduled_atas a UTCTime.status: "queued"withscheduled_at: null(the time had passed) returnsstatus: "queued"andscheduled_at: nil, but only when the time is at most a minute ahead by the client clock, read once before the first request. Further ahead, it raisesschedule_not_confirmed.scheduled_atkey or another instant, raisesschedule_not_confirmedwithEmailError#message_id, and is never retried. The fix text says to read the email withemails.getbefore sending again. The error carries the reply's warnings on the newEmailError#warnings, and the client doesn't log them: it logs warnings only for a send that succeeds. This is the one 2xx whose warnings the SDK does not log, so the email skill's "unless its SDK already does" doesn't hold for it: an app that rescuesschedule_not_confirmedlogsEmailError#warningsitself.SendResult#statusis derived fromscheduled_at, so it has no writer.scheduling_requires_cloudmessage names only the host and port, never credentials in the URL.scheduled_atraises as a normalEmailError. There is no fallback to sending now.emails.getalready passes statuses through. Its docs now namescheduled.Known issues
schedule_not_confirmed. The email exists andemails.getreads it.lib/posthog/emails.rb:73:SendResultgains a Struct member, so its Marshal format changes both ways. A result one gem version cached doesn't load in the other, including during a rolling upgrade. The changeset says so, and Michael accepted it (d-123a1b48).lib/posthog/emails.rb:73: the new member also breaks pattern matches on three elements and addsscheduled_attoto_handto_a, for every send. The changeset says so.lib/posthog/emails.rb:716: a time exactly a minute ahead, compared after rounding, can raiseschedule_not_confirmedfor an email PostHog queued. The error carries the message ID and says to read the email before sending again.lib/posthog/emails.rb:391: ascheduled_atstring in an ASCII-incompatible encoding, such as UTF-16LE, raisesEncoding::CompatibilityErrorinstead ofArgumentError. It still refuses before any request, so nothing is sent.💚 How did you test it?
Test-first, in
spec/posthog/emails_spec.rbagainst WebMock, on Ruby 3.2.2:Timewith a+01:00offset, a string with+02:00, a Rails time with zone and aDateTimeall send the same UTC millisecond, on both forms1500-02-29among them), aDateand an integer raise before any requestscheduling_requires_cloudbefore the attachment upload or the send, without the URL's credentials; EU schedulesqueuedwithnull; the same answer for a time 60.001 s ahead raisesschedule_not_confirmed, also when the reply comes 2 s late for a time 61 s ahead, or a 503 retry comes 2 s laterschedule_not_confirmedwith the message ID after one request, and that ID reads the email; so does a reply time that isn't valid UTF-8client.shutdownreads the send as settled, and a raising logger's error or a caller's deadline of any class propagates as it isscheduled_too_far400 raises with no second requestemails.getpasses a status it doesn't map through,archivedas the casebundle exec rubocopandbundle exec rake public_api:checkpass. In Docker,spec/posthog/rails/template_backtrace_spec.rbfails the same way onmain, so CI is the reference for the full suite. CI's non-required "RSpec (latest Rails / stable Ruby)" job fails onmaintoo, and is unrelated to this PR:regexp_parser2.13.2 breaksjson_schemerwhile the MCP specs load.Live, against PostHog Cloud US at f41adaa, whose library and specs this head keeps: one scheduled send about 5 minutes ahead, with same-key replays before and after the due time. The 202 confirmed the time, and each replay returned the same message ID and time. The status read says delivered, and the delivery log and the inbox show one email at its time. No reply carried a warning: PostHog returns one only for a project with no verified sending domain, and the proof project has one.
Shadow diff against
main, live on PostHog Cloud US: one ordinary send withoutscheduled_atfrom each. The request body and the 202 reply match. The head result addsscheduled_at: nilandstatus: "queued", and both emails arrived.main's email specs pass unchanged against this branch'slib/.Not checked: a
SendResultmarshaled across gem versions, in either direction. Adding the Struct member changes its Marshal format, and the changeset says so. Not checked live: a reply that carries a warning.📝 Checklist
If releasing new changes
pnpm changesetto 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 scheduled-send work. It followed the server's v1 contract and aligned edge cases with the Node and Python PRs. Two choices were deliberate: the result returnsscheduled_atas aTime, asStatusdoes for its times, and theschedule_not_confirmedfix text gives one piece of advice for every caller, as in Python: read the email withemails.getbefore sending again.EmailError#warnings. Replaced the cause-chain handling of a raising logger.scheduling_requires_cloudandschedule_not_confirmed, the same in every SDK.schedule_not_confirmedpast a minute of clock skew, in every SDK.SendResultMarshal format:443, since a refusal never sends early.Involvement: no grilling rounds, no prototypes; one Hedge review panel (Claude fresh eyes, Codex correctness, risk, design and anti-overengineering), one Codex fixes review and thirteen Codex final reads, three of them past the review budget on the agent's call; live sends captured at three heads, and a live shadow diff.
🤖 Generated with Claude Code
How did you test this code?
17744e9(reused fromf41adaa)1ae7ecfto17744e917744e9Not checked: none recorded
Full receipt: https://artifacts.posthog.com/a/hSRjKU9JQ5Sy9PB9BWihJV