Skip to content

feat(messaging): add scheduled_at to email_status_events - #129915

Merged
trunk-io[bot] merged 5 commits into
masterfrom
scheduled-sends/n0-email-status-columns
Nov 12, 2026
Merged

trunk-io[bot] merged 5 commits into
masterfrom
scheduled-sends/n0-email-status-columns

Conversation

@Silthus

@Silthus Silthus commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Note

Just needs a stamp. Adds a scheduled_at column to email_status_events in ClickHouse. StampHog can't approve it: it's a ClickHouse migration.

Problem

Warning

Let this migration finish in US and EU before the stack that writes scheduled_at merges. An earlier row loses the time.

Changes

  • email_status_events gets a nullable scheduled_at. Nothing writes or reads it yet.
  • The Kafka table and its view are recreated, because a Kafka table's columns are fixed. The same consumer group resumes, so rows arrive late, not lost.
  • email_status is untouched. The rest is regenerated HCL and snapshots.

How did you test this code?

  • Ran the statements on a scratch pipeline while rows were sent: none lost (below).
  • Not run: the migration on dev or prod. CI's multinode smoke runs it.
  • The CI report's flaky Playwright test ("Delete a person property") and the red Cloud compose gate don't come from this PR. The gate fails on every HCL PR since feat(clickhouse): drop the unused metrics tables from the logs cluster #133190 dropped the metrics4 tables from the logs cluster.
Scratch pipeline run

Rows 1 and 2 went in before the migration, 3 after the view was dropped, 4 after the Kafka table was dropped, and 5 and 6 after the migration.

Row Status scheduled_at sent scheduled_at stored
1 queued none null
2 scheduled 2026-11-06 09:00 null (column did not exist yet)
3 queued none null
4 scheduled 2026-11-07 09:00 2026-11-07 09:00
5 scheduled 2026-11-08 09:00 2026-11-08 09:00
6 canceled none null

All six offsets landed once. The storage table's columns end sending_domain, scheduled_at, _timestamp, matching the golden.

Test rationale: no new test; test_schema.py snapshots the column.

Release status

  • No feature flag controls this change

Docs update

  • None.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Agent: Claude Code, Claude Opus 5.5

Skills: /clickhouse-migrations, /writing-pr-descriptions, /writing-tests, /writing-code-comments

More context for AI agents
  • Session: T3 Code stack thread for Silthus/personal#303 on a devbox; local ClickHouse and Redpanda, PostHog MCP read-only SQL.
  • Decisions: the column goes on email_status_events, not email_status, because that table already holds the recipient and its feed can change without pausing the status feed.
  • Decisions: nullable, so a row that was never scheduled reads as no time rather than 1970.
  • Follow-ups: the scheduled-send stack writes the column on scheduled and rescheduled rows, and the waiting-sends list reads it.
  • Read closely: the statement order in 0369_email_status_events_scheduled_at.py.

🤖 Generated with Claude Code

A scheduled send records the time it is due, so the list of waiting
sends can read it from ClickHouse instead of the job queue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silthus Silthus self-assigned this Nov 5, 2026
@trunk-io

trunk-io Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Trunk lane — backend Python lane

This PR is assigned to the backend Python lane. It runs backend Python tests and may merge in parallel with PRs in other lanes.

✅ Duplication (Python) — clean

New Python code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

✅ Duplication (TypeScript) — clean

New TypeScript code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

⚠️ Playwright — 1 flaky

🎭 Playwright report · View test results →

⚠️ 1 flaky test:

  • Delete a person property (chromium)

These issues are not necessarily caused by your changes.
Annoyed by this section? Help fix flakies and failures and it will go green!

ℹ️ ClickHouse migration SQL — 1 migration(s)

