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): filter report list by priority (#58784)

Oliver Browne809b231c4211
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index e06f4259d6c9..4285a90c18a1 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -206,6 +206,66 @@ class TestSignalReportListAPI(APIBaseTest):
assert response.status_code == status.HTTP_200_OK
assert response.json()["priority"] == "P0"
+ # --- priority filter ---
+
+ @parameterized.expand(
+ [
+ ("single", "P1", {"P1"}),
+ ("multiple", "P0,P2", {"P0", "P2"}),
+ ("case_insensitive", "p1", {"P1"}),
+ ]
+ )
+ def test_filter_by_priority(self, _name, query_value, expected_priorities):
+ reports_by_priority = {
+ "P0": self._create_report(title="P0 report"),
+ "P1": self._create_report(title="P1 report"),
+ "P2": self._create_report(title="P2 report"),
+ }
+ for priority, report in reports_by_priority.items():
+ self._priority_artefact(report, priority=priority)
+
+ response = self.client.get(self._list_url(priority=query_value))
+ assert response.status_code == status.HTTP_200_OK
+ ids = {r["id"] for r in response.json()["results"]}
+ assert ids == {str(reports_by_priority[p].id) for p in expected_priorities}
+
+ def test_filter_excludes_reports_without_priority(self):
+ self._create_report(title="No priority")
+ r_p1 = self._create_report(title="P1 report")
+ self._priority_artefact(r_p1, priority="P1")
+
+ response = self.client.get(self._list_url(priority="P1"))
+ assert response.status_code == status.HTTP_200_OK
+ ids = {r["id"] for r in response.json()["results"]}
+ assert ids == {str(r_p1.id)}
+
+ @parameterized.expand(
+ [
+ ("out_of_range", "P9"),
+ ("garbage", "not-a-priority"),
+ ("mixed_valid_and_invalid", "P0,P9"),
+ ]
+ )
+ def test_filter_priority_invalid_value_returns_400(self, _name, raw):
+ response = self.client.get(self._list_url(priority=raw))
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ body = response.json()
+ assert body["attr"] == "priority"
+ assert body["code"] == "invalid_input"
+
+ def test_filter_priority_combines_with_ordering(self):
+ r_p2 = self._create_report(title="P2 report")
+ r_p0 = self._create_report(title="P0 report")
+ r_p1 = self._create_report(title="P1 report")
+ self._priority_artefact(r_p2, priority="P2")
+ self._priority_artefact(r_p0, priority="P0")
+ self._priority_artefact(r_p1, priority="P1")
+
+ response = self.client.get(self._list_url(priority="P0,P2", ordering="priority"))
+ assert response.status_code == status.HTTP_200_OK
+ ids = [r["id"] for r in response.json()["results"]]
+ assert ids == [str(r_p0.id), str(r_p2.id)]
+
# --- ordering ---
def test_ready_before_candidate_even_if_candidate_has_higher_weight(self):
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index 3d37066376fc..66c6bdc0e420 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -53,6 +53,7 @@ from products.data_warehouse.backend.data_load.service import trigger_external_d
from products.signals.backend.facade.api import emit_signal
from products.signals.backend.implementation_pr import fetch_implementation_pr_urls_for_reports
from products.signals.backend.models import (
+ AutonomyPriority,
InvalidStatusTransition,
SignalReport,
SignalReportArtefact,
@@ -396,6 +397,7 @@ class SignalReportViewSet(
qs = self._annotate_latest_actionability_value(qs)
qs = self._annotate_signal_report_status_rank(qs)
qs = self._annotate_signal_report_priority(qs)
+ qs = self._apply_signal_report_priority_filter(qs)
qs = self._prefetch_signal_report_priority_artefacts(qs)
qs = self._annotate_is_suggested_reviewer(qs)
if self.action != "list":
@@ -483,6 +485,28 @@ class SignalReportViewSet(
)
)
+ def _apply_signal_report_priority_filter(self, queryset):
+ # Filters on the `priority_rank` annotation, which must be applied first.
+ # Reports without a priority artefact (coalesced to "~") are excluded when this filter is set.
+ priority_filter = self.request.query_params.get("priority")
+ if not priority_filter:
+ return queryset
+
+ values = [p.strip().upper() for p in priority_filter.split(",") if p.strip()]
+ if not values:
+ return queryset
+
+ allowed = set(AutonomyPriority.values)
+ invalid = [v for v in values if v not in allowed]
+ if invalid:
+ raise serializers.ValidationError(
+ {
+ "priority": f"Invalid priority value(s): {', '.join(sorted(set(invalid)))}. Allowed: {', '.join(sorted(allowed))}."
+ }
+ )
+
+ return queryset.filter(priority_rank__in=values)
+
def _annotate_signal_report_status_rank(self, queryset):
# `ordering=status` uses semantic stage rank (annotation), not lexicographic `status` column order.
# `status=ready` splits into two virtual stages (requires `latest_actionability_value`):
@@ -700,6 +724,16 @@ class SignalReportViewSet(
"include any of the given users."
),
),
+ OpenApiParameter(
+ name="priority",
+ type=OpenApiTypes.STR,
+ location=OpenApiParameter.QUERY,
+ required=False,
+ description=(
+ "Comma-separated list of priorities to include. Valid values: P0, P1, P2, P3, P4. "
+ "Reports without a priority assignment are excluded when this filter is set."
+ ),
+ ),
OpenApiParameter(
name="ordering",
type=OpenApiTypes.STR,
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index 1ec73e6037ce..af258e157570 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -1145,6 +1145,10 @@ export type SignalsReportsListParams = {
* Comma-separated ordering clauses. Each clause is a field name optionally prefixed with '-' for descending. Allowed fields: status, is_suggested_reviewer, signal_count, total_weight, priority, created_at, updated_at, id. Defaults to '-is_suggested_reviewer,status,-updated_at'.
*/
ordering?: string
+ /**
+ * Comma-separated list of priorities to include. Valid values: P0, P1, P2, P3, P4. Reports without a priority assignment are excluded when this filter is set.
+ */
+ priority?: string
/**
* Case-insensitive substring match against report title and summary.
*/
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index ba5470ca5905..caf9d99b1f85 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -49838,6 +49838,10 @@ export namespace Schemas {
* Comma-separated ordering clauses. Each clause is a field name optionally prefixed with '-' for descending. Allowed fields: status, is_suggested_reviewer, signal_count, total_weight, priority, created_at, updated_at, id. Defaults to '-is_suggested_reviewer,status,-updated_at'.
*/
ordering?: string;
+ /**
+ * Comma-separated list of priorities to include. Valid values: P0, P1, P2, P3, P4. Reports without a priority assignment are excluded when this filter is set.
+ */
+ priority?: string;
/**
* Case-insensitive substring match against report title and summary.
*/
diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.ts
index 45744ff127b3..db7a0b6c3857 100644
--- a/services/mcp/src/generated/signals/api.ts
+++ b/services/mcp/src/generated/signals/api.ts
@@ -25,6 +25,12 @@ export const SignalsReportsListQueryParams = /* @__PURE__ */ zod.object({
.describe(
"Comma-separated ordering clauses. Each clause is a field name optionally prefixed with '-' for descending. Allowed fields: status, is_suggested_reviewer, signal_count, total_weight, priority, created_at, updated_at, id. Defaults to '-is_suggested_reviewer,status,-updated_at'."
),
+ priority: zod
+ .string()
+ .optional()
+ .describe(
+ 'Comma-separated list of priorities to include. Valid values: P0, P1, P2, P3, P4. Reports without a priority assignment are excluded when this filter is set.'
+ ),
search: zod.string().optional().describe('Case-insensitive substring match against report title and summary.'),
source_product: zod
.string()
diff --git a/services/mcp/src/tools/generated/signals.ts b/services/mcp/src/tools/generated/signals.ts
index 80911b25510f..481a3baaca92 100644
--- a/services/mcp/src/tools/generated/signals.ts
+++ b/services/mcp/src/tools/generated/signals.ts
@@ -40,6 +40,7 @@ const inboxReportsList = (): ToolBase<
limit: params.limit,
offset: params.offset,
ordering: params.ordering,
+ priority: params.priority,
search: params.search,
source_product: params.source_product,
status: params.status,
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 55a48c93fd67..f7f08d2edd40 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
@@ -13,6 +13,10 @@
"description": "Comma-separated ordering clauses. Each clause is a field name optionally prefixed with '-' for descending. Allowed fields: status, is_suggested_reviewer, signal_count, total_weight, priority, created_at, updated_at, id. Defaults to '-is_suggested_reviewer,status,-updated_at'.",
"type": "string"
},
+ "priority": {
+ "description": "Comma-separated list of priorities to include. Valid values: P0, P1, P2, P3, P4. Reports without a priority assignment are excluded when this filter is set.",
+ "type": "string"
+ },
"search": {
"description": "Case-insensitive substring match against report title and summary.",
"type": "string"