Skip to content

feat(emails): schedule a transactional email with scheduled_at - #330

Open
Silthus wants to merge 33 commits into
mainfrom
feat/scheduled-email-send
Open

Silthus wants to merge 33 commits into
mainfrom
feat/scheduled-email-send

Conversation

@Silthus

@Silthus Silthus commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

A PHP app can't send a transactional email later. It has to run its own job queue to send at the right time. PostHog Cloud now schedules a send that carries scheduled_at, and this PR adds the field to emails()->send(), as the Node (PostHog/posthog-js#5694) and Python (PostHog/posthog-python#1240) SDKs do.

Impact

The server counts scheduled sends on the send event (scheduled and scheduled_lead_bucket), so the SDKs need no event of their own. This PR adds the PHP path to them.

Warning

🟡 Merge risk: medium, 🔴 once released · one-way door once the release publishes: scheduled_at on send(), getStatus() and getScheduledAt() on SendEmailResult, and getMessageId() on EmailError become public API

  • A send with scheduled_at changes from a local invalid_form refusal to a scheduled send, on PostHog Cloud US and EU only. Any other app host throws scheduling_requires_cloud before any request.
  • A send without scheduled_at, and emails()->get(), are unchanged. The shadow diff covers them: the base's whole test suite passes unchanged against the library at this head.
  • A send whose answer carries warnings no longer throws when error_log can't write them. The base threw after PostHog had queued the email; now the result comes back. A new test covers it.
  • Covered by the live run on US Cloud at this head: a time that had passed came back queued and went out now, and a time 30 seconds ahead came back scheduled with its time and went out once, at the requested second. A same-key replay returned the same email.
  • Uncovered: EU Cloud has no live run, since no EU send key exists. It takes the same SDK path as US. Residual: a scheduled send that EU apps can't make.
  • Uncovered: a queued answer to a retry or a replay is tested with fakes only. The minute counts from the send's first attempt, as in every SDK. Residual: a send more than a minute ahead of its first attempt, whose retries reach PostHog only after the time has passed, reads a false schedule_not_confirmed for an email that went out once. A caller who then sends it again with a new key sends it twice; the error carries the message ID and says to read its status first.
  • Uncovered: attachments uploaded before PostHog refuses scheduled_at while its flag is off. Residual: uploads that no email uses.
  • A cache shared across a rolling upgrade: the cross-version run shows results and errors without a schedule read both ways. A scheduled result reads as an incomplete object in an older reader, or in one whose allowed_classes names only SendEmailResult (Known issues).
  • Uncovered: an app class that extends SendEmailResult or EmailError and already defines getStatus(), getScheduledAt() or getMessageId() with another signature. Residual: that class fails to load after the upgrade (Known issues).
  • Switch-off: none in the SDK. The server's workflows-email-scheduled-sends flag answers 400 on scheduled_at while it is off, and the SDK surfaces that 400 without falling back to sending now.
  • Tier: critical (c: public API once released; f: SDK release)

Rollout

  • Stages: the server's floor and send PRs deploy to US and EU first, the flag goes on for one team and the live proof runs, then this PR merges and its release publishes.
  • Watch: a schedule_not_confirmed error in an app that schedules. No alert exists for it in the SDK.