ClickHouse migration SQL per cloud environment

  • unset
    • all
      DROP TABLE IF EXISTS email_status_events_mv
      DROP TABLE IF EXISTS kafka_email_status_events
      ALTER TABLE email_status_events_data ADD COLUMN IF NOT EXISTS scheduled_at Nullable(DateTime64(6, 'UTC')) AFTER sending_domain
      ALTER TABLE email_status_events ADD COLUMN IF NOT EXISTS scheduled_at Nullable(DateTime64(6, 'UTC')) AFTER sending_domain
      CREATE TABLE IF NOT EXISTS kafka_email_status_events
      (
          team_id Int64,
          message_id UUID,
          status LowCardinality(String),
          version UInt64,
          created_at DateTime64(6, 'UTC'),
          status_at DateTime64(6, 'UTC'),
          reason String,
          recipient String,
          function_id String,
          sending_domain LowCardinality(String),
          scheduled_at Nullable(DateTime64(6, 'UTC'))
      )
      ENGINE = Kafka(warpstream_cyclotron, kafka_topic_list = 'clickhouse_email_status_test', kafka_group_name = 'clickhouse_email_status_events', kafka_format = 'JSONEachRow')
      SETTINGS kafka_skip_broken_messages = 100,
               kafka_num_consumers = 1,
               kafka_thread_per_consumer = 1,
               kafka_poll_timeout_ms = 10000,
               kafka_max_block_size = 100000
      CREATE MATERIALIZED VIEW IF NOT EXISTS email_status_events_mv
      TO email_status_events_data
      AS SELECT
          team_id,
          message_id,
          status,
          version,
          created_at,
          status_at,
          reason,
          recipient,
          function_id,
          sending_domain,
          scheduled_at,
          _timestamp,
          _offset,
          _partition
      FROM kafka_email_status_events
  • US, EU, DEV
    • aux
      DROP TABLE IF EXISTS email_status_events_mv
      DROP TABLE IF EXISTS kafka_email_status_events
      ALTER TABLE email_status_events_data ADD COLUMN IF NOT EXISTS scheduled_at Nullable(DateTime64(6, 'UTC')) AFTER sending_domain
      CREATE TABLE IF NOT EXISTS kafka_email_status_events
      (
          team_id Int64,
          message_id UUID,
          status LowCardinality(String),
          version UInt64,
          created_at DateTime64(6, 'UTC'),
          status_at DateTime64(6, 'UTC'),
          reason String,
          recipient String,
          function_id String,
          sending_domain LowCardinality(String),
          scheduled_at Nullable(DateTime64(6, 'UTC'))
      )
      ENGINE = Kafka(warpstream_cyclotron, kafka_topic_list = 'clickhouse_email_status_test', kafka_group_name = 'clickhouse_email_status_events', kafka_format = 'JSONEachRow')
      SETTINGS kafka_skip_broken_messages = 100,
               kafka_num_consumers = 1,
               kafka_thread_per_consumer = 1,
               kafka_poll_timeout_ms = 10000,
               kafka_max_block_size = 100000
      CREATE MATERIALIZED VIEW IF NOT EXISTS email_status_events_mv
      TO email_status_events_data
      AS SELECT
          team_id,
          message_id,
          status,
          version,
          created_at,
          status_at,
          reason,
          recipient,
          function_id,
          sending_domain,
          scheduled_at,
          _timestamp,
          _offset,
          _partition
      FROM kafka_email_status_events
    • aux, data
      ALTER TABLE email_status_events ADD COLUMN IF NOT EXISTS scheduled_at Nullable(DateTime64(6, 'UTC')) AFTER sending_domain

@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 9280063: no findings.

Master took ClickHouse migrations 0369 to 0374, so the email_status_events
scheduled_at migration moves to 0375 and max_migration.txt follows it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silthus
Silthus marked this pull request as ready for review November 10, 2026 08:26
@Silthus
Silthus requested a review from a team as a code owner November 10, 2026 08:26
@parameterai

parameterai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Risk: No findings

The change since the last review is a merge of master: the email_status_events migration was renumbered 0376→0380 (byte-identical), max_migration.txt updated with no numbering collision (master owns 0375–0379), and the HCL layers/goldens/snapshots were regenerated. All PR-owned email_status_events scheduled_at definitions survived the regeneration consistently across every environment; the remaining hunks are master's own channel_type/metrics4/query-log changes passing through the merge. No security-relevant surface in the PR-authored delta.

Sentinel reviewed 0677612 · Review settings

@stamphog
stamphog Bot requested a review from a team November 10, 2026 08:26
@veria-ai

veria-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

Renumber the email status scheduled_at ClickHouse migration to 0376, after master's 0375_person_group_membership_activity.
@Silthus
Silthus requested a review from meikelmosby November 11, 2026 18:53
Renumber the email_status_events scheduled_at migration to 0380.

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

Silthus commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

/trunk merge

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not approved yet — waiting on the conditions below.

Re-add the stamphog label to request another review once you have addressed this.

StampHog refused this pull request at two gates. The deny-list gate flagged it for matching migrations, because it adds posthog/clickhouse/migrations/0380_email_status_events_scheduled_at.py and bumps max_migration.txt. The tier gate classified it as T2-never (202 lines, 26 files, two areas, feat), so it can't be handled automatically however small the column change is.

The size and prerequisites gates passed, so size isn't the issue and splitting wouldn't clear the refusal. The author should ask a human reviewer, preferably someone familiar with ClickHouse migrations, to review it. The migration's statement order and the Kafka table recreation are what that reviewer should read most closely.

Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✗ matches: migrations
size ✓ 184L, 24F substantive, 202L/26F incl. docs/generated/snapshots — within ceiling
tier ✗ classified as T2-never: T2-never (202L, 26F, two-areas, feat)
stamphog 2.8.0 .stamphog/policy.yml @ unknown · reviewed head 0677612

@trunk-io
trunk-io Bot merged commit b49c1c4 into master Nov 12, 2026
281 of 282 checks passed
@trunk-io
trunk-io Bot deleted the scheduled-sends/n0-email-status-columns branch November 12, 2026 11:51
@deployment-status-posthog

deployment-status-posthog Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-11-12 12:18 UTC Run
prod-us ✅ Deployed 2026-11-12 12:37 UTC Run
prod-eu ✅ Deployed 2026-11-12 12:40 UTC Run

This table shows the posthog release only. Hogstation shows every service that this PR reaches, Kargo services included.

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.

3 participants