Repository navigation
Conversation
send() takes scheduled_at, an aware datetime or an ISO 8601 string with an offset, and refuses a naive datetime before any request. Emails and AsyncEmails gain update(), cancel() and list(). Cancel and update retry like a send; list never retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p parser Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
posthog-python Compliance ReportDate: 2026-11-13T13:27:57.608446+00:00 ✅ All Tests Passed!270/270 tests passed Capture_V1 Tests✅ 95/95 tests passed View Details
Capture_Ai Tests✅ 5/5 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
Feature_Flags_V4 Tests✅ 149/149 tests passed View Details
Feature_Flags_Local_Evaluation Tests✅ 4/4 tests passed View Details
|
SDK performance: posthog-pythonBenchmarks 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 |
…onflicts - A scheduled send that a PostHog without scheduled sends answers with no status now carries the scheduling_unsupported warning, as posthog-node does, so the caller sees the email went out now. - list() raises api_error when a page's next cursor is missing or not a nonempty string, instead of ending a paging loop early. - cancel() raises api_error unless PostHog answers status canceled. - A 409 already_sending or canceled is named validation_error, like template_outdated, as posthog-node names it: a retry can't resolve it. - list() takes only status="scheduled", typed Literal["scheduled"]. - update() documents that a lost answer to a move to now can retry into already_sending. Drop the unused cancel path constant and typing.List. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orted Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #1216 (tracking and sensitive on a code send). The conflicts were additions on both sides: the optional code fields, the strict type smoke lines, and the test imports. All are kept. 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>
There was a problem hiding this comment.
Not approved — this change needs a human reviewer.
Re-adding the stamphog label gives the same result unless the changed files change.
stamphog can't auto-approve this pull request, and the refusal is final. Two gates refused it. The deny-list gate matched public_api, because references/public_api_snapshot.txt changes and posthog/emails.py adds new public methods and result types (update, cancel, list, and the scheduled_at keyword). The tier gate classified it as T2-never: a cross-cutting feature of 1096 lines across 5 files.
The size gate passed, so splitting the PR won't clear the deny-list match. The next step is to ask a human reviewer, preferably an owner of the SDK's public API, to review it.
- posthog[bot] reviewed the current head.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✗ | matches: public_api |
| size | ✓ | 534L, 2F substantive, 1096L/5F incl. docs/generated/snapshots — within ceiling |
| tier | ✗ | classified as T2-never: T2-never (1096L, 5F, cross-cutting, feat) |
| stamphog 2.8.0 | .stamphog/policy.yml @ unknown · reviewed head afa81b7 |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esults raise Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ports update, cancel and list onto main's request code from #1172: replies are parsed from the raw body, and each call goes through _posthog_request. Keeps both sides' send fields, tests and strict-type checks; the regenerated public API snapshot carries both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A move whose request got no answer, such as on a timeout or a cancellation, may still reach PostHog after a newer move and undo it. The client now sends the moves of one email one at a time, and after an unanswered move it refuses to move that email to another time with move_unconfirmed, without a request. A move to the same time still goes out. Matches posthog-node's fix for the same ordering problem. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tant A gateway timeout or other server error is an answer that confirms nothing: the move may still run upstream and land after a newer one, so it now blocks a later move to another time like a lost answer does. 4xx answers still don't. Moves now compare by their instant in UTC, so the same time written as a string or a datetime goes out instead of raising move_unconfirmed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irmed A late move can't undo a confirmed cancel, since PostHog answers it 409 canceled, so the client drops that email's entry instead of keeping it for its lifetime. The next move goes out and reads canceled. A failed cancel keeps the entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…send # Conflicts: # posthog/emails.py # posthog/test/test_emails.py
D5 c1a6dd3 leaves `to` out of the scheduled email list, since a key that can only read statuses could read who a project is about to email. The client raised api_error on every such row, so ScheduledEmail drops `to` and a row needs only its id and times. Callers match a row to its send by id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A move queued behind one still out when a cancel was confirmed was refused locally once the first move timed out, though PostHog would answer it 409 canceled. Moves of an email whose cancel was confirmed while they were out or queued now leave no record, since none can undo the cancel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uling work to main The v7 spec cuts this PR down to scheduled_at on send. The next commits rebuild that scope test-first on main's key-scoped email routes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spec v7 scope only: scheduled_at on emails.send, both forms, sync and async. A naive datetime or a string without an offset raises before any request, and so does a client whose app host isn't PostHog Cloud. The time is rounded up to the millisecond once and sent on every retry. A 202 for a scheduled request must confirm the requested instant with status scheduled, or answer scheduled_at null with status queued; anything else raises schedule_not_confirmed with the email's message_id. No fallback to sending now, no move, cancel or list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeQL reads a URL substring check as URL sanitization. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ents The Raises line now says schedule_not_confirmed means PostHog queued the email, so a retry on EmailError can't read it as nothing sent. The reason for refusing scheduled_at off Cloud moves into the error's why. Tests of the scheduling path assert on the requests the transport received, one behaviour each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_prepare reads the time once and each form adds its wire value. A string time goes through the module's _timestamp instead of a second ISO parser. The rounded time is rebuilt as a plain UTC datetime, so a datetime subclass such as a pandas Timestamp compares as the instant on the wire. SendEmailResult.status is now derived from scheduled_at. An unconfirmed schedule's fix no longer suggests a resend that a fresh key would turn into a second email. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A 202 that answers `queued` with no `scheduled_at`, missing or null, for a time more than 60 seconds ahead of the client's clock raises `schedule_not_confirmed` with the message ID instead of reporting the email as sent. Within 60 seconds, or for a past time, it goes out now. - Refuse a `scheduled_at` whose offset has minutes or seconds past 59, such as "+01:60", before any request: fromisoformat would carry it into the next hour and send the email at another time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A 202 without the scheduled_at key raises schedule_not_confirmed again, however near the requested time, as the spec says. Only queued with a null time is accepted, and only within 60 seconds. - Read scheduled_at only with Z or a +HH:MM offset in range, and read the seconds fraction in the client: digits past microseconds round up, and a short fraction such as .1Z reads the same on Python 3.10. - A time past the latest datetime raises ValueError, not OverflowError. - Install the test transport at the Requests boundary in the host tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Status reads go back to main's parser. scheduled_at strings now need a date, a T or a space, a time and Z or a +HH:MM offset, read the same way on every supported Python, and a time's nanoseconds round it up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The echoed scheduled_at now goes through the same pattern as the requested time, so an out-of-range offset can't confirm a schedule and every supported Python reads a short fraction the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Google's DatetimeWithNanoseconds keeps the whole fraction in nanosecond, so an exact millisecond went out a millisecond late. Only the part below a microsecond rounds the time up now, as for a pandas Timestamp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A send-now answer for a scheduled_at was measured against the clock when the answer arrived, so a slow answer or a retry widened the window. It now counts from the send's first attempt, as the other SDKs do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A local code that doesn't start with invalid_ is an application_error in the cross-SDK error names. The code, message, why, fix and field stay the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
💡 Motivation and Context
A send from code can now wait up to 7 days before it goes out:
emails.send(..., scheduled_at=...). PostHog Cloud already parks a scheduled send like a workflow delay step and answersstatusandscheduled_aton the 202 (behindworkflows-email-scheduled-sends). This adds the public field to the Python SDK, and nothing more.This PR was first written as schedule, move, cancel and list. It is now cut down to the agreed v1 scope:
scheduled_aton send only, with the oldscheduling_unsupportedfallback removed. Cancel, move and list come in a follow-up.Impact
Scheduled sends close a gap for teams moving from Resend, where call sites schedule with
scheduledAt. The usage bar: a quarter of code-sending orgs schedule at least once within 60 days of GA, read from thescheduledproperty on thetransactional email api sendevent. The SDK carries no flag of its own; the server flag decides who can schedule.What changes
scheduled_atonEmails.sendandAsyncEmails.send, both forms (template and code). It takes an awaredatetimeor an ISO 8601 string: a date, aTor a space, a time, andZor a±HH:MMoffset.Nonecounts as left out.datetime, or a string in any other shape, raisesValueErrorbefore any request: no offset, an offset out of range such as+01:60(which Python'sfromisoformatwould carry into the next hour), the basic format20261201T090000Z, any other separator, and a time past the latestdatetime.scheduling_requires_cloudbefore any request, naming the host. A self-hosted PostHog from before scheduled sends would drop the field and send at once, which no answer check could undo.Timestampor Google'sDatetimeWithNanoseconds, round up too.emails.getkeeps main's time parser. Tests cover microseconds, nanoseconds, a carry into the next day, non-UTC offsets and adatetimesubclass such as a pandasTimestamp.status: scheduled, or answerscheduled_at: nullwithstatus: queuedfor a time at most 60 seconds ahead of the client's clock at the send's first attempt (the time had passed, so it goes out now). A slow answer or a retry doesn't widen that window, as in every PostHog SDK. Anything else raisesschedule_not_confirmed, with the email's id on the newEmailError.message_id, including a 202 without thescheduled_atkey and a send-now answer for a time further ahead.scheduled_atsurfaces as an error. There is no fallback to sending now.SendEmailResultgainsscheduled_atand a derivedstatusproperty ("queued"or"scheduled", typed as aLiteral). A send withoutscheduled_atkeeps today's result, withstatusreading"queued".EmailStatusdocumentsscheduled.No cross-SDK spec in PostHog/sdk-specs covers scheduling yet; the error codes and the 60-second rule are the ones every PostHog SDK uses. The Python API still owes its API review: the names
scheduling_requires_cloud,schedule_not_confirmed,EmailError.message_id,SendEmailResult.statusandSendEmailResult.scheduled_atare open to it, and posthog-node should match them.Warning
🟡 Merge risk: medium · one-way door once released: the public names
scheduled_at,SendEmailResult.status,SendEmailResult.scheduled_at,EmailError.message_id,schedule_not_confirmedandscheduling_requires_cloudscheduled_atis a new optional argument, and the server flagworkflows-email-scheduled-sendsgates scheduling on PostHog's side. Once a maintainer approves the release,posthogandposthoganalyticson PyPI fix the names above, so the Python API review comes first.scheduled_atkeeps its request bytes and result values; the existing send tests cover it, and a result now also readsstatus == "queued"andscheduled_at=None.schedule_not_confirmed(Known issues).workflows-email-scheduled-sends, which answers 400 toscheduled_atwhile off. None in the SDK: fix forward.sendwithoutscheduled_atstatus="queued"sendwithscheduled_aton CloudTypeError: unknown argumentscheduled_at, checks the answersendwithscheduled_atoff CloudTypeErrorscheduling_requires_cloudbefore any requestsendwith a pastscheduled_aton CloudTypeErrorqueuedwithscheduled_at: nullas sent now; covered by unit tests, not run on real CloudTypeErrorschedule_not_confirmedwith the message ID instead of reporting the email as sent; unit tests onlysendwithscheduled_aton Cloud EUTypeErrorTypeErrorschedule_not_confirmedafter PostHog accepted the email; a caller who resends without the sameidempotency_keysends a second email, so the error's fix says to reademails.getfirstRollout
schedule_not_confirmedreports and scheduled emails whosestatus_atprecedes theirscheduled_atin the server's email status rows.💚 How did you test it?
Unit tests in
posthog/test/test_emails.pythrough a fakerequestsadapter andhttpx.MockTransport, the seams the existing send tests use: the wire value per input form, refusals before any request, the Cloud-host check (standalone and throughPosthog(app_host=...)), retries sending the same bytes and key, each answer shape the check accepts or refuses, a refusedscheduled_atwithout fallback, and the async client. Locally:ruff format --check,ruff check, mypy with the baseline, the full pytest suite,make public_api_checkand.github/scripts/check_strict_types.shpass.Live run on PostHog Cloud US at f6a2e6b, the head (the SDK release gate): a send scheduled about 5 minutes ahead went out as
.124Zfor a.123456time, PostHog confirmed the same instant, a same-key resend returned the same email withreplayed: true,emails.getreadscheduledand thendelivered0.91 s after the requested time, and the mailbox holds exactly one email. Earlier runs at ebd9ce9 and 6b3b639 showed the same. Not run live: a past time, a send-now answer, and the EU region.Known issues
schedule_not_confirmed. The error carries the message ID and says to reademails.getbefore sending again, so no email goes out twice.Server behavior seen in the live runs on PostHog Cloud, not SDK bugs; the SDK reports what PostHog answers:
emails.getright after a scheduled send can answer 404not_foundfor a few seconds, because PostHog writes the status row asynchronously; a later read returnsscheduled.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Opus 5.5) cut the earlier schedule, move, cancel and list work down to
scheduled_aton send: it mergedmain, reset the scheduling files tomain's key-scoped routes, and rebuilt the scope test-first. Reviews run through a cross-family panel.scheduled_aton send only; move, cancel and list wait for a follow-up; noscheduling_unsupportedfallbackschedule_not_confirmedwithmessage_id, not retried. Rejected: returning a result with a warningstatusis derived fromscheduled_at, so the two can't disagree. Rejected: two stored fieldsscheduled_atstrings and PostHog's echo of them get their own strict pattern, thenfromisoformaton the rebuilt time, so every supported Python reads them the same; status reads keep main's_timestamp. Rejected: one parser shared withemails.get, which changed how status times read🤖 Generated with Claude Code
How did you test this code?
Merge card: medium, one-way door · 12 rounds, 9 final reads · gaps: prod-shape (🤖 agent d-fa7906d2) · 2 known issues · 14800 min opened to ready
eacf325(reused fromf6a2e6b)eacf325(reused frome94fc42)eacf325(reused frome94fc42)ef74081toeacf325eacf325Not checked: none recorded
Full receipt: https://artifacts.posthog.com/a/KuQKAGAW0JVHfC8JTpWvLS