Changes

  • send() takes scheduled_at on both forms: a DateTimeInterface, or an ISO 8601 string with an explicit offset (Z or ±HH:MM).
  • The client rounds a time finer than a millisecond up to the next millisecond, so the email never goes out early. It does this once, before the first request, and sends the same UTC value on every retry.
  • A string without an offset, an impossible date such as Feb 30, a Unix timestamp or anything else throws invalid_scheduled_at before any request.
  • A scheduled send to an app host other than https://us.posthog.com or https://eu.posthog.com throws scheduling_requires_cloud before any request, uploads included. The error names only the host and port, never credentials in the URL. A proxy with a Cloud app_host still schedules.
  • The client checks the 202 of a scheduled send:
    • status: scheduled with the requested instant (any offset, compared at millisecond precision): accepted, getStatus() is scheduled, getScheduledAt() the time in UTC.
    • status: queued with scheduled_at: null for a time that had passed or was at most 60 seconds ahead of the client clock when the send's first attempt went out: accepted. A retry or a replay never moves that minute, getStatus() is queued, getScheduledAt() is null.
    • status: queued with scheduled_at: null for a time more than 60 seconds ahead: throws schedule_not_confirmed with getMessageId(), never a success.
    • Anything else, such as a 202 without the scheduled_at key or another instant: throws schedule_not_confirmed with getMessageId(). An accepted 202 is never retried.
  • A 400 on scheduled_at surfaces as an EmailError. The client never falls back to sending now.
  • EmailStatus documents scheduled, which get() already passed through.
  • README, the send() docblock, the public API snapshot and a minor changeset.

💚 How did you test it?

Test-first in test/EmailsTest.php, through Emails::send() and Emails::get() with the fake PostHog transport. The new cases cover both forms; UTC and non-UTC offsets, strings and DateTimes; sub-millisecond rounding up, including into the next year; the same value on a retry; offset-less and impossible times refused before any request; Cloud US and EU hosts against self-hosted, proxy and local hosts; the exact-match, other-instant and missing-key 202s; a 202 that reports the requested millisecond with extra digits; results and errors serialized by the SDK before scheduling; the queued answer for a past time, for a time a minute ahead, and refused for a time more than a minute ahead, without the scheduled_at key, across a daylight-saving change of the local clock, and when the clock fails after PostHog answered, including symfony/clock 6.2, which has no Clock class, and 6.3.0, whose NativeClock raises a deprecation on PHP 8.4+; a replay; a 400 with no fallback; and scheduled on the status read. I broke each guarded behaviour in turn (rounding, the Cloud check, the host in the message, the missing-key check, the 60-second leeway, the instant check, the offset, the date check, the serialization defaults), and each break failed a test.

Locally, through PHP 8.5 in Docker: the full PHPUnit suite, phpcs on the changed files, composer api:check and composer validate --strict pass.

A five-lens review panel (hedge proof review, round 1) found one real bug: a scheduled send to an app_host with credentials in its URL copied them into the error message. It is fixed with a test. The other valid findings are fixed too.

Later single-reader rounds found the send-now check reused one clock read across retries, and that the new properties changed how unscheduled results and errors serialize. Both are fixed test-first, and a result or error without a schedule serializes exactly as the base did. The send-now check now runs once, before the send's first attempt, so a retry or a replay never moves the minute: every SDK counts it the same way. A confirmed schedule comes back as an internal final subclass of SendEmailResult that holds the time, so SendEmailResult itself has no serialization hook: lazy objects, subclasses, and dynamic and virtual properties keep the base's behavior. EmailError drops a null message ID through an untyped __sleep(), so a subclass's own __sleep(), __serialize() or Serializable still decides its fields.

Shadow diff: the base's whole test suite, unchanged, passes against the library at this head, the git archive test included.

Cross-version: the SDK at this head, installed with the real symfony/clock 6.2 (no Clock class) and 6.3.0 on PHP 8.2 and 8.5 with every deprecation thrown, queues a past time, schedules a future one and refuses an unconfirmed one in all four runs. Results and errors serialized by the base read cleanly here, and unscheduled ones serialized here read cleanly in the base.

Live run on US Cloud at this head: a send for a time that had passed, and a send 30 seconds ahead plus a same-key replay. The first was queued now. The second was scheduled at the requested millisecond, the replay returned the same email, and the delivery log and the mailbox each show one email per send, the scheduled one sent after its time.

