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): pick the recommended inbox sort head from the flag variant (#117742)

posthog[bot]44ae540ac288
diff --git a/products/signals/backend/ranking/inbox_sort.py b/products/signals/backend/ranking/inbox_sort.py
index 47d387504a08..bb6a3f702a31 100644
--- a/products/signals/backend/ranking/inbox_sort.py
+++ b/products/signals/backend/ranking/inbox_sort.py
@@ -1,15 +1,16 @@
"""Resolve the `recommended` inbox sort to a ranker, and give each row a coarse merge key.
-A multivariate flag keyed by the requesting user picks the ranker. `control`, an unknown variant, or a flag that is
-off or fails to evaluate gives the priority order. `test` orders by the served `fixed` head first.
+A multivariate flag keyed by the requesting user picks the ranker. The variants `open`, `action` and `fixed` order
+by the served head of the same name first. `control`, an unknown variant, or a flag that is off or fails to evaluate
+gives the priority order.
-The merge key lets a client merge rows from the two rankers without the raw score. It is the score
-decile then the priority rank, so it never says more about the score than one decimal place. The
-`fixed` ranker sorts by the same decile, so the row order does not say more either. Keep
+The merge key lets a client merge rows from different rankers without the raw score. It is the score
+decile then the priority rank, so it never says more about the score than one decimal place. Each
+head ranker sorts by the same decile, so the row order does not say more either. Keep
`score_decile` and `inbox_merge_key` in step.
"""
-from typing import Literal
+from typing import Literal, get_args
from django.db.models import Case, F, FloatField, Value, When
from django.db.models.functions import Floor
@@ -26,12 +27,15 @@ logger = structlog.get_logger(__name__)
RECOMMENDED_INBOX_SORT_FLAG = "signals-inbox-recommended-sort"
-InboxRanker = Literal["priority", "fixed"]
+InboxRanker = Literal["priority", "open", "action", "fixed"]
+HeadRanker = Literal["open", "action", "fixed"]
+
+HEAD_RANKERS: tuple[HeadRanker, ...] = get_args(HeadRanker)
PRIORITY_ORDERING = "priority,status,-updated_at"
RANKER_ORDERINGS: dict[InboxRanker, str] = {
"priority": PRIORITY_ORDERING,
- "fixed": "-ranking_fixed,priority,status,-updated_at",
+ **{head: f"-ranking_{head},{PRIORITY_ORDERING}" for head in HEAD_RANKERS},
}
_DECILES = 10
@@ -53,7 +57,10 @@ def resolve_recommended_ranker(team: Team, user: User) -> InboxRanker:
except Exception:
logger.exception("signals.inbox_sort.flag_failed", team_id=team.id, user_id=user.id)
return "priority"
- return "fixed" if variant == "test" else "priority"
+ for head in HEAD_RANKERS:
+ if variant == head:
+ return head
+ return "priority"
def score_decile(field: str) -> Case:
diff --git a/products/signals/backend/serializers.py b/products/signals/backend/serializers.py
index a2d6e4491797..9bb737c57b9a 100644
--- a/products/signals/backend/serializers.py
+++ b/products/signals/backend/serializers.py
@@ -1871,7 +1871,8 @@ class SignalReportListSerializer(SignalReportSerializer):
inbox_merge_key = serializers.SerializerMethodField(
help_text=(
"Coarse sort key from the ranker named by the list response's ranker field, for sort=recommended "
- "only. Lower keys rank first. It is the ranking score decile, then the priority as a tiebreak. "
+ "only. Lower keys rank first. It is the score decile of the ranker's head (open, action or fixed), "
+ "then the priority as a tiebreak. The priority ranker uses the priority only. "
"Reports without a usable score sort after scored ones. Null for every other sort."
),
)
@@ -1884,7 +1885,7 @@ class SignalReportListSerializer(SignalReportSerializer):
ranker = self.context.get("inbox_ranker")
if ranker is None:
return None
- score = getattr(obj, "ranking_fixed_score", None) if ranker == "fixed" else None
+ score = None if ranker == "priority" else getattr(obj, f"ranking_{ranker}_score", None)
return inbox_merge_key(score, getattr(obj, "priority_sort_rank", None))
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 087a522be252..70a0c1418649 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -1377,11 +1377,12 @@ class TestSignalReportListAPI(APIBaseTest):
[
("flag_off", {"return_value": None}),
("control", {"return_value": "control"}),
- ("unknown_variant", {"return_value": "test-2"}),
+ ("unknown_variant", {"return_value": "test"}),
+ ("non_recommended_head", {"return_value": "discuss"}),
("flag_error", {"side_effect": RuntimeError("flags down")}),
]
)
- def test_recommended_sort_uses_priority_order_unless_the_flag_serves_test(self, _name, flag_result):
+ def test_recommended_sort_uses_priority_order_unless_the_flag_serves_a_head(self, _name, flag_result):
p2 = self._create_report(title="P2")
p0 = self._create_report(title="P0")
no_priority = self._create_report(title="No priority")
@@ -1401,7 +1402,8 @@ class TestSignalReportListAPI(APIBaseTest):
(str(no_priority.id), 65),
]
- def test_recommended_sort_test_variant_ranks_by_fixed_head_without_showing_scores_to_non_staff(self):
+ @parameterized.expand([("open",), ("action",), ("fixed",)])
+ def test_recommended_sort_head_variant_ranks_by_that_head_without_showing_scores_to_non_staff(self, head):
self.user.is_staff = False
self.user.save()
low_p0 = self._create_report(title="Low P0")
@@ -1417,10 +1419,17 @@ class TestSignalReportListAPI(APIBaseTest):
(stale_p0, "P0"),
):
self._priority_artefact(report, priority=priority)
- self._ranking_score_artefact(low_p0, scores={"fixed": 0.1234})
- self._ranking_score_artefact(high_p3, scores={"fixed": 0.8765})
- self._ranking_score_artefact(same_decile_p0, scores={"fixed": 0.8123})
- self._ranking_score_artefact(stale_p0, scores={"fixed": 0.9876})
+ other_heads = [h for h in ("open", "action", "fixed") if h != head]
+ # The other heads score in reverse, so an order from the wrong head fails the assertion.
+ for report, score in (
+ (low_p0, 0.1234),
+ (high_p3, 0.8765),
+ (same_decile_p0, 0.8123),
+ (stale_p0, 0.9876),
+ ):
+ self._ranking_score_artefact(
+ report, scores={head: score, **{other: round(1 - score, 4) for other in other_heads}}
+ )
SignalReportArtefact.objects.create(
team=self.team,
report=stale_p0,
@@ -1429,14 +1438,14 @@ class TestSignalReportListAPI(APIBaseTest):
)
with patch(
- "products.signals.backend.ranking.inbox_sort.posthoganalytics.get_feature_flag", return_value="test"
+ "products.signals.backend.ranking.inbox_sort.posthoganalytics.get_feature_flag", return_value=head
) as get_flag:
response = self.client.get(self._list_url(status="ready", sort="recommended"))
assert response.status_code == status.HTTP_200_OK
assert get_flag.call_args.args[1] == self.user.distinct_id
body = response.json()
- assert body["ranker"] == "fixed"
+ assert body["ranker"] == head
assert [(r["id"], r["inbox_merge_key"]) for r in body["results"]] == [
(str(same_decile_p0.id), 6),
(str(high_p3.id), 9),
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index 3077df35bee2..f5fdc191876e 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -1137,9 +1137,9 @@ class SignalReportListPagination(LimitOffsetPagination):
"type": "string",
"nullable": True,
"description": (
- "The ranker that ordered the page when sort=recommended: priority, or fixed for the served "
- "ranking model's fixed head. Null for every other sort. Each row's inbox_merge_key belongs "
- "to this ranker."
+ "The ranker that ordered the page when sort=recommended: priority, or open, action or fixed "
+ "for that head of the served ranking model. Null for every other sort. Each row's "
+ "inbox_merge_key belongs to this ranker."
),
}
return paginated
@@ -2475,9 +2475,9 @@ class SignalReportViewSet(
required=False,
description=(
"Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when "
- "ordering is supplied. recommended resolves per project to a ranker: the priority order, or "
- "the served ranking model's fixed head with unscored and stale reports in priority order "
- "after the scored ones. The response's ranker field names the one used."
+ "ordering is supplied. recommended resolves per user to a ranker: the priority order, or "
+ "the open, action or fixed head of the served ranking model with unscored and stale reports "
+ "in priority order after the scored ones. The response's ranker field names the one used."
),
),
OpenApiParameter(
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index 225ee020452e..d6b3b77594f5 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -776,7 +776,7 @@ export interface SignalReportListApi {
/** The served model's score from the latest ranking score artefact. Staff only: null for other users, and null when the report has no score. */
readonly ranking: ReportRankingApi | null
/**
- * Coarse sort key from the ranker named by the list response's ranker field, for sort=recommended only. Lower keys rank first. It is the ranking score decile, then the priority as a tiebreak. Reports without a usable score sort after scored ones. Null for every other sort.
+ * Coarse sort key from the ranker named by the list response's ranker field, for sort=recommended only. Lower keys rank first. It is the score decile of the ranker's head (open, action or fixed), then the priority as a tiebreak. The priority ranker uses the priority only. Reports without a usable score sort after scored ones. Null for every other sort.
* @nullable
*/
readonly inbox_merge_key: number | null
@@ -790,7 +790,7 @@ export interface PaginatedSignalReportListListApi {
previous?: string | null
results: SignalReportListApi[]
/**
- * The ranker that ordered the page when sort=recommended: priority, or fixed for the served ranking model's fixed head. Null for every other sort. Each row's inbox_merge_key belongs to this ranker.
+ * The ranker that ordered the page when sort=recommended: priority, or open, action or fixed for that head of the served ranking model. Null for every other sort. Each row's inbox_merge_key belongs to this ranker.
* @nullable
*/
ranker?: string | null
@@ -7806,7 +7806,7 @@ export type SignalsReportsListParams = {
*/
search?: string
/**
- * Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per project to a ranker: the priority order, or the served ranking model's fixed head with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used.
+ * Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per user to a ranker: the priority order, or the open, action or fixed head of the served ranking model with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used.
*/
sort?: string
/**
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index af7da9d78c19..a1765bece5ea 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -74161,7 +74161,7 @@ export namespace Schemas {
/** The served model's score from the latest ranking score artefact. Staff only: null for other users, and null when the report has no score. */
readonly ranking: ReportRanking | null;
/**
- * Coarse sort key from the ranker named by the list response's ranker field, for sort=recommended only. Lower keys rank first. It is the ranking score decile, then the priority as a tiebreak. Reports without a usable score sort after scored ones. Null for every other sort.
+ * Coarse sort key from the ranker named by the list response's ranker field, for sort=recommended only. Lower keys rank first. It is the score decile of the ranker's head (open, action or fixed), then the priority as a tiebreak. The priority ranker uses the priority only. Reports without a usable score sort after scored ones. Null for every other sort.
* @nullable
*/
readonly inbox_merge_key: number | null;
@@ -74175,7 +74175,7 @@ export namespace Schemas {
previous?: string | null;
results: SignalReportList[];
/**
- * The ranker that ordered the page when sort=recommended: priority, or fixed for the served ranking model's fixed head. Null for every other sort. Each row's inbox_merge_key belongs to this ranker.
+ * The ranker that ordered the page when sort=recommended: priority, or open, action or fixed for that head of the served ranking model. Null for every other sort. Each row's inbox_merge_key belongs to this ranker.
* @nullable
*/
ranker?: string | null;
@@ -129570,7 +129570,7 @@ export namespace Schemas {
*/
search?: string;
/**
- * Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per project to a ranker: the priority order, or the served ranking model's fixed head with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used.
+ * Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per user to a ranker: the priority order, or the open, action or fixed head of the served ranking model with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used.
*/
sort?: string;
/**
diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.ts
index 6faa69f8572e..8be3e4b5b9f6 100644
--- a/services/mcp/src/generated/signals/api.ts
+++ b/services/mcp/src/generated/signals/api.ts
@@ -240,7 +240,7 @@ export const SignalsReportsListQueryParams = () => zod.object({
.string()
.optional()
.describe(
- "Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per project to a ranker: the priority order, or the served ranking model's fixed head with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used."
+ "Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per user to a ranker: the priority order, or the open, action or fixed head of the served ranking model with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used."
),
source_id: zod
.string()
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 cb03efdbc05b..3b6ba0ab590c 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
@@ -75,7 +75,7 @@
"type": "string"
},
"sort": {
- "description": "Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per project to a ranker: the priority order, or the served ranking model's fixed head with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used.",
+ "description": "Inbox sort preset: priority, recommended, last_updated, newest, or oldest. Ignored when ordering is supplied. recommended resolves per user to a ranker: the priority order, or the open, action or fixed head of the served ranking model with unscored and stale reports in priority order after the scored ones. The response's ranker field names the one used.",
"type": "string"
},
"source_id": {