posthog icon indicating copy to clipboard operation
posthog copied to clipboard

Anomaly search: sort the most recent order by when the flagged bucket ended

Open andrewm4894 opened this issue 2 weeks ago • 2 comments

Part of #136343. Follows #138642, which #138705 closed.

Problem

The "most recent" order of anomaly search now sorts by how many buckets ago the newest flag was, counted back from the newest scored bucket of the same interval. The intent was to stop hourly series from filling the first page. It went too far the other way:

  • Every daily and weekly series that is flagged in its newest bucket ties at zero buckets ago.
  • A project with many daily and weekly series has more of these ties than the first pages hold.
  • An hourly series is rarely flagged in the single newest hour, so hourly rows sort behind all of them.

On a project that scores hourly, daily and weekly insights, the first 100 rows of the default view can hold no hourly series at all, although some were flagged a few hours ago. A person who opens the tab to see what just happened does not see it.

The same ties put weekly rows with one scored bucket in the range near the top. Those rows show one flagged bucket of one, which reads as noise. #138641 covers that part.

Proposal

Sort the recent order by when the newest flagged bucket ended, in wall-clock time, newest first.

  • The end of a bucket is its start plus one interval. Compare ends, not starts: a daily bucket that closed at midnight is nine hours old at 09:00, not 33.
  • Break ties as today (rate lift, flagged buckets, importance).
  • Change rank_series in products/signals/backend/anomaly_scores/read.py only. The tab, the MCP tools and the anomaly scout all read this order, so they change together.
  • Update the order help text on the search serializer, and regenerate the API types.

Known cost: this leans back towards hourly series, which is what #138642 set out to fix. That is acceptable. A list that leans hourly is better than one that hides hourly. Grouping series under one insight row and the anomaly rate filter in #138641 should reduce the lean.

Done when

  • On a project with hourly, daily and weekly flagged series, an hourly series flagged a few hours ago sorts above a daily series whose newest flagged bucket closed earlier.
  • A weekly series whose newest flagged bucket closed days ago does not sort above series flagged today.
  • The order is stable across pages.
  • A test covers a mix of the three intervals.

andrewm4894 avatar Nov 19 '26 17:11 andrewm4894

PostHog self-driving picked up this issue. Status: No further self-driving work is planned on this.

Somebody may already be working on it, so ask before you start a fix.

Report (team access only): https://us.posthog.com/project/2/inbox/reports/4743d377-3f70-4ac9-9cad-512b661e8a93?link_source=github_comment

posthog[bot] avatar Nov 19 '26 17:11 posthog[bot]

Hi @andrewm4894, I'd like to take this one.

Plan:

  • Change the "most recent" order of anomaly search to sort by when the newest flagged bucket ended (the bucket start plus the interval), newest first, instead of buckets-ago. A daily or weekly series flagged in its newest bucket then sorts by when that day or week ended, and an hourly series flagged a few hours ago comes before a daily bucket that ended yesterday.
  • Break ties by the anomaly score, then by insight id, so paging is stable.
  • Tests on a project with hourly, daily and weekly series: the first page holds recently flagged hourly rows, ties sort the same way on every page, and the other orders don't change.

Should a single-bucket weekly series keep its current place, since #138641 handles that separately?

rahulsjha avatar Nov 20 '26 11:11 rahulsjha