Known issues

  • No sdk-specs spec covers scheduled sends yet.
  • Self-hosted PostHog and reverse proxies can't schedule in v1, by design. A capability check comes in a follow-up.
  • minor: test/EmailsTest.php:2116 No test sends without scheduled_at and gets a schedule in the answer (the branch is now lib/Emails.php:1274). The test is written and lands with the stacked batch PR.
  • major: lib/Emails.php:1283 A scheduled result serializes as an internal subclass. An older SDK, or a reader whose allowed_classes names only SendEmailResult, reads it as an incomplete object, such as in a cache shared across a rolling upgrade. An error with a message ID read by an older SDK gets a PHP 8.2+ dynamic-property deprecation, which fails the read in an app that throws on deprecations (lib/EmailError.php:72). Results and errors without a schedule serialize exactly as before, and this version reads old ones cleanly.
  • minor: lib/SendEmailResult.php:57 and lib/EmailError.php:155 Both classes are public and not final. An app subclass that already defines getStatus(), getScheduledAt() or getMessageId() with an incompatible signature fails to load after the upgrade.
  • When PostHog answers a scheduled send with warnings but without confirming the time, the SDK logs those warnings, but the schedule_not_confirmed error doesn't carry them.
  • minor: lib/Emails.php:1293 [base] On symfony/clock 6.2, or up to 6.3.0 in an app that throws on deprecations, the retry wait's Clock::get() (now lib/Emails.php:1112, base lib/Emails.php:966) fails before a retry. This is base behavior: the send-now check falls back to PHP's clock, the retry wait doesn't yet.
  • When retries or a lost answer delay PostHog's queued answer, the SDK still counts the minute from the send's first attempt, so a send whose time was more than 60 seconds ahead then reads schedule_not_confirmed even if the time has passed by the answer. This is the cross-SDK rule. The email goes out once; read its status with getMessageId() before you send it again.
  • A client clock that runs more than 60 seconds behind can turn a send PostHog rightly queued now into a false schedule_not_confirmed. The email still goes out once; read its status with getMessageId() before you send it again.

📝 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 change to generate a change intent file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Written by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, as an implementation lane under a conductor thread that Michael directs. It follows the scheduled-sends spec's v1 scope: the field, the Cloud-host check and the answer check, with no cancel, move, list or batch. The Python reference PR set the error names. DateTimeInterface counts as an aware time, since a PHP DateTime always holds an instant.

Question Answer Who Where
queued with a null time for a future request Refused with schedule_not_confirmed when the time is more than 60 seconds ahead, in all SDKs. Replaced: accepting it, as spec v7 said. 👍 conductor brief
Where the send-now minute counts from The send's first attempt, in every SDK, never a retry or the answer. Replaced: counting from the attempt PostHog answered. 👤 conductor brief
Error code names Python's scheduling_requires_cloud and schedule_not_confirmed, in every SDK. Rejected: Node's old names. 🤖 this PR
Reply precision The confirmed time must equal the requested instant at millisecond precision. Rejected: rounding the reply up as Node does. 🤖 this PR

Involvement: no grilling rounds; tests mutation-checked; one five-lens review panel (Claude fresh eyes, GPT correctness, risk, design and anti-overengineering).

🤖 Generated with Claude Code

How did you test this code?

Merge card: medium, one-way door · 1 round, 25 final reads · gaps: prod-shape (👤 the user d-f03eae56), judge (🤖 agent d-a597f50e) · 9 known issues · 3227 min opened to ready

