Skip to content

: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.

fix(home): align report ranking with inbox (#124665)

Shy Altera9b54413f913
diff --git a/frontend/src/scenes/project-homepage/today/todayForYouRows.test.ts b/frontend/src/scenes/project-homepage/today/todayForYouRows.test.ts
index 483c92a4e71a..0de281141cca 100644
--- a/frontend/src/scenes/project-homepage/today/todayForYouRows.test.ts
+++ b/frontend/src/scenes/project-homepage/today/todayForYouRows.test.ts
@@ -18,8 +18,13 @@ function highlight(key: string, label: HighlightItemApi['label']): HighlightItem
}
describe('forYouRows', () => {
- it('keeps the server order, puts reports before highlights and more reports last, and steps through reports in list order', () => {
- const reports = ['a', 'b', 'c', 'd', 'e', 'f'].map((id) => makeReport({ id }))
+ it.each([
+ { ids: [], visible: 2, done: ['risk-1'] },
+ { ids: ['a', 'b'], visible: 4, done: ['b', 'risk-1'] },
+ { ids: ['a', 'b', 'c', 'd', 'e'], visible: 5, done: ['b', 'risk-1'] },
+ { ids: ['a', 'b', 'c', 'd', 'e', 'f'], visible: 5, done: ['b', 'risk-1'] },
+ ])('keeps report order and highlights with $ids and a visible limit of $visible', ({ ids, visible, done }) => {
+ const reports = ids.map((id) => makeReport({ id }))
const { rows, limit } = forYouRows({
reports,
loadedMoreReports: [makeReport({ id: 'more' })],
@@ -28,9 +33,9 @@ describe('forYouRows', () => {
reportStateOverrides: { b: 'resolved' },
})
- expect(limit).toBe(5)
- expect(rows.map((row) => row.key)).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'risk-1', 'opportunity-1', 'more'])
- expect(rows.filter((row) => row.done).map((row) => row.key)).toEqual(['b', 'risk-1'])
- expect(forYouReportIds(rows)).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'more'])
+ expect(limit).toBe(visible)
+ expect(rows.map((row) => row.key)).toEqual([...ids, 'risk-1', 'opportunity-1', 'more'])
+ expect(rows.filter((row) => row.done).map((row) => row.key)).toEqual(done)
+ expect(forYouReportIds(rows)).toEqual([...ids, 'more'])
})
})
diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts b/frontend/src/scenes/project-homepage/today/todayLogic.test.ts
index 0708699fb908..0f842f8e895f 100644
--- a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts
+++ b/frontend/src/scenes/project-homepage/today/todayLogic.test.ts
@@ -91,6 +91,7 @@ describe('todayLogic', () => {
afterEach(() => {
jest.useRealTimers()
+ jest.restoreAllMocks()
})
it.each(['toggle', 'url'])('reloads frequent items when sample mode is disabled by %s', async (source) => {
@@ -371,6 +372,7 @@ describe('todayLogic', () => {
})
it('asks for the top reports for the person and counts the rest', async () => {
+ jest.spyOn(Date, 'now').mockReturnValue(new Date('2026-10-28T12:00:00.000Z').getTime())
const reports = [makeReport({ id: 'a' }), makeReport({ id: 'b' })]
listResponse = [200, { results: reports, count: 9 }]
const logic = todayLogic()
@@ -379,12 +381,14 @@ describe('todayLogic', () => {
await expectLogic(logic).toFinishAllListeners().toMatchValues({ reports, moreReportCount: 7 })
expect(Object.fromEntries(listParams!.entries())).toEqual({
view: 'for_you',
- sort: 'priority',
+ sort: 'recommended',
+ created_after: '2026-10-21T12:00:00.000Z',
limit: String(TOP_REPORT_COUNT),
})
})
it('pages through the reports past the list without the ones it shows, and starts over when the list shows other reports', async () => {
+ jest.spyOn(Date, 'now').mockReturnValue(new Date('2026-10-28T12:00:00.000Z').getTime())
const page = (prefix: string, length: number): ReturnType<typeof makeReport>[] =>
Array.from({ length }, (_, index) => makeReport({ id: `${prefix}${index}` }))
listResponse = [200, { results: [makeReport({ id: 'a' })], count: 5 }]
@@ -401,7 +405,8 @@ describe('todayLogic', () => {
.toMatchValues({ loadedMoreReports: first, canLoadMoreReports: true, moreReportsInInbox: 0 })
expect(Object.fromEntries(listParams!.entries())).toEqual({
view: 'for_you',
- sort: 'priority',
+ sort: 'recommended',
+ created_after: '2026-10-21T12:00:00.000Z',
limit: String(MORE_REPORTS_PAGE_SIZE),
offset: '0',
exclude: 'a',
@@ -457,10 +462,17 @@ describe('todayLogic', () => {
{ status: 403, expected: { topReports: { results: [], count: 0 }, reportsFailed: false } },
])('keeps a failed load apart from an empty list, and treats $status that way', async ({ status, expected }) => {
listResponse = [status, { detail: 'Error' }]
+ const item = makeHighlightItem({ key: 'alert:synthetic', source: 'alerts' })
+ highlightResponses = [[200, makeHighlights({ items: [item] })]]
const logic = todayLogic()
logic.mount()
- await expectLogic(logic).toFinishAllListeners().toMatchValues(expected)
+ await expectLogic(logic)
+ .toFinishAllListeners()
+ .toMatchValues({
+ ...expected,
+ forYouRows: { rows: [expect.objectContaining({ kind: 'highlight', item })], limit: 1 },
+ })
})
it('remembers the report to focus and the home scroll only while the person stays on Today', async () => {
diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.ts b/frontend/src/scenes/project-homepage/today/todayLogic.ts
index b2cce3b58e2b..f5b7a6074f7d 100644
--- a/frontend/src/scenes/project-homepage/today/todayLogic.ts
+++ b/frontend/src/scenes/project-homepage/today/todayLogic.ts
@@ -53,11 +53,18 @@ import { todayVerdictLogic } from './todayVerdictLogic'
export const TOP_REPORT_COUNT = 5
export const MORE_REPORTS_PAGE_SIZE = 20
-export const TODAY_REPORT_LIST_PARAMS = { view: 'for_you', sort: 'priority' } as const
export const RECENT_OBJECT_COUNT = 4
const RECENT_OBJECT_MORE_COUNT = 8
const CLOCK_MS = 30_000
+function todayReportListParams(): Record<string, string | undefined> {
+ return {
+ view: 'for_you',
+ sort: 'recommended',
+ created_after: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
+ }
+}
+
/** Where a report was opened from, sent with the `today report opened` event. */
export type TodayReportOpenSource = 'list' | 'more'
@@ -522,7 +529,7 @@ export const todayLogic = kea<todayLogicType>([
let response
try {
response = await signalsReportsList(String(values.currentProjectId), {
- ...TODAY_REPORT_LIST_PARAMS,
+ ...todayReportListParams(),
limit: TOP_REPORT_COUNT,
})
} catch (error) {
@@ -548,7 +555,7 @@ export const todayLogic = kea<todayLogicType>([
const exclude = values.shownReportIds
const loaded = values.loadedMoreReports
const response = await signalsReportsList(String(values.currentProjectId), {
- ...TODAY_REPORT_LIST_PARAMS,
+ ...todayReportListParams(),
limit: MORE_REPORTS_PAGE_SIZE,
offset: loaded.length,
exclude: exclude.length > 0 ? exclude : undefined,
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 131aced5cd38..c3ee575c9716 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -1968,7 +1968,27 @@ class TestSignalReportListAPI(APIBaseTest):
row = next(r for r in response.json()["results"] if r["id"] == str(report.id))
assert row["is_suggested_reviewer"] is True
- def test_for_you_view_lists_only_the_open_actionable_reports_for_the_user(self):
+ @parameterized.expand(
+ [
+ ("priority", "priority", None, True, True, "US"),
+ ("recommended_control", "recommended", "control", True, True, "US"),
+ ("recommended_open", "recommended", "open", True, True, "US"),
+ ("ai_off", "recommended", "open", False, True, "US"),
+ ("autostart_off", "recommended", "open", True, False, "US"),
+ ("ai_and_autostart_off", "recommended", "open", False, False, "US"),
+ ("eu", "recommended", "open", True, True, "EU"),
+ ("flag_off", "recommended", None, True, True, "US"),
+ ]
+ )
+ def test_for_you_view_lists_only_the_open_actionable_reports_for_the_user(
+ self, _name: str, sort: str, variant: str | None, ai: bool, autostart: bool, region: str
+ ) -> None:
+ self.organization.is_ai_data_processing_approved = ai
+ self.organization.save(update_fields=["is_ai_data_processing_approved"])
+ SignalTeamConfig.objects.update_or_create(team=self.team, defaults={"autostart_enabled": autostart})
+ self.user.is_staff = False
+ self.user.save(update_fields=["is_staff"])
+
def report_naming_me(title: str, priority: str, **fields) -> SignalReport:
report = self._create_report(title=title, **fields)
SignalReportArtefact.objects.create(
@@ -1982,26 +2002,42 @@ class TestSignalReportListAPI(APIBaseTest):
waiting = report_naming_me("Waits for my input", "P2", status=SignalReport.Status.PENDING_INPUT)
reviewing = report_naming_me("Names me as reviewer", "P1")
+ self._ranking_score_artefact(waiting, scores={"open": 0.9})
+ self._ranking_score_artefact(reviewing, scores={"open": 0.1})
report_naming_me("Not actionable", "P0", latest_actionability="not_actionable")
+ report_naming_me("Already addressed", "P0", latest_already_addressed=True)
report_naming_me("Resolved", "P0", status=SignalReport.Status.RESOLVED)
+ old = report_naming_me("Old report", "P0")
+ SignalReport.objects.filter(pk=old.pk).update(created_at=timezone.now() - timedelta(days=8))
unowned = self._create_report(title="Nobody owns it", latest_actionability="immediately_actionable")
self._priority_artefact(unowned, priority="P0")
- response = self.client.get(self._list_url(view="for_you", sort="priority", limit=1))
+ first, second = (
+ (waiting, reviewing)
+ if sort == "recommended" and variant == "open" and region != "EU"
+ else (reviewing, waiting)
+ )
+ params = {"view": "for_you", "sort": sort, "created_after": (timezone.now() - timedelta(days=7)).isoformat()}
+ with (
+ self.settings(CLOUD_DEPLOYMENT=region),
+ patch(
+ "products.signals.backend.ranking.inbox_sort.posthoganalytics.get_feature_flag", return_value=variant
+ ),
+ patch("products.signals.backend.ranking.access.feature_enabled_or_false", return_value=False),
+ ):
+ response = self.client.get(self._list_url(**params, limit=1))
- assert response.status_code == status.HTTP_200_OK
- body = response.json()
- assert [row["id"] for row in body["results"]] == [str(reviewing.id)]
- assert body["count"] == 2
- assert body["next"] is not None
- next_page = self.client.get(body["next"]).json()
- assert [row["id"] for row in next_page["results"]] == [str(waiting.id)]
-
- without_shown = self.client.get(
- self._list_url(view="for_you", sort="priority", exclude=str(reviewing.id), offset=0)
- ).json()
- assert [row["id"] for row in without_shown["results"]] == [str(waiting.id)]
- assert without_shown["count"] == 1
+ assert response.status_code == status.HTTP_200_OK
+ body = response.json()
+ assert [row["id"] for row in body["results"]] == [str(first.id)]
+ assert body["count"] == 2
+ assert body["next"] is not None
+ next_page = self.client.get(body["next"]).json()
+ assert [row["id"] for row in next_page["results"]] == [str(second.id)]
+
+ without_shown = self.client.get(self._list_url(**params, exclude=str(first.id), offset=0)).json()
+ assert [row["id"] for row in without_shown["results"]] == [str(second.id)]
+ assert without_shown["count"] == 1
def test_is_suggested_reviewer_uses_latest_reviewers_row(self):
# suggested_reviewers is append-only: an older row listing the user must not keep them