:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(today): keep frecency pulse ranking and remove the ranking flag (#126174)
Shy Alterb7b7f173997a
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 4fbb21481efa..cdbbcc37ab83 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -546,7 +546,6 @@ export const FEATURE_FLAGS = {TAXONOMIC_FILTER_VALUE_SEARCH_GATING: 'taxonomic-filter-value-search-gating', // owner: @pauldambraTEXT_CARD_WORD_ART: 'text-card-word-art', // owner: @jonmcwest, gates the word art insert button in dashboard text cardsTODAY_JUMP_BACK_RANKING: 'today-jump-back-ranking',- TODAY_PULSE_RANKING: 'today-pulse-ranking',TODAY_RAIL_NAV: 'today-rail-nav', // owner: @k11kirky, replaces the left navigation with a rail (Home, Spaces, Library, Tools) and makes the Today page the homepageTODAY_REPORT_JEV: 'today-report-jev', // owner: @puemos, asks the decision model to label the problem, cause and fix in a Today report, to mark the numbers a source states, and to pick the code excerpt a finding describesTOOLBAR_PAID_HEATMAPS: 'toolbar-paid-heatmaps', // owner: #team-web-analyticsdiff --git a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.tsindex 4ad000d16a61..3123b30513fe 100644--- a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts+++ b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts@@ -31,9 +31,8 @@ describe('todayHighlightsLogic', () => {jest.restoreAllMocks()})- it('records which pulse metric was opened, why it was shown and the ranking variant', async () => {+ it('records which pulse metric was opened and why it was shown', async () => {const capture = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined)- jest.spyOn(posthog, 'getFeatureFlag').mockReturnValue('frecency')const logic = todayHighlightsLogic()logic.mount()@@ -43,7 +42,6 @@ describe('todayHighlightsLogic', () => {kind: 'insight',reason: 'dashboard',position: 2,- pulse_ranking: 'frecency',})})diff --git a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.tsindex cb90b0113876..30c62ac3f51a 100644--- a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts+++ b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts@@ -6,7 +6,6 @@ import { v4 as uuidv4 } from 'uuid'import { toast } from '@posthog/quill'import { ApiError } from 'lib/api'-import { FEATURE_FLAGS } from 'lib/constants'import { teamLogic } from 'scenes/teamLogic'import { todayHighlightsRetrieve } from 'products/today/frontend/generated/api'@@ -504,7 +503,6 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([kind: pulseKind(metric.key),reason: metric.reason,position,- pulse_ranking: posthog.getFeatureFlag(FEATURE_FLAGS.TODAY_PULSE_RANKING) ?? null,})toast.success({title: 'Hidden from Today',@@ -559,7 +557,6 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([kind: pulseKind(metric.key),reason: metric.reason,position,- pulse_ranking: posthog.getFeatureFlag(FEATURE_FLAGS.TODAY_PULSE_RANKING) ?? null,})},pulseMetricPreviewed: ({ metric, position }) => {@@ -572,7 +569,6 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([kind: pulseKind(metric.key),reason: metric.reason,position,- pulse_ranking: posthog.getFeatureFlag(FEATURE_FLAGS.TODAY_PULSE_RANKING) ?? null,})},loadHighlightsSuccess: ({ highlights }) => {@@ -605,7 +601,6 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([pulse_count: values.pulseTiles.length,pulse_candidate_count: highlights.pulse.length,pulse_reasons: values.pulseTiles.map((metric) => metric.reason),- pulse_ranking: posthog.getFeatureFlag(FEATURE_FLAGS.TODAY_PULSE_RANKING) ?? null,})},})),diff --git a/products/today/backend/feature_flags.py b/products/today/backend/feature_flags.pyindex 2e5791bf0c6b..8c42891718ce 100644--- a/products/today/backend/feature_flags.py+++ b/products/today/backend/feature_flags.py@@ -3,16 +3,12 @@import structlogfrom posthog.models import Team, User-from posthog.ph_client import feature_enabled_or_false, get_feature_flag_or_none+from posthog.ph_client import feature_enabled_or_falselogger = structlog.get_logger(__name__)TODAY_RAIL_NAV_FLAG = "today-rail-nav"TODAY_REPORT_JEV_FLAG = "today-report-jev"-TODAY_PULSE_RANKING_FLAG = "today-pulse-ranking"-FRECENCY_RANKING = "frecency"-RECENCY_RANKING = "recency"-CONTROL_RANKING = "control"def is_enabled_for(user: User, team: Team) -> bool:@@ -45,18 +41,6 @@ def _flag_on(flag: str, user: User, team: Team) -> bool:return False-def pulse_ranking(user: User, team: Team) -> str:- variant = get_feature_flag_or_none(- TODAY_PULSE_RANKING_FLAG,- str(user.distinct_id),- groups=_groups(team),- group_properties=_group_properties(team),- person_properties={"email": user.email},- send_feature_flag_events=False,- )- return variant if variant in (FRECENCY_RANKING, RECENCY_RANKING) else CONTROL_RANKING--def may_ask_jev(user: User, team: Team) -> bool:"""Jev calls are not billed as AI credits, so they skip the organization's credit limit."""return _may_send_to_ai(user, team) and all(diff --git a/products/today/backend/logic/highlights.py b/products/today/backend/logic/highlights.pyindex 7fe9a56cc47b..7bfb8734a2d3 100644--- a/products/today/backend/logic/highlights.py+++ b/products/today/backend/logic/highlights.py@@ -32,7 +32,6 @@ from ..facade.enums import (HighlightPriority,HighlightsStatus,)-from ..feature_flags import pulse_rankingfrom ..models import TodayHighlightsfrom ..temporal.inputs import (HIGHLIGHTS_WORKFLOW_NAME,@@ -95,7 +94,7 @@ def get_highlights(*, team: Team, user: User, scopes: frozenset[str] | None) ->def _key(team: Team, user: User, scopes: frozenset[str] | None) -> str:granted = "session" if scopes is None else ",".join(sorted(scopes))restrictions = property_restrictions(team, user)- return hashlib.sha256(f"{granted}:{restrictions}:{pulse_ranking(user, team)}".encode()).hexdigest()[:32]+ return hashlib.sha256(f"{granted}:{restrictions}".encode()).hexdigest()[:32]def _is_due(row: TodayHighlights, now: datetime) -> bool:diff --git a/products/today/backend/logic/today_highlights/routine.py b/products/today/backend/logic/today_highlights/routine.pyindex 9545e41133d6..a82af7ebdd53 100644--- a/products/today/backend/logic/today_highlights/routine.py+++ b/products/today/backend/logic/today_highlights/routine.py@@ -21,20 +21,11 @@ from products.product_analytics.backend.facade.contracts import InsightDashboardfrom ...facade import contractsfrom ...facade.enums import HighlightInterval, HighlightMetricReason, HighlightUnit-from ...feature_flags import FRECENCY_RANKING, RECENCY_RANKING, pulse_rankingfrom ..highlight_rules import shortfrom ..highlight_series import pretty, usable_seriesfrom ..highlight_trends import complete, detectfrom ..highlight_types import Context, Found, Source-ROUTINE_WINDOW_DAYS = 28-DAILY_ROUTINE_DAYS = 8-WARMUP_ROUTINE_DAYS = 2-WARMUP_HISTORY_DAYS = 14-VIEW_DAYS_RECORDED_SINCE = date(2026, 10, 16)-WEEKLY_ROUTINE_WEEKS = 3-ROUTINE_CANDIDATES = 6-ROUTINE_TILES = 2FRECENCY_HALF_LIFE_DAYS = 14FRECENCY_LOOKBACK_DAYS = VIEW_DAYS_KEPTFRECENCY_CANDIDATES = 8@@ -57,54 +48,7 @@ class ViewedItem:def find(context: Context) -> Found:pinned = context.pinned- budget = PULSE_CANDIDATES - len(pinned)- ranking = pulse_ranking(context.user, context.team)- if ranking in (FRECENCY_RANKING, RECENCY_RANKING):- return Found(pulse=tuple(_frecent_metrics(context, ranking, pinned, budget)))- metrics: list[contracts.HighlightMetric] = []- for item in _routine_insights(context):- if len(metrics) >= min(ROUTINE_TILES, budget):- break- if f"insight:{item.ref}" in pinned:- continue- metric = context.guard(f"routine {item.ref}", partial(insight_metric, context, item.ref, viewed=item), None)- if metric is not None:- metrics.append(metric)- return Found(pulse=tuple(metrics))---def routine_days(view_days: Sequence[date], today: date, warming_up: bool = False) -> int:- recent = {day for day in view_days if today - timedelta(days=ROUTINE_WINDOW_DAYS) < day <= today}- needed = WARMUP_ROUTINE_DAYS if warming_up else DAILY_ROUTINE_DAYS- daily = sum(1 for day in recent if day > today - timedelta(days=14)) >= needed- weekly = len({day.isocalendar()[:2] for day in recent}) >= WEEKLY_ROUTINE_WEEKS- return len(recent) if daily or weekly else 0---def is_warming_up(today: date) -> bool:- """Whether view days have been recorded for too short a time for the daily rule."""- return (today - VIEW_DAYS_RECORDED_SINCE).days < WARMUP_HISTORY_DAYS---def _routine_insights(context: Context) -> list[ViewedItem]:- views = FileSystemViewLog.objects.filter(- team=context.team,- user=context.user,- type="insight",- viewed_at__gte=timezone.now() - timedelta(days=ROUTINE_WINDOW_DAYS),- ).values_list("ref", "view_days", "viewed_at")- warming_up = is_warming_up(context.today)- ranked = sorted(- (- (routine_days(days or [], context.today, warming_up), viewed_at, ref, frozenset(days or []))- for ref, days, viewed_at in views- ),- key=lambda row: row[:3],- reverse=True,- )- return [ViewedItem(kind="insight", ref=ref, days=view_days) for days, _at, ref, view_days in ranked if days][- :ROUTINE_CANDIDATES- ]+ return Found(pulse=tuple(_frecent_metrics(context, pinned, PULSE_CANDIDATES - len(pinned))))def frecency(view_days: Collection[date], today: date) -> float:@@ -112,15 +56,13 @@ def frecency(view_days: Collection[date], today: date) -> float:return sum(0.5 ** (age / FRECENCY_HALF_LIFE_DAYS) for age in ages if 0 <= age <= FRECENCY_LOOKBACK_DAYS)-def _frecent_metrics(- context: Context, ranking: str, excluded: Collection[str], budget: int-) -> list[contracts.HighlightMetric]:+def _frecent_metrics(context: Context, excluded: Collection[str], budget: int) -> list[contracts.HighlightMetric]:if budget <= 0:return []deadline = monotonic() + BLOCKING_SECONDScandidates: list[tuple[ViewedItem, contracts.HighlightMetric | None]] = []available: set[str] = set()- for item in _candidates(context, _frecent_views(context, ranking)[:FRECENCY_CANDIDATES]):+ for item in _candidates(context, _frecent_views(context)[:FRECENCY_CANDIDATES]):shown = frozenset([*excluded, *available])metric = context.guard(f"frecent {item.kind} {item.ref}",@@ -157,7 +99,7 @@ def _candidates(context: Context, own: list[ViewedItem]) -> Iterator[ViewedItem]yield ViewedItem(kind="insight", ref=ref, days=frozenset(), popular=True)-def _frecent_views(context: Context, ranking: str) -> list[ViewedItem]:+def _frecent_views(context: Context) -> list[ViewedItem]:views = FileSystemViewLog.objects.filter(team=context.team,user=context.user,@@ -170,10 +112,7 @@ def _frecent_views(context: Context, ranking: str) -> list[ViewedItem]:for kind, ref, days, viewed_at in views]scored = [(frecency(item.days, context.today), max(item.days), item) for item in items]- if ranking == RECENCY_RANKING:- scored.sort(key=lambda row: (row[1], row[0]), reverse=True)- else:- scored.sort(key=lambda row: row[:2], reverse=True)+ scored.sort(key=lambda row: row[:2], reverse=True)return [item for score, _last, item in scored if score > 0]diff --git a/products/today/backend/tests/test_highlight_insights.py b/products/today/backend/tests/test_highlight_insights.pyindex 1e48d152ca29..1460fe294bf2 100644--- a/products/today/backend/tests/test_highlight_insights.py+++ b/products/today/backend/tests/test_highlight_insights.py@@ -37,30 +37,6 @@ def insight(series: dict[str, list[tuple[date, float]]], **fields: Any) -> Insigclass TestInsightRules(SimpleTestCase):- @parameterized.expand(- [- ("opened on most days", [TODAY - timedelta(days=d) for d in range(10)], False, 10),- ("opened every Monday", [TODAY - timedelta(days=1 + 7 * w) for w in range(4)], False, 4),- ("opened on many days of one week", [TODAY - timedelta(days=d) for d in range(5)], False, 0),- ("a habit that stopped a month ago", [TODAY - timedelta(days=30 + 7 * w) for w in range(4)], False, 0),- ("opened on two days while history is short", [TODAY, TODAY - timedelta(days=3)], True, 2),- ("opened on one day while history is short", [TODAY], True, 0),- ]- )- def test_routine_days(self, _name: str, view_days: list[date], warming_up: bool, expected: int) -> None:- self.assertEqual(routine.routine_days(view_days, TODAY, warming_up), expected)-- @parameterized.expand(- [- ("the day recording started", date(2026, 10, 16), True),- ("the last warm-up day", date(2026, 10, 29), True),- ("two weeks after recording started", date(2026, 10, 30), False),- ("months later", date(2027, 3, 1), False),- ]- )- def test_is_warming_up(self, _name: str, today: date, expected: bool) -> None:- self.assertEqual(routine.is_warming_up(today), expected)-@parameterized.expand([("opened today", [TODAY], 1.0),@@ -329,7 +305,7 @@ class TestRoutineInsights(BaseTest):])@time_machine.travel("2026-10-13T12:00:00Z", tick=False)- def test_the_frecency_ranking_shows_a_dashboard_opened_often_as_its_first_working_tile(+ def test_the_pulse_shows_a_dashboard_opened_often_as_its_first_working_tile(self, _name: str, scopes: frozenset[str] | None, expected: list[tuple[str, str, str | None, int, date]]) -> None:for kind, ref, ages in (("insight", "old", (20,)), ("dashboard", "7", (1, 2))):@@ -364,7 +340,6 @@ class TestRoutineInsights(BaseTest):return charts.get(kwargs["short_id"])with (- patch.object(routine, "pulse_ranking", return_value="frecency"),patch.object(routine, "dashboard_insights", return_value=growth),patch.object(routine, "get_insight_series", side_effect=series),):@@ -373,16 +348,8 @@ class TestRoutineInsights(BaseTest):self.assertEqual([(m.key, m.url, m.dashboard_name, m.opened_days, m.last_opened) for m in pulse], expected)self.assertEqual([m.movers for m in pulse], [[]] * len(expected))- @parameterized.expand(- [- ("frecency puts the habit first", "frecency", ["insight:habit", "insight:fresh"]),- ("recency puts the latest open first", "recency", ["insight:fresh", "insight:habit"]),- ]- )@time_machine.travel("2026-10-13T12:00:00Z", tick=False)- def test_each_new_ranking_orders_the_same_views_its_own_way(- self, _name: str, ranking: str, expected: list[str]- ) -> None:+ def test_a_habit_ranks_above_a_more_recent_single_open(self) -> None:for ref, ages in (("habit", range(2, 10)), ("fresh", (1,))):FileSystemViewLog.objects.create(team=self.team,@@ -394,17 +361,14 @@ class TestRoutineInsights(BaseTest):)points = [(TODAY - timedelta(days=d), 2.0 if d <= 7 else 1.0) for d in range(14, 0, -1)]- with (- patch.object(routine, "pulse_ranking", return_value=ranking),- patch.object(- routine,- "get_insight_series",- side_effect=lambda **kwargs: insight({"opened": points}, short_id=kwargs["short_id"], name="Opened"),- ),+ with patch.object(+ routine,+ "get_insight_series",+ side_effect=lambda **kwargs: insight({"opened": points}, short_id=kwargs["short_id"], name="Opened"),):pulse = routine.find(Context(self.team, self.user, TODAY)).pulse- self.assertEqual([m.key for m in pulse], expected)+ self.assertEqual([m.key for m in pulse], ["insight:habit", "insight:fresh"])@parameterized.expand([@@ -455,7 +419,6 @@ class TestRoutineInsights(BaseTest):return insight({"opened": points}, short_id=ref, name=ref)with (- patch.object(routine, "pulse_ranking", return_value="recency"),patch.object(routine, "dashboard_insights", return_value=growth),patch.object(routine, "get_insight_series", side_effect=series),patch.object(routine, "monotonic", side_effect=lambda: clock[0]),@@ -491,13 +454,10 @@ class TestRoutineInsights(BaseTest):)points = [(TODAY - timedelta(days=d), 2.0 if d <= 7 else 1.0) for d in range(14, 0, -1)]- with (- patch.object(routine, "pulse_ranking", return_value="recency"),- patch.object(- routine,- "get_insight_series",- side_effect=lambda **kwargs: insight({"opened": points}, short_id=kwargs["short_id"], name="Opened"),- ),+ with patch.object(+ routine,+ "get_insight_series",+ side_effect=lambda **kwargs: insight({"opened": points}, short_id=kwargs["short_id"], name="Opened"),):pulse = routine.find(Context(self.team, self.user, TODAY)).pulsediff --git a/products/today/backend/tests/test_highlights.py b/products/today/backend/tests/test_highlights.pyindex f6fece3544f1..2f5f5296d20c 100644--- a/products/today/backend/tests/test_highlights.py+++ b/products/today/backend/tests/test_highlights.py@@ -378,14 +378,6 @@ class TestGetHighlights(BaseTest):1,[],),- (- "a ready row for the other pulse ranking",- {"status": HighlightsStatus.READY, "ready_at": timedelta(minutes=1)},- HighlightsStatus.COMPUTING,- 1,- [],- "frecency",- ),])def test_the_request_never_waits_for_a_computation(@@ -395,15 +387,10 @@ class TestGetHighlights(BaseTest):status: HighlightsStatus,starts: int,pulse: list[str],- ranking_later: str = "control",) -> None:connect = MagicMock()connect.return_value.start_workflow = AsyncMock()- ranking = ["control"]- with (- patch.object(highlights, "sync_connect", connect),- patch.object(highlights, "pulse_ranking", side_effect=lambda _user, _team: ranking[0]),- ):+ with patch.object(highlights, "sync_connect", connect):if row is not None:highlights.get_highlights(team=self.team, user=self.user, scopes=None)now = timezone.now()@@ -413,7 +400,6 @@ class TestGetHighlights(BaseTest):)connect.return_value.start_workflow.reset_mock()cache.clear()- ranking[0] = ranking_laterfound = highlights.get_highlights(team=self.team, user=self.user, scopes=None)self.assertEqual(