Proof What ran Result Commit
live-run A past-time and a 30-second scheduled send against PostHog Cloud US at this head, plus a same-key replay, then a mailbox read Queued and scheduled results with the right time, same id on replay, and the mailbox holds one email per send, the scheduled one at its second 910a663 (reused from 76ca036)
prod-shape not run gap, accepted
cross-version Serialized results and errors read across the base and this head on PHP 8.2 and 8.5 with deprecations thrown, plus the real symfony/clock 6.2 and 6.3.0 runs from an earlier head whose clock code is unchanged Unscheduled results and errors read both ways and every value round-trips at head; scheduled results and errors with an ID fail old readers, listed under Known issues 910a663 (reused from 62301f8)
shadow-diff The test suite of the merge base with main, unchanged, against the library at this head, with git available Every base test passes, the package archive test included 910a663
Review 5-lens panel (claude-opus-5-5, gpt-6.2-sol), round 1, final read 1, final read 2, final read 3, final read 4, final read 5, final read 6, final read 7, final read 8, final read 9, final read 10, final read 11, final read 12, final read 13, final read 14, final read 15, final read 16, final read 17, final read 18, final read 19, final read 20, final read 21, final read 22, final read 23, final read 24, final read 25 108 findings: 54 fixed, 52 rejected, 2 other d282e04 to 910a663
Proof judge an independent model reads the evidence against the diff ❌ failed at 910a663
PR Review rounds Production lines Sanity pass Skipped proofs
#330 1 round, 25 final reads 688 → 1,489 (×2.2); docs 6 → 10 not run prod-shape: The SDK's app_host setting lives in customer code and never reaches PostHog, so no production read shows which PHP apps point at a proxy or self-hosted host; the change refuses those hosts locally before any request, and a send without scheduled_at is unchanged for every host (👤 the user d-f03eae56); judge: The judge holds the first-attempt send-now window Michael decided for every SDK, the base retry-wait defect on symfony/clock 6.2 that ordinary sends already have, and the evidence carries from 76ca036. Each is listed under Known issues; the only commit since renames the error of scheduling_requires_cloud, thrown before any request, and the final read of this head found nothing. (🤖 agent d-a597f50e)

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

send() takes scheduled_at, a DateTimeInterface or an ISO 8601 string
with an offset, on both forms. The client rounds it up to the next
millisecond once and sends it in UTC on every retry. It refuses a
string without an offset, and any app host that isn't PostHog Cloud,
before any request. It checks that the 202 confirms the requested
instant and throws schedule_not_confirmed with the message ID when
it doesn't. The result has getStatus() and getScheduledAt(), and
EmailError has getMessageId().

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

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

posthog-php-socket Compliance Report

Date: 2026-11-26T15:49:39.124033+00:00
Duration: 118704ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 30ms
Format Validation.Event Has Uuid ✅ 524ms
Format Validation.Event Has Lib Properties ✅ 525ms
Format Validation.Distinct Id Is String ✅ 526ms
Format Validation.Token Is Present ✅ 526ms
Format Validation.Custom Properties Preserved ✅ 525ms
Format Validation.Event Has Timestamp ✅ 526ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 526ms
Retry Behavior.Retries On 503 ✅ 5834ms
Retry Behavior.Does Not Retry On 400 ✅ 2529ms
Retry Behavior.Does Not Retry On 401 ✅ 2527ms
Retry Behavior.Respects Retry After Header ✅ 8534ms
Retry Behavior.Implements Backoff ✅ 16249ms
Retry Behavior.Retries On 500 ✅ 5637ms
Retry Behavior.Retries On 502 ✅ 5632ms
Retry Behavior.Retries On 504 ✅ 5636ms
Retry Behavior.Max Retries Respected ✅ 16249ms
Deduplication.Generates Unique Uuids ✅ 534ms
Deduplication.Preserves Uuid On Retry ✅ 5635ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10840ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5640ms
Deduplication.No Duplicate Events In Batch ✅ 533ms
Deduplication.Different Events Have Different Uuids ✅ 528ms
Compression.Sends Gzip When Enabled ✅ 526ms
Batch Format.Uses Proper Batch Structure ✅ 526ms
Batch Format.Flush With No Events Sends Nothing ✅ 521ms
Batch Format.Multiple Events Batched Together ✅ 514ms
Error Handling.Does Not Retry On 403 ✅ 2528ms
Error Handling.Does Not Retry On 413 ✅ 2528ms
Error Handling.Retries On 408 ✅ 5633ms

Feature_Flags Tests

✅ 17/17 tests passed

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

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

posthog-php-lib_curl Compliance Report

