: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
feat(signals): serve the reports for you and use them on the today fallback (#110054)
Vojta Bartoš705547d6585e
diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsxindex 7106feed4221..4b151b510cf9 100644--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx@@ -18,7 +18,6 @@ import { TodaySpaceHoverCard } from '~/layout/today/TodaySpaceHoverCard'import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'import { sessionItem } from '~/layout/today/todayWorkItems'import { mswDecorator } from '~/mocks/browser'-import { EMPTY_PAGINATED_RESPONSE } from '~/mocks/handlers'import { makeReport, mockSignals } from 'products/signals/frontend/inbox/__mocks__/inboxMocks'import { reportMetricQueryHandler } from 'products/signals/frontend/inbox/__mocks__/reportMetricMocks'@@ -426,6 +425,7 @@ const meta: Meta = {mswDecorator({get: {'/api/projects/:team_id/signals/reports/': { results: REPORTS, count: 7 },+ '/api/projects/:team_id/signals/reports/for_you/': { results: REPORTS, count: 7 },'/api/projects/:team_id/signals/reports/:id/': (req) => [200,REPORTS.find((report) => report.id === req.params.id) ?? REPORTS[0],@@ -567,7 +567,7 @@ export const SampleReportPage: Story = {export const HomeWithNoReports: Story = {decorators: [mswDecorator({- get: { '/api/projects/:team_id/signals/reports/': EMPTY_PAGINATED_RESPONSE },+ get: { '/api/projects/:team_id/signals/reports/for_you/': { results: [], count: 0 } },}),],}@@ -575,7 +575,7 @@ export const HomeWithNoReports: Story = {export const HomeWhenReportsFailToLoad: Story = {decorators: [mswDecorator({- get: { '/api/projects/:team_id/signals/reports/': () => [500, { detail: 'Server error' }] },+ get: { '/api/projects/:team_id/signals/reports/for_you/': () => [500, { detail: 'Server error' }] },}),],}diff --git a/frontend/src/scenes/project-homepage/today/TodayBriefing.tsx b/frontend/src/scenes/project-homepage/today/TodayBriefing.tsxindex ecc89426001e..051eb6744b89 100644--- a/frontend/src/scenes/project-homepage/today/TodayBriefing.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayBriefing.tsx@@ -87,7 +87,7 @@ function TodayBriefingReports(): JSX.Element {{moreReportCount > 0 && (<><Link to={urls.inbox()} data-attr="today-briefing-inbox">- {`${moreReportCount} more ${moreReportCount === 1 ? 'report is' : 'reports are'} in the Inbox`}+ {`${moreReportCount} more for you in the Inbox`}</Link><span>. </span></>diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts b/frontend/src/scenes/project-homepage/today/todayLogic.test.tsindex 83a002dc9a70..ddc08166b8ba 100644--- a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts+++ b/frontend/src/scenes/project-homepage/today/todayLogic.test.ts@@ -56,7 +56,7 @@ describe('todayLogic', () => {briefingCalls = 0useMocks({get: {- '/api/projects/:team_id/signals/reports/': ({ request }) => {+ '/api/projects/:team_id/signals/reports/for_you/': ({ request }) => {listParams = new URL(request.url).searchParamsreturn listResponse},@@ -138,19 +138,14 @@ describe('todayLogic', () => {expect(briefingCalls).toBe(2)})- it('asks for the top actionable reports by priority and counts the rest', async () => {+ it('asks for the top reports for the person and counts the rest', async () => {const reports = [makeReport({ id: 'a' }), makeReport({ id: 'b' })]listResponse = [200, { results: reports, count: 9 }]const logic = todayLogic()logic.mount()await expectLogic(logic).toFinishAllListeners().toMatchValues({ reports, moreReportCount: 7 })- expect(Object.fromEntries(listParams!.entries())).toMatchObject({- status: 'ready,pending_input',- actionability: 'immediately_actionable,requires_human_input',- ordering: 'priority,-updated_at',- limit: String(TOP_REPORT_COUNT),- })+ expect(Object.fromEntries(listParams!.entries())).toEqual({ limit: String(TOP_REPORT_COUNT) })})it('shows sample reports from ?sample=1 without asking the API, until ?sample=0', async () => {diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.ts b/frontend/src/scenes/project-homepage/today/todayLogic.tsindex 0e834c470ca2..9df1edf98639 100644--- a/frontend/src/scenes/project-homepage/today/todayLogic.ts+++ b/frontend/src/scenes/project-homepage/today/todayLogic.ts@@ -4,7 +4,7 @@ import { router } from 'kea-router'import type { LocationChangedPayload } from 'kea-router/lib/types'import posthog from 'posthog-js'-import api, { ApiError } from 'lib/api'+import { ApiError } from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { removeProjectIdIfPresent } from 'lib/utils/kea-router'import { navigateToHref } from 'lib/utils/navigateToHref'@@ -15,6 +15,7 @@ import { userLogic } from 'scenes/userLogic'import { TeamType, UserType } from '~/types'+import { signalsReportsForYouRetrieve } from 'products/signals/frontend/generated/api'import { SignalReport } from 'products/signals/frontend/inbox/types'import { todayBriefingRefreshCreate, todayBriefingRetrieve } from 'products/today/frontend/generated/api'import type { BriefingApi, BriefingItemApi } from 'products/today/frontend/generated/api.schemas'@@ -297,16 +298,17 @@ export const todayLogic = kea<todayLogicType>([if (values.useSampleData) {return sampleTopReports(TOP_REPORT_COUNT)}- // The same filter as the Inbox's actionable view, ranked by priority, so Today shows- // the reports most worth acting on first.- // nosemgrep: prefer-codegen-api-namespaced-signals -- Today passes reports to the Inbox's helpers, which take the handwritten SignalReport. The generated report type is wider (string status and priority, read-only arrays), so this call moves to generated types together with the Inbox.- const response = await api.signalReports.list({- status: 'ready,pending_input',- actionability: 'immediately_actionable,requires_human_input',- ordering: 'priority,-updated_at',+ if (values.currentProjectId === null) {+ return { results: [], count: 0 }+ }+ // The person's own reports, ranked and counted the way the Today briefing ranks them.+ const response = await signalsReportsForYouRetrieve(String(values.currentProjectId), {limit: TOP_REPORT_COUNT,})- return { results: response.results, count: response.count }+ // Today passes reports to the Inbox's helpers, which take the handwritten SignalReport. The+ // generated row type is wider (string status and priority, read-only arrays), so the cast+ // goes away when the Inbox moves to generated types.+ return { results: response.results as unknown as SignalReport[], count: response.count }},},],diff --git a/products/signals/backend/serializers.py b/products/signals/backend/serializers.pyindex b24eb1003e29..6f3f3cb291e4 100644--- a/products/signals/backend/serializers.py+++ b/products/signals/backend/serializers.py@@ -1660,6 +1660,36 @@ class SignalReportListQuerySerializer(serializers.Serializer):)+MAX_FOR_YOU_REPORTS = 20+++class SignalReportsForYouQuerySerializer(serializers.Serializer):+ limit = serializers.IntegerField(+ required=False,+ default=5,+ min_value=1,+ max_value=MAX_FOR_YOU_REPORTS,+ help_text=f"How many of the top reports to return, 1 to {MAX_FOR_YOU_REPORTS}. Defaults to 5.",+ )+++class SignalReportsForYouResponseSerializer(serializers.Serializer):+ results = SignalReportListSerializer(+ many=True,+ help_text=(+ "The open, actionable reports that matter most to the current user, best first: reports "+ "waiting for their input, reports they claimed, reports naming them as a reviewer, then P0 "+ "reports that nobody owns. The Today briefing ranks reports the same way."+ ),+ )+ count = serializers.IntegerField(+ help_text=(+ "How many open reports are for the current user: the reports in `results`, plus the other "+ "open, actionable reports that name them as a reviewer."+ ),+ )++# One list page, with room for a next page's ids that have not loaded yet.MAX_SOURCE_METADATA_REPORTS = 100diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.pyindex 4b20606ef7be..139f883ba306 100644--- a/products/signals/backend/test/test_signal_report_api.py+++ b/products/signals/backend/test/test_signal_report_api.py@@ -1154,6 +1154,28 @@ 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_ranks_the_reports_naming_the_user_and_counts_only_theirs(self):+ def report_naming_me(title: str, report_status: str) -> SignalReport:+ report = self._create_report(title=title, status=report_status)+ SignalReportArtefact.objects.create(+ team=self.team,+ report=report,+ type=SignalReportArtefact.ArtefactType.SUGGESTED_REVIEWERS,+ content=json.dumps([{"user_uuid": str(self.user.uuid)}]),+ )+ return report++ waiting = report_naming_me("Waits for my input", SignalReport.Status.PENDING_INPUT)+ report_naming_me("Names me as reviewer", SignalReport.Status.READY)+ self._create_report(title="Someone else's report")++ response = self.client.get(f"{self._list_url()}for_you/?limit=1")++ assert response.status_code == status.HTTP_200_OK+ body = response.json()+ assert [row["id"] for row in body["results"]] == [str(waiting.id)]+ assert body["count"] == 2+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# flagged after a newer row drops them (latest-wins).diff --git a/products/signals/backend/views.py b/products/signals/backend/views.pyindex 804ec4345076..09adad3e4b54 100644--- a/products/signals/backend/views.py+++ b/products/signals/backend/views.py@@ -108,6 +108,7 @@ from products.signals.backend.billing import (refund_ineligibility_reason,report_pr_is_merged,)+from products.signals.backend.briefing_reports import open_report_counts, reports_for_briefingfrom products.signals.backend.dismissal_notes import forward_dismissal_notefrom products.signals.backend.facade.api import emit_signalfrom products.signals.backend.feedback_notes import forward_feedback_note@@ -202,6 +203,8 @@ from products.signals.backend.serializers import (SignalReportMetricRefreshResponseSerializer,SignalReportRefundSerializer,SignalReportSerializer,+ SignalReportsForYouQuerySerializer,+ SignalReportsForYouResponseSerializer,SignalReportSourceMetadataRequestSerializer,SignalReportSourceMetadataResponseSerializer,SignalReportSuggestedReviewersArtefactSerializer,@@ -1126,7 +1129,7 @@ class SignalReportViewSet(return Response(ReportReadStateResponseSerializer({"states": states}).data)def get_serializer_class(self) -> type[serializers.BaseSerializer]:- if self.action == "list":+ if self.action in {"list", "for_you"}:return SignalReportListSerializerreturn SignalReportSerializer@@ -1251,7 +1254,7 @@ class SignalReportViewSet(_DEFAULT_STATUSES = _FILTERABLE_STATUSES - {SignalReport.Status.SUPPRESSED}# Actions that work on many reports at once, so per-row annotations are wasted work there.- _MULTI_REPORT_ACTIONS = frozenset({"list", "bulk_state"})+ _MULTI_REPORT_ACTIONS = frozenset({"list", "bulk_state", "for_you"})# Actions allowed to resolve a suppressed report by ID even without an explicit# `status` filter. These are the read/reopen paths the inbox's Dismissed tab needs:@@ -2259,6 +2262,15 @@ class SignalReportViewSet("signals.reports.list.has_next_page", page_offset + len(report_ids) < total_count)+ data = self._render_report_rows(reports, include_source_metadata=include_source_metadata)++ if page is not None:+ return self.get_paginated_response(data)+ return Response(data)++ def _render_report_rows(self, reports: Sequence[Any], *, include_source_metadata: bool) -> Any:+ """Serialize report rows the way the inbox list does, with batched lookups instead of per-row queries."""+ report_ids = [str(r.id) for r in reports]# Source metadata is decorative. The serializer degrades to empty values when ClickHouse is# unavailable, so a metadata failure does not hide otherwise available reports. The web inbox# opts out and loads it after the rows render, so the page does not wait on ClickHouse.@@ -2307,11 +2319,34 @@ class SignalReportViewSet(serializer = self.get_serializer(reports, many=True, context=context)with tracer.start_as_current_span("signals.reports.list.serialize"):- data = serializer.data+ return serializer.data- if page is not None:- return self.get_paginated_response(data)- return Response(data)+ @validated_request(+ query_serializer=SignalReportsForYouQuerySerializer,+ responses={200: OpenApiResponse(response=SignalReportsForYouResponseSerializer)},+ summary="List the reports that matter most to the current user",+ description=(+ "The open, actionable reports for the current user, best first, and how many there are in "+ "total. Uses the same ranking and count as the Today briefing, so this is the short list to "+ "show someone who asks what needs them."+ ),+ )+ @action(detail=False, methods=["get"], url_path="for_you", required_scopes=["task:read"])+ def for_you(self, request: ValidatedRequest, *args, **kwargs) -> Response:+ user = cast(User, request.user)+ ranked_ids = [+ report.report_id+ for report in reports_for_briefing(+ team_id=self.team_id, user_id=user.id, limit=request.validated_query_data["limit"]+ )+ ]+ by_id = {str(report.id): report for report in self.get_queryset().filter(id__in=ranked_ids)}+ reports = [by_id[report_id] for report_id in ranked_ids if report_id in by_id]+ more = open_report_counts(+ team_id=self.team_id, user=user, exclude_report_ids=[str(report.id) for report in reports]+ )+ rows = self._render_report_rows(reports, include_source_metadata=True)+ return Response({"results": rows, "count": len(rows) + more.for_person})@extend_schema(summary="List the org members who can be suggested as reviewers",diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.tsindex 46be34331d79..56224b460005 100644--- a/products/signals/frontend/generated/api.schemas.ts+++ b/products/signals/frontend/generated/api.schemas.ts@@ -3028,6 +3028,13 @@ export interface SignalReportBulkStateResponseApi {not_found_count: number}+export interface SignalReportsForYouResponseApi {+ /** The open, actionable reports that matter most to the current user, best first: reports waiting for their input, reports they claimed, reports naming them as a reviewer, then P0 reports that nobody owns. The Today briefing ranks reports the same way. */+ results: SignalReportListApi[]+ /** How many open reports are for the current user: the reports in `results`, plus the other open, actionable reports that name them as a reviewer. */+ count: number+}+/*** * `passing` - Passing* * `failing` - Failing@@ -6777,6 +6784,15 @@ export type SignalsReportsAvailableReviewersRetrieve200 = {}}+export type SignalsReportsForYouRetrieveParams = {+ /**+ * How many of the top reports to return, 1 to 20. Defaults to 5.+ * @minimum 1+ * @maximum 20+ */+ limit?: number+}+export type SignalsReportsPrCiStatusesParams = {/*** Comma-separated report UUIDs to resolve CI state for, at most 100 per request.diff --git a/products/signals/frontend/generated/api.ts b/products/signals/frontend/generated/api.tsindex 758e42e628a5..678993e85927 100644--- a/products/signals/frontend/generated/api.ts+++ b/products/signals/frontend/generated/api.ts@@ -94,6 +94,7 @@ import type {SignalReportSourceMetadataResponseApi,SignalReportStateRequestApi,SignalReportSuggestedReviewersArtefactApi,+ SignalReportsForYouResponseApi,SignalScoutConfigApi,SignalScoutConfigCreateApi,SignalScoutCreateApi,@@ -119,6 +120,7 @@ import type {SignalsReportPrReviewCommentsCreateParams,SignalsReportsAvailableReviewersRetrieve200,SignalsReportsAvailableReviewersRetrieveParams,+ SignalsReportsForYouRetrieveParams,SignalsReportsListParams,SignalsReportsPrCiStatusesParams,SignalsScoutConfigListParams,@@ -1162,6 +1164,37 @@ export const signalsReportsBulkStateCreate = async (})}+export const getSignalsReportsForYouRetrieveUrl = (projectId: string, params?: SignalsReportsForYouRetrieveParams) => {+ const normalizedParams = new URLSearchParams()++ Object.entries(params || {}).forEach(([key, value]) => {+ if (value !== undefined) {+ normalizedParams.append(key, value === null ? 'null' : String(value))+ }+ })++ const stringifiedParams = normalizedParams.toString()++ return stringifiedParams.length > 0+ ? `/api/projects/${projectId}/signals/reports/for_you/?${stringifiedParams}`+ : `/api/projects/${projectId}/signals/reports/for_you/`+}++/**+ * The open, actionable reports for the current user, best first, and how many there are in total. Uses the same ranking and count as the Today briefing, so this is the short list to show someone who asks what needs them.+ * @summary List the reports that matter most to the current user+ */+export const signalsReportsForYouRetrieve = async (+ projectId: string,+ params?: SignalsReportsForYouRetrieveParams,+ options?: RequestInit+): Promise<SignalReportsForYouResponseApi> => {+ return apiMutator<SignalReportsForYouResponseApi>(getSignalsReportsForYouRetrieveUrl(projectId, params), {+ ...options,+ method: 'GET',+ })+}+export const getSignalsReportsPrCiStatusesUrl = (projectId: string, params: SignalsReportsPrCiStatusesParams) => {const normalizedParams = new URLSearchParams()diff --git a/products/signals/mcp/tools.yaml b/products/signals/mcp/tools.yamlindex 6bcc4d833a08..14a0b1390614 100644--- a/products/signals/mcp/tools.yaml+++ b/products/signals/mcp/tools.yaml@@ -1239,6 +1239,9 @@ tools:signals-reports-feedback-create:operation: signals_reports_feedback_createenabled: false+ signals-reports-for-you-retrieve:+ operation: signals_reports_for_you_retrieve+ enabled: falsesignals-reports-pr-ci-statuses:operation: signals_reports_pr_ci_statusesenabled: falsediff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex e7e7f5728b68..09d56ba85ae8 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -94538,6 +94538,13 @@ export namespace Schemas {readonly task_id: string | null;}+ export interface SignalReportsForYouResponse {+ /** The open, actionable reports that matter most to the current user, best first: reports waiting for their input, reports they claimed, reports naming them as a reviewer, then P0 reports that nobody owns. The Today briefing ranks reports the same way. */+ results: SignalReportList[];+ /** How many open reports are for the current user: the reports in `results`, plus the other open, actionable reports that name them as a reviewer. */+ count: number;+ }+/*** Optional JSON Schema (draft 2020-12) describing ONE structured record this scout produces via `scout-record-output` — e.g. a per-report quality judgment (`{"type": "object", "properties": {"verdict": {"enum": ["good", "bad", "unsure"]}, "reason": {"type": "string"}}, "required": ["verdict", "reason"]}`). The root must be `"type": "object"`. Setting a schema turns the structured-output channel on: the run prompt renders the schema and every submitted record is validated against it and recorded in the project as a `$scout_structured_output` event, queryable like any event. The channel also requires emit — a dry-run scout has nowhere to record to. Cardinality is the scout's call (one record per run, one per judged entity, ...). Null = channel off. Setting a schema requires skill-authoring authorization (the `llm_skill:write` scope and skill editor access) since the scout reads it verbatim in its prompt; clearing it needs only the config write. Records validate against the schema in force when the run was dispatched.* @nullable@@ -120979,6 +120986,15 @@ export namespace Schemas {email: string;}};+ export type SignalsReportsForYouRetrieveParams = {+ /**+ * How many of the top reports to return, 1 to 20. Defaults to 5.+ * @minimum 1+ * @maximum 20+ */+ limit?: number;+ };+export type SignalsReportsPrCiStatusesParams = {/*** Comma-separated report UUIDs to resolve CI state for, at most 100 per request.