Skip to content

Select each user's new alerts for the daily digest - #1608

Draft
epompeii wants to merge 1 commit into
u/ep/digest/preffrom
u/ep/digest/select
Draft

epompeii wants to merge 1 commit into
u/ep/digest/preffrom
u/ep/digest/select

Conversation

@epompeii

@epompeii epompeii commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

The alert digest gets its selection: for a given moment, every user whose digest is due, the window of time it covers, and the new alerts it lists, grouped by project. This is a pure read. Nothing calls it yet; the email and the job that sends it come in the changes above. The selection is Bencher Plus only.

What changes

  • Who is due. A user is due when their digest is daily, they are not locked, and the end of their window has passed their mark (digest_through). Their send time is the latest moment at or before now when the clocks in their time zone strike their digest_hour. The window ends 1 hour before that send and starts at their mark. A user whose mark has already reached the end of the window is not due, which covers a user who signed up just before the hour. A mark 3 days old opens a 3 day window, so a server that was down at a user's hour sends the missed alerts at the next one.
  • The 1 hour grace. A report takes its time when its upload starts, and its alerts take the report's time. An upload still running at the send would date its alerts inside a window that already closed. Ending the window 1 hour before the send leaves room for that, and those alerts are in the next window.
  • The local clock. The send follows the user's zone through daylight saving. A send hour that the clocks skip sends when they resume, and a send hour that they repeat sends at its first pass. In a zone 30 minutes off UTC, the send hour starts on the half hour UTC: 09:00 in Asia/Kolkata is 03:30 UTC. A zone that skipped a whole date looks one more day back. The math is TimeZone::struck in bencher_valid.
  • Who gets which projects. Every member of an organization, through their organization role, gets every project of that organization in one digest. A deleted project, and every project of a deleted organization, is left out. A project with no members reaches nobody.
  • New alerts. An alert is new when it was created inside the window, [start, end), and is still active. An alert dismissed inside the window is not new. An alert created between the end of the window and the send is neither new nor outstanding; it is new in the next window.
  • Archived dimensions. An alert on an archived branch, testbed, or measure is neither listed nor counted, which matches the console's default alert list, so the counts match the page the link opens. An archived benchmark hides nothing, as in the console.
  • At most 8 per project. Each project lists at most 8 new alerts, worst first by how far past its limit each one landed, |value - limit| / |limit|, so alerts in different units compare. A limit of 0 is the worst. A tie goes to the older alert, then to the one written first. The rest are counted as "more".
  • Outstanding. A project with a new alert also carries a count of its active alerts created before the window. A project with no new alert carries none.
  • An empty day. A due user with no new alert is still returned, with no projects, so the job can move their mark without sending an email.
  • Query shape. The new alerts are a range over index_alert_project_created for each of the user's projects, and the outstanding count reads index_alert_project_status_modified. A guard in each query keeps SQLite on the right index, with a comment that says why. A user with no live project skips the alert query.
  • Each alert carries its project, benchmark, measure (with its units), branch, testbed, value, both limits, and the side of the limit it crossed, which is what the email prints.

Tests

lib/bencher_schema/src/model/user/digest.rs covers, on seeded fixtures: the two edges of the window; an alert dismissed inside the window; a user in two organizations, and none of an organization they do not belong to; a deleted project and a deleted organization; an unclaimed project; a user set to never and a locked user; a project past 8 alerts, ranked on both sides with a limit of 0 and ties, written out of order; the outstanding count only beside a new alert; archived dimensions; due users and their windows, including a user not yet due today and a 3 day window; and sends that follow the local clock across a skipped hour, a repeated hour, and a zone 30 minutes off UTC. bencher_valid tests a send across a date that a zone skipped whole.

This PR is the second of four for the alert digest. It sits on #1607, which adds the digest settings, and the stack sits on top of the changepoint layers (stack #1536). Next: #1609.

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.

1 participant