Date: 2026-11-26T15:49:25.721349+00:00
Duration: 119465ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 33ms
Format Validation.Event Has Uuid ✅ 525ms
Format Validation.Event Has Lib Properties ✅ 526ms
Format Validation.Distinct Id Is String ✅ 528ms
Format Validation.Token Is Present ✅ 527ms
Format Validation.Custom Properties Preserved ✅ 528ms
Format Validation.Event Has Timestamp ✅ 527ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 527ms
Retry Behavior.Retries On 503 ✅ 5837ms
Retry Behavior.Does Not Retry On 400 ✅ 2531ms
Retry Behavior.Does Not Retry On 401 ✅ 2530ms
Retry Behavior.Respects Retry After Header ✅ 8536ms
Retry Behavior.Implements Backoff ✅ 16250ms
Retry Behavior.Retries On 500 ✅ 5636ms
Retry Behavior.Retries On 502 ✅ 5639ms
Retry Behavior.Retries On 504 ✅ 5636ms
Retry Behavior.Max Retries Respected ✅ 17039ms
Deduplication.Generates Unique Uuids ✅ 250ms
Deduplication.Preserves Uuid On Retry ✅ 5637ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10844ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5641ms
Deduplication.No Duplicate Events In Batch ✅ 534ms
Deduplication.Different Events Have Different Uuids ✅ 531ms
Compression.Sends Gzip When Enabled ✅ 528ms
Batch Format.Uses Proper Batch Structure ✅ 528ms
Batch Format.Flush With No Events Sends Nothing ✅ 524ms
Batch Format.Multiple Events Batched Together ✅ 514ms
Error Handling.Does Not Retry On 403 ✅ 2530ms
Error Handling.Does Not Retry On 413 ✅ 2531ms
Error Handling.Retries On 408 ✅ 5637ms

Feature_Flags Tests

✅ 17/17 tests passed

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

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

posthog-php-fork_curl Compliance Report

Date: 2026-11-26T15:49:39.648343+00:00
Duration: 118293ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 33ms
Format Validation.Event Has Uuid ✅ 528ms
Format Validation.Event Has Lib Properties ✅ 529ms
Format Validation.Distinct Id Is String ✅ 529ms
Format Validation.Token Is Present ✅ 530ms
Format Validation.Custom Properties Preserved ✅ 529ms
Format Validation.Event Has Timestamp ✅ 530ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 529ms
Retry Behavior.Retries On 503 ✅ 5852ms
Retry Behavior.Does Not Retry On 400 ✅ 2531ms
Retry Behavior.Does Not Retry On 401 ✅ 2531ms
Retry Behavior.Respects Retry After Header ✅ 8543ms
Retry Behavior.Implements Backoff ✅ 16275ms
Retry Behavior.Retries On 500 ✅ 5645ms
Retry Behavior.Retries On 502 ✅ 5645ms
Retry Behavior.Retries On 504 ✅ 5642ms
Retry Behavior.Max Retries Respected ✅ 16271ms
Deduplication.Generates Unique Uuids ✅ 39ms
Deduplication.Preserves Uuid On Retry ✅ 5645ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10854ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5652ms
Deduplication.No Duplicate Events In Batch ✅ 533ms
Deduplication.Different Events Have Different Uuids ✅ 530ms
Compression.Sends Gzip When Enabled ✅ 532ms
Batch Format.Uses Proper Batch Structure ✅ 528ms
Batch Format.Flush With No Events Sends Nothing ✅ 519ms
Batch Format.Multiple Events Batched Together ✅ 517ms
Error Handling.Does Not Retry On 403 ✅ 2532ms
Error Handling.Does Not Retry On 413 ✅ 2531ms
Error Handling.Retries On 408 ✅ 5640ms

Feature_Flags Tests

✅ 17/17 tests passed

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

Silthus and others added 16 commits November 23, 2026 08:45
A scheduled send to an app_host that carries credentials put them in
the error message. The refusal now names only the host and port. The
new nullable properties get defaults so an object serialized by the
previous version still reads. Also reuses the Cloud host map, drops
clock bounds the parser already enforces, and tightens the tests and
docs from review round 1.

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

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

