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.

feat(signals): add has_implementation_pr filter to reports list (#64143)

Andrew Maguirea408d28d5330
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 1351a99ae818..e2f8a97cc69a 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -602,6 +602,76 @@ class TestSignalReportListAPI(APIBaseTest):
str(report_with_pr.id): "https://github.com/org/repo/pull/42",
}
+ # --- has_implementation_pr filter ---
+
+ @parameterized.expand(
+ [
+ ("true_keeps_pr_reports", "true", "with_pr"),
+ ("false_keeps_non_pr_reports", "false", "without_pr"),
+ ]
+ )
+ def test_filter_has_implementation_pr(self, _name, query_value, expected):
+ report_with_pr = self._create_report(title="Report with PR")
+ report_without_pr = self._create_report(title="Report without PR")
+ self._create_implementation_task_with_run(report_with_pr, pr_url="https://github.com/org/repo/pull/42")
+ expected_id = str(report_with_pr.id if expected == "with_pr" else report_without_pr.id)
+
+ response = self.client.get(self._list_url(has_implementation_pr=query_value))
+ assert response.status_code == status.HTTP_200_OK
+ body = response.json()
+ assert {r["id"] for r in body["results"]} == {expected_id}
+ # `count` is the true total (matches what a limit=1 count query returns).
+ assert body["count"] == 1
+
+ def test_filter_has_implementation_pr_ignores_empty_pr_url(self):
+ report_empty_pr = self._create_report(title="Report with empty PR url")
+ self._create_implementation_task_with_run(report_empty_pr, pr_url="")
+
+ with_pr = self.client.get(self._list_url(has_implementation_pr="true"))
+ assert with_pr.json()["count"] == 0
+ without_pr = self.client.get(self._list_url(has_implementation_pr="false"))
+ assert str(report_empty_pr.id) in {r["id"] for r in without_pr.json()["results"]}
+
+ def test_filter_has_implementation_pr_absent_returns_all(self):
+ report_with_pr = self._create_report(title="Report with PR")
+ report_without_pr = self._create_report(title="Report without PR")
+ self._create_implementation_task_with_run(report_with_pr, pr_url="https://github.com/org/repo/pull/42")
+
+ response = self.client.get(self._list_url())
+ assert response.status_code == status.HTTP_200_OK
+ ids = {r["id"] for r in response.json()["results"]}
+ assert {str(report_with_pr.id), str(report_without_pr.id)} <= ids
+
+ def test_filter_has_implementation_pr_count_via_limit_one(self):
+ for i in range(3):
+ report = self._create_report(title=f"PR report {i}")
+ self._create_implementation_task_with_run(report, pr_url=f"https://github.com/org/repo/pull/{i}")
+ self._create_report(title="No PR report")
+
+ response = self.client.get(self._list_url(has_implementation_pr="true", limit=1))
+ assert response.status_code == status.HTTP_200_OK
+ body = response.json()
+ assert body["count"] == 3
+ assert len(body["results"]) == 1
+
+ def test_filter_has_implementation_pr_empty_value_is_noop(self):
+ report_with_pr = self._create_report(title="Report with PR")
+ report_without_pr = self._create_report(title="Report without PR")
+ self._create_implementation_task_with_run(report_with_pr, pr_url="https://github.com/org/repo/pull/42")
+
+ response = self.client.get(self._list_url(has_implementation_pr=""))
+ assert response.status_code == status.HTTP_200_OK
+ ids = {r["id"] for r in response.json()["results"]}
+ assert {str(report_with_pr.id), str(report_without_pr.id)} <= ids
+
+ @parameterized.expand([("garbage", "maybe"), ("number", "2")])
+ def test_filter_has_implementation_pr_invalid_value_returns_400(self, _name, raw):
+ response = self.client.get(self._list_url(has_implementation_pr=raw))
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ body = response.json()
+ assert body["attr"] == "has_implementation_pr"
+ assert body["code"] == "invalid_input"
+
# --- source_products ---
def test_source_products_defaults_to_empty_list(self):
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index d51063476168..99c68cb400d2 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -395,6 +395,7 @@ class SignalReportViewSet(
qs = self._apply_signal_report_status_filter(qs)
qs = self._apply_signal_report_search_filter(qs)
qs = self._apply_signal_report_source_product_filter(qs)
+ qs = self._apply_signal_report_implementation_pr_filter(qs)
qs = self._apply_signal_report_suggested_reviewer_filter(qs)
qs = self._annotate_latest_actionability_value(qs)
qs = self._annotate_signal_report_status_rank(qs)
@@ -476,6 +477,40 @@ class SignalReportViewSet(
report_ids_with_source = fetch_report_ids_for_source_products(self.team, source_products)
return queryset.filter(id__in=report_ids_with_source)
+ def _implementation_pr_exists_subquery(self):
+ # EXISTS over the latest implementation TaskRun that carries a non-empty
+ # `pr_url`. Mirrors `_annotate_implementation_pr_url`, but as a boolean
+ # EXISTS so it can be used as a filter (and counted) without the
+ # per-row PR-url annotation, which the list action skips for performance.
+ return Exists(
+ TaskRun.objects.filter(
+ task__signal_report_tasks__report_id=OuterRef("id"),
+ task__signal_report_tasks__relationship=SignalReportTask.Relationship.IMPLEMENTATION,
+ output__pr_url__isnull=False,
+ ).exclude(output__pr_url="")
+ )
+
+ def _apply_signal_report_implementation_pr_filter(self, queryset):
+ # `has_implementation_pr=true|false` filters reports by whether a shipped
+ # implementation PR exists. Lets the inbox count PR reports (the "Pull
+ # requests" tab) with a cheap `limit=1` count query instead of paging the
+ # whole list and filtering client-side. Absent or empty param leaves the
+ # list unchanged; an unrecognized value is a 400.
+ raw = self.request.query_params.get("has_implementation_pr")
+ if raw is None or not raw.strip():
+ return queryset
+ value = raw.strip().lower()
+ if value in ("1", "true", "yes"):
+ wants_pr = True
+ elif value in ("0", "false", "no"):
+ wants_pr = False
+ else:
+ raise serializers.ValidationError(
+ {"has_implementation_pr": f"Invalid value: {raw!r}. Allowed: true, false."}
+ )
+ pr_exists = self._implementation_pr_exists_subquery()
+ return queryset.filter(pr_exists if wants_pr else ~pr_exists)
+
def _apply_signal_report_suggested_reviewer_filter(self, queryset):
suggested_reviewer_filter = self.request.query_params.get("suggested_reviewers")
if not suggested_reviewer_filter:
@@ -798,6 +833,17 @@ class SignalReportViewSet(
"priority, created_at, updated_at, id. Defaults to '-is_suggested_reviewer,status,-updated_at'."
),
),
+ OpenApiParameter(
+ name="has_implementation_pr",
+ type=OpenApiTypes.BOOL,
+ location=OpenApiParameter.QUERY,
+ required=False,
+ description=(
+ "Filter reports by whether a shipped implementation pull request exists. "
+ "'true' keeps only reports with a PR; 'false' keeps only those without. "
+ "Pair with limit=1 to count PR reports cheaply."
+ ),
+ ),
],
)
def list(self, request, *args, **kwargs):
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index 30f0590652e8..b7b3a0b90f19 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -1279,6 +1279,10 @@ export type SignalsProcessingListParams = {
}
export type SignalsReportsListParams = {
+ /**
+ * Filter reports by whether a shipped implementation pull request exists. 'true' keeps only reports with a PR; 'false' keeps only those without. Pair with limit=1 to count PR reports cheaply.
+ */
+ has_implementation_pr?: boolean
/**
* Number of results to return per page.
*/
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 0cf9a158bf0c..4475d5e26fc7 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -59021,6 +59021,10 @@ export namespace Schemas {
};
export type SignalsReportsListParams = {
+ /**
+ * Filter reports by whether a shipped implementation pull request exists. 'true' keeps only reports with a PR; 'false' keeps only those without. Pair with limit=1 to count PR reports cheaply.
+ */
+ has_implementation_pr?: boolean;
/**
* Number of results to return per page.
*/
diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.ts
index 49ed62b5d9c4..15a2fdea6c61 100644
--- a/services/mcp/src/generated/signals/api.ts
+++ b/services/mcp/src/generated/signals/api.ts
@@ -17,6 +17,12 @@ export const SignalsReportsListParams = /* @__PURE__ */ zod.object({
})
export const SignalsReportsListQueryParams = /* @__PURE__ */ zod.object({
+ has_implementation_pr: zod
+ .boolean()
+ .optional()
+ .describe(
+ "Filter reports by whether a shipped implementation pull request exists. 'true' keeps only reports with a PR; 'false' keeps only those without. Pair with limit=1 to count PR reports cheaply."
+ ),
limit: zod.number().optional().describe('Number of results to return per page.'),
offset: zod.number().optional().describe('The initial index from which to return the results.'),
ordering: zod
diff --git a/services/mcp/src/tools/generated/signals.ts b/services/mcp/src/tools/generated/signals.ts
index 0b6b3d93c297..d89db336089d 100644
--- a/services/mcp/src/tools/generated/signals.ts
+++ b/services/mcp/src/tools/generated/signals.ts
@@ -45,6 +45,7 @@ const inboxReportsList = (): ToolBase<
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/signals/reports/`,
query: {
+ has_implementation_pr: params.has_implementation_pr,
limit: params.limit,
offset: params.offset,
ordering: params.ordering,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-reports-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-reports-list.json
index 07092c4c25dd..8ed07d3d816d 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-reports-list.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-reports-list.json
@@ -1,6 +1,10 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
+ "has_implementation_pr": {
+ "description": "Filter reports by whether a shipped implementation pull request exists. 'true' keeps only reports with a PR; 'false' keeps only those without. Pair with limit=1 to count PR reports cheaply.",
+ "type": "boolean"
+ },
"limit": {
"description": "Number of results to return per page.",
"type": "number"