: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
perf(signals): lift repo slug onto the reports list (#96350)
Paul D'Ambraeeea42084542
diff --git a/products/signals/backend/serializers.py b/products/signals/backend/serializers.pyindex 4421440b3541..a0f44380942a 100644--- a/products/signals/backend/serializers.py+++ b/products/signals/backend/serializers.py@@ -653,6 +653,12 @@ class SignalReportSerializer(serializers.ModelSerializer):dismissal_note = serializers.SerializerMethodField(help_text="Free-form note captured alongside the dismissal reason (when present).",)+ repo_slug = serializers.SerializerMethodField(+ help_text=(+ "`organization/repository` the report's work targets, from the latest repo-selection "+ "artefact (when present). Lets list cards show repository context without a per-card fetch."+ ),+ )is_suggested_reviewer = serializers.BooleanField(read_only=True, default=False)source_products = serializers.SerializerMethodField(help_text="Distinct source products contributing signals to this report (from ClickHouse).",@@ -711,6 +717,7 @@ class SignalReportSerializer(serializers.ModelSerializer):"already_addressed","dismissal_reason","dismissal_note",+ "repo_slug","is_suggested_reviewer","source_products","scout_name",@@ -817,6 +824,31 @@ class SignalReportSerializer(serializers.ModelSerializer):value = data.get("note")return value if isinstance(value, str) and value else None+ def _get_repo_selection_artefact_data(self, obj: SignalReport) -> dict | None:+ prefetched = getattr(obj, "prefetched_repo_selection_artefacts", None)+ if prefetched is not None:+ art = prefetched[0] if prefetched else None+ else:+ art = (+ obj.artefacts.filter(type=SignalReportArtefact.ArtefactType.REPO_SELECTION)+ .order_by("-created_at")+ .first()+ )+ if art is None:+ return None+ try:+ data = json.loads(art.content)+ except (json.JSONDecodeError, TypeError, ValueError):+ return None+ return data if isinstance(data, dict) else None++ def get_repo_slug(self, obj: SignalReport) -> str | None:+ data = self._get_repo_selection_artefact_data(obj)+ if data is None:+ return None+ value = data.get("repository")+ return value if isinstance(value, str) and value else None+def get_source_products(self, obj: SignalReport) -> list[str]:source_products_map: dict[str, list[str]] | None = self.context.get("source_products_map")if source_products_map is not None:diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.pyindex 20e7edc035a0..161f92ed1463 100644--- a/products/signals/backend/test/test_signal_report_api.py+++ b/products/signals/backend/test/test_signal_report_api.py@@ -1,6 +1,6 @@import jsonimport uuid-from datetime import timedelta+from datetime import datetime, timedeltafrom types import SimpleNamespacefrom typing import TYPE_CHECKINGfrom urllib.parse import urlencode@@ -56,6 +56,7 @@ from products.signals.backend.task_run_artefacts import ()from products.signals.backend.views import (PR_CI_STATUS_MAX_REPORTS,+ SignalReportViewSet,classify_report_list_client,parse_pr_ci_status_report_ids,)@@ -1391,6 +1392,50 @@ class TestSignalReportListAPI(APIBaseTest):row = next(r for r in response.json()["results"] if r["id"] == str(report.id))assert row["dismissal_reason"] == "analysis_wrong"+ def _repo_selection_artefact(+ self, report: SignalReport, *, repository: str | None, created_at: datetime | None = None+ ) -> SignalReportArtefact:+ art = SignalReportArtefact(+ team=self.team,+ report=report,+ type=SignalReportArtefact.ArtefactType.REPO_SELECTION,+ content=json.dumps({"repository": repository, "reason": "pick"}),+ )+ art.save()+ if created_at is not None:+ SignalReportArtefact.objects.filter(pk=art.pk).update(created_at=created_at)+ return art++ def test_list_surfaces_latest_repo_slug(self):+ report = self._create_report()+ self._repo_selection_artefact(report, repository="acme/old", created_at=timezone.now() - timedelta(days=1))+ self._repo_selection_artefact(report, repository="acme/new")++ response = self.client.get(self._list_url())+ assert response.status_code == status.HTTP_200_OK+ row = next(r for r in response.json()["results"] if r["id"] == str(report.id))+ assert row["repo_slug"] == "acme/new"++ def test_list_prefetches_only_latest_repo_selection(self):+ report = self._create_report()+ self._repo_selection_artefact(report, repository="acme/old", created_at=timezone.now() - timedelta(days=1))+ latest = self._repo_selection_artefact(report, repository="acme/new")++ reports = list(+ SignalReportViewSet()._prefetch_signal_report_priority_artefacts(SignalReport.objects.filter(pk=report.pk))+ )++ assert reports[0].prefetched_repo_selection_artefacts == [latest]++ def test_list_repo_slug_null_without_selection(self):+ report = self._create_report()+ self._repo_selection_artefact(report, repository=None)++ response = self.client.get(self._list_url())+ assert response.status_code == status.HTTP_200_OK+ row = next(r for r in response.json()["results"] if r["id"] == str(report.id))+ assert row["repo_slug"] is None+class TestAssociatedTaskRunsForReports(APIBaseTest):"""`SignalReport.associated_task_runs_for_reports` — the batched, page-wide counterpart ofdiff --git a/products/signals/backend/views.py b/products/signals/backend/views.pyindex 6a669dd3d4f5..d35891dc505f 100644--- a/products/signals/backend/views.py+++ b/products/signals/backend/views.py@@ -1548,6 +1548,13 @@ class SignalReportViewSet(),to_attr="prefetched_dismissal_artefacts",),+ Prefetch(+ "artefacts",+ queryset=SignalReportArtefact.objects.filter(+ type=SignalReportArtefact.ArtefactType.REPO_SELECTION+ ).order_by("-created_at")[:1],+ to_attr="prefetched_repo_selection_artefacts",+ ),)def _annotate_is_suggested_reviewer(self, queryset):@@ -2628,6 +2635,10 @@ class SignalReportViewSet()if is_wrong_repo:self._apply_wrong_repo_selection(report, corrected_repository)+ # The wrong-repo path just wrote a new repo_selection artefact; drop the+ # stale prefetch so a follow-up serializer reads the corrected/cleared slug.+ if hasattr(report, "prefetched_repo_selection_artefacts"):+ del report.prefetched_repo_selection_artefacts# The dismissal prefetch may have been evaluated before this artefact# existed; drop the stale cache so a follow-up serializer re-reads the# just-written reason/note instead of the previous (or empty) dismissal.diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.tsindex 373bd1a781f3..ce1aa11f0946 100644--- a/products/signals/frontend/generated/api.schemas.ts+++ b/products/signals/frontend/generated/api.schemas.ts@@ -281,6 +281,11 @@ export interface SignalReportApi {* @nullable*/readonly dismissal_note: string | null+ /**+ * `organization/repository` the report's work targets, from the latest repo-selection artefact (when present). Lets list cards show repository context without a per-card fetch.+ * @nullable+ */+ readonly repo_slug: string | nullreadonly is_suggested_reviewer: boolean/** Distinct source products contributing signals to this report (from ClickHouse). */readonly source_products: readonly string[]diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex ad61c411b43f..52bea4376fca 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -58750,6 +58750,11 @@ export namespace Schemas {* @nullable*/readonly dismissal_note: string | null;+ /**+ * `organization/repository` the report's work targets, from the latest repo-selection artefact (when present). Lets list cards show repository context without a per-card fetch.+ * @nullable+ */+ readonly repo_slug: string | null;readonly is_suggested_reviewer: boolean;/** Distinct source products contributing signals to this report (from ClickHouse). */readonly source_products: readonly string[];