Feed unserialize() fixtures written by the SDK before scheduling, and
check that a 202 reporting the requested millisecond with extra digits
is accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A scheduled send that PostHog answers with queued and a null
scheduled_at now throws schedule_not_confirmed with the message ID
when the requested time is more than 60 seconds ahead of the clock.

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

The minute ahead used local wall-clock seconds, so it stretched by an
hour when the local clock left daylight saving. A queued answer without
the scheduled_at key now reads like a null time, as in posthog-python.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 202 that drops the scheduled_at key may come from a PostHog that
ignored the field, so it throws schedule_not_confirmed for any time, as
in posthog-python. Only an explicit null within the minute sends now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Emails reads Clock::get() to retry and to check a queued scheduled send,
and symfony/clock 6.2 has no Clock class.

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

A clock that throws while the client checks a queued answer now gives
schedule_not_confirmed with the message ID instead of losing it. An
unscheduled result serializes exactly as before scheduling, so an older
SDK reads it without a dynamic property. The replay test checks the
original ID and time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
__sleep broke serialization of SendEmailResult subclasses, so results
keep PHP's default serialization. The minute check now catches a failure
anywhere in reading and shifting the clock's time, and the test fails
the clock once PostHog has answered.

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

The minute check catches the missing Clock class of symfony/clock 6.2
and reports schedule_not_confirmed with the message ID, so apps pinned
to 6.2 can still upgrade. Split the compatibility test and check that a
send without scheduled_at ignores a schedule in the answer.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
symfony/clock 6.2 has no Clock class. The guarded minute check turns
the missing class into schedule_not_confirmed with the message ID, so
apps pinned to 6.2 can still upgrade. A test refuses to load the class
and fails when the guard catches less than every Throwable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On symfony/clock 6.2 the minute check now reads the time from NativeClock,
so a queued answer for a past time is accepted there too instead of
throwing schedule_not_confirmed.

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

symfony/clock 6.2's NativeClock raises an implicit-nullable deprecation on PHP 8.4+, which apps that throw on
deprecations turned into a false schedule_not_confirmed. Without the Clock class the minute check now reads PHP's
own clock. A schedule_not_confirmed answer now logs the server's warnings before it throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silthus and others added 9 commits November 24, 2026 08:25
Up to symfony/clock 6.3.0, Clock::get() loads a NativeClock that raises a deprecation on PHP 8.4+, so an app that
throws on deprecations still got a false schedule_not_confirmed. The minute check now reads Clock::get() and falls
back to PHP's clock on any failure, one path for 6.2, 6.3.0 and a clock that fails. Warnings are no longer logged
when error_log is disabled, so an unconfirmed schedule still throws schedule_not_confirmed with the message ID.

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

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>
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>
The result and the error now leave out an unset schedule or message ID
through an untyped __sleep, so a subclass's own __sleep, __serialize or
Serializable still decides its fields, and an untyped override loads.
Warnings reach an error_log the app defines in the PostHog namespace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silthus and others added 5 commits November 24, 2026 16:02
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>
Unscheduled results serialize natively again, as the previous version did,
so lazy objects, dynamic and virtual properties keep their base behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silthus
Silthus marked this pull request as ready for review November 25, 2026 11:28
@Silthus
Silthus requested a review from a team as a code owner November 25, 2026 11:28
@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 7106cd9: 1 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/Emails.php Resolved

@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.

Silthus and others added 2 commits November 26, 2026 10:08
A queued answer without a scheduled time now counts as a send-now only
when scheduled_at was at most a minute ahead when the first attempt went
out. A retry or a replay no longer moves the window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A local code that doesn't start with invalid_ is an application_error, as
the SDK spec's error names say. The code, message, why, fix and field are
unchanged, and the send still makes no request.

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

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