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): cap personal ranking tiers (#126635)

posthog[bot]38a7971b8448
diff --git a/products/signals/backend/management/AGENTS.md b/products/signals/backend/management/AGENTS.md
index c555018087e7..3dd76a52a796 100644
--- a/products/signals/backend/management/AGENTS.md
+++ b/products/signals/backend/management/AGENTS.md
@@ -271,6 +271,7 @@ Idempotent. A reactivated check no longer matches.
It reads its limits from the `personal-inbox-ranking` flag payload, and `"enabled": false` there stops every build.
It prints the effective config first: the model, `reasoning_effort`, `rank_top`, `max_candidates`, `timeout_seconds` and `max_completion_tokens`.
The model ranks only the best `rank_top` candidates. The other candidates follow in model order, with `ranked_by: model`.
+At most `top_max` entries (default 5) get the `top` tier and at most `worth_a_look_max` (default 10) get `worth_a_look`. An entry past a cap moves down to the next tier with room and keeps its rank.
```bash
# Call the model, but store no PersonalInboxRanking row and capture no event
diff --git a/products/signals/backend/personal_ranking/config.py b/products/signals/backend/personal_ranking/config.py
index d0ad30115884..7f41ec596895 100644
--- a/products/signals/backend/personal_ranking/config.py
+++ b/products/signals/backend/personal_ranking/config.py
@@ -98,6 +98,9 @@ class PersonalRankingConfig:
max_candidates: int = 30
# The model ranks only this many candidates. The others follow in model order. At most `max_limit`.
rank_top: int = 10
+ # The most entries in each tier. The validator moves an entry past a cap down one tier and keeps its rank.
+ top_max: int = 5
+ worth_a_look_max: int = 10
# The entries that get a `next_step`, and the most a caller can ask for.
default_limit: int = 25
max_limit: int = 50
@@ -130,6 +133,8 @@ _MAXIMUMS: dict[str, int] = {
"max_candidates": 100,
"pool_size": 100,
"rank_top": 100,
+ "top_max": 50,
+ "worth_a_look_max": 100,
"default_limit": 100,
"max_limit": 100,
"next_step_max_chars": 400,
diff --git a/products/signals/backend/personal_ranking/logic.py b/products/signals/backend/personal_ranking/logic.py
index d9a265f0fa61..1a700ba2f5d8 100644
--- a/products/signals/backend/personal_ranking/logic.py
+++ b/products/signals/backend/personal_ranking/logic.py
@@ -30,6 +30,7 @@ from products.signals.backend.personal_ranking.config import PersonalRankingConf
from products.signals.backend.personal_ranking.prompt import (
PROMPT_VERSION,
RESPONSE_FORMAT,
+ TIERS,
render_person,
system_prompt,
user_message,
@@ -275,6 +276,7 @@ def _capture(
"candidate_count": len(build.candidates),
"ranked_by_llm_count": sum(1 for entry in build.entries if entry.ranked_by == "llm"),
"folded_count": len(build.folded),
+ "tier_counts": {tier: sum(1 for entry in build.entries if entry.tier == tier) for tier in TIERS},
"pool_counts": pools,
**dataclasses.asdict(build.counts),
"tokens_in": build.tokens_in,
@@ -376,6 +378,8 @@ def build_personal_ranking(
model_reasons=model_reasons,
limit=limit,
rank_top=config.rank_top,
+ top_max=config.top_max,
+ worth_a_look_max=config.worth_a_look_max,
reason_limits=config.reason_limits,
next_step_max_chars=config.next_step_max_chars,
)
@@ -390,7 +394,9 @@ def build_personal_ranking(
status=status,
personalized=validated is not None and summary_ready,
fallback_reason=fallback_reason,
- entries=validated.entries if validated is not None else model_order(refs, model_reasons, limit),
+ entries=validated.entries
+ if validated is not None
+ else model_order(refs, model_reasons, min(limit, config.worth_a_look_max)),
folded=validated.folded if validated is not None else (),
candidates=tuple(candidates),
counts=validated.counts if validated is not None else ValidationCounts(),
diff --git a/products/signals/backend/personal_ranking/prompt.py b/products/signals/backend/personal_ranking/prompt.py
index c2ec11b6bd61..8b3b6720de99 100644
--- a/products/signals/backend/personal_ranking/prompt.py
+++ b/products/signals/backend/personal_ranking/prompt.py
@@ -12,7 +12,7 @@ from products.signals.backend.activity_summary.read import ActivitySummaryStatus
from products.signals.backend.personal_ranking.candidates import Candidate, NeedsYouKind
from products.signals.backend.personal_ranking.config import PersonalRankingConfig
-PROMPT_VERSION = 4
+PROMPT_VERSION = 5
Tier = Literal["top", "worth_a_look", "later"]
TIERS: tuple[Tier, ...] = get_args(Tier)
@@ -94,7 +94,7 @@ The person block is an activity summary built from their recent PostHog activity
- Themes are their recent areas of work. A strong theme seen recently counts more than a weak or old one.
- Owns lists objects they made or keep changing. Watches lists objects they keep opening. A report about an object they own matters more than one they only watch.
- Works in lists the PostHog products they use most.
-When no activity summary is available, rank on the needs-you facts, priority and the model's lift.
+When no activity summary is available, rank on the needs-you facts and the model's lift.
The `model` line of a report holds the ranking model's predictions for three outcomes:
- `open`: someone opens the report.
@@ -106,13 +106,13 @@ Read every candidate. Rank only the best {config.rank_top}, fold the duplicates,
To pick and order the best {config.rank_top}:
- Put first the reports that need this person: waiting on their input, claimed by them, or naming them as suggested reviewer.
- Then the reports that match their themes, the objects they own or watch, and the products they work in.
-- Use priority and the ranking model's lift as evidence of value. Prefer lift to the raw probability. A report with an open pull request is cheap to finish.
+- Use the ranking model's lift as evidence of value. Prefer lift to the raw probability. A report with an open pull request is cheap to finish.
- Old reports with no activity and reports far from their work go last.
- When the person has a focus, it outranks their usual themes.
Output:
- `ranked`: at most {config.rank_top} entries, the best candidates that you do not fold, with `ref` (such as "c3"), `rank` (1 is first, no gaps, no repeats) and `tier`.
-- `tier`: "top" for the few they should look at today, "worth_a_look" for the rest of the useful reports, "later" for the rest. A lower rank never has a better tier.
+- `tier`: "top" for at most {config.top_max} reports they should look at today. A "top" report needs a needs-you fact, a match to one of their themes, an object they own, or the focus. "worth_a_look" for at most {config.worth_a_look_max} other useful reports. "later" for the rest. A lower rank never has a better tier.
- `reason`: why this rank, in plain words. Name the theme, object, product or needs-you fact that matched. Never quote the profile. At most {reasons.top} characters for "top", {reasons.worth_a_look} for "worth_a_look", {reasons.later} for "later". Every entry needs a reason.
- `matched`: the theme label that matched (as written in the person block) and the needs-you kinds that apply, or null when nothing matched.
- `next_step`: one short action for ranks 1 to {min(limit, config.rank_top)}, at most {config.next_step_max_chars} characters, else null.
@@ -152,7 +152,7 @@ def _works_in(computed: dict[str, Any] | None) -> list[str]:
def render_person(summary: ActivitySummaryView | None, config: PersonalRankingConfig) -> str:
if summary is None or summary.status != ActivitySummaryStatus.READY:
- return "No activity summary for this person. Rank on the needs-you facts, priority and the ranking model."
+ return "No activity summary for this person. Rank on the needs-you facts and the ranking model."
lines = []
if summary.headline:
lines.append(f"Headline: {summary.headline}")
diff --git a/products/signals/backend/personal_ranking/validation.py b/products/signals/backend/personal_ranking/validation.py
index 35ef6971bfa1..77b8e5b734b7 100644
--- a/products/signals/backend/personal_ranking/validation.py
+++ b/products/signals/backend/personal_ranking/validation.py
@@ -6,6 +6,7 @@ and every other unfolded candidate follows in model order.
"""
import json
+from collections import Counter
from collections.abc import Mapping, Sequence
from typing import Any, Literal
@@ -58,6 +59,8 @@ class ValidationCounts:
# Ranked entries past `rank_top`. They follow in model order too.
beyond_rank_top: int = 0
tier_corrections: int = 0
+ # Entries past the cap of their tier. Each moves down to the next tier with room and keeps its rank.
+ tier_demotions: int = 0
# Folds of an unknown ref, into an unknown or folded ref, or into the ref itself.
invalid_folds: int = 0
@@ -188,6 +191,8 @@ def validate_ranking(
model_reasons: Mapping[str, str],
limit: int,
rank_top: int,
+ top_max: int,
+ worth_a_look_max: int,
reason_limits: ReasonLimits,
next_step_max_chars: int,
) -> ValidatedRanking:
@@ -212,15 +217,24 @@ def validate_ranking(
top = kept[:rank_top]
ranked_refs = {entry.ref for entry in top}
+ caps: dict[Tier, int] = {"top": top_max, "worth_a_look": worth_a_look_max}
+ tier_sizes: Counter[Tier] = Counter()
entries: list[RankedEntry] = []
- renumbered = tier_corrections = 0
- worst_tier = 0
+ renumbered = tier_corrections = tier_demotions = 0
+ # Corrections follow the model's own tiers, so a demotion is not counted again as a correction.
+ worst_corrected = worst_tier = 0
for rank, entry in enumerate(top, start=1):
renumbered += entry.rank != rank
- tier_index = max(TIERS.index(entry.tier), worst_tier)
- tier_corrections += tier_index != TIERS.index(entry.tier)
+ corrected_index = max(TIERS.index(entry.tier), worst_corrected)
+ tier_corrections += corrected_index != TIERS.index(entry.tier)
+ worst_corrected = corrected_index
+ tier_index = max(corrected_index, worst_tier)
+ while TIERS[tier_index] in caps and tier_sizes[TIERS[tier_index]] >= caps[TIERS[tier_index]]:
+ tier_index += 1
+ tier_demotions += tier_index != corrected_index
worst_tier = tier_index
tier = TIERS[tier_index]
+ tier_sizes[tier] += 1
reason = entry.reason.strip() or model_reasons[entry.ref]
entries.append(
RankedEntry(
@@ -257,6 +271,7 @@ def validate_ranking(
missing_refs=len(missing) - (len(kept) - len(top)),
beyond_rank_top=len(kept) - len(top),
tier_corrections=tier_corrections,
+ tier_demotions=tier_demotions,
invalid_folds=invalid_folds,
),
)
diff --git a/products/signals/backend/test/test_personal_ranking.py b/products/signals/backend/test/test_personal_ranking.py
index 4465be84d25b..a814c791f1e5 100644
--- a/products/signals/backend/test/test_personal_ranking.py
+++ b/products/signals/backend/test/test_personal_ranking.py
@@ -42,7 +42,7 @@ from products.signals.backend.personal_ranking.config import (
parse_config,
)
from products.signals.backend.personal_ranking.logic import BUILT_EVENT, build_personal_ranking
-from products.signals.backend.personal_ranking.prompt import render_person, user_message
+from products.signals.backend.personal_ranking.prompt import render_person, system_prompt, user_message
from products.signals.backend.personal_ranking.validation import MalformedRankingError, validate_ranking
from products.signals.backend.personal_ranking_tasks import build_lock_key, build_personal_inbox_ranking
from products.signals.backend.ranking.report_predictions import OutcomePrediction, ReportPredictions
@@ -60,13 +60,15 @@ def _answer(ranked: list[dict], folded: list[dict] | None = None) -> str:
return json.dumps({"ranked": ranked, "folded": folded or []})
-def _validate(content: str | None, limit: int = 2, rank_top: int = 10):
+def _validate(content: str | None, limit: int = 2, rank_top: int = 10, top_max: int = 5, worth_a_look_max: int = 10):
return validate_ranking(
content,
refs=REFS,
model_reasons=MODEL_REASONS,
limit=limit,
rank_top=rank_top,
+ top_max=top_max,
+ worth_a_look_max=worth_a_look_max,
reason_limits=LIMITS,
next_step_max_chars=12,
)
@@ -178,6 +180,45 @@ class TestValidateRanking(SimpleTestCase):
assert [entry.next_step for entry in result.entries] == ["open the PR…", "look", None, None]
assert result.entries[3].reason == "model c4"
+ @parameterized.expand(
+ [
+ (
+ "full_top_spills_into_worth_a_look",
+ ["top"] * 4,
+ 1,
+ 2,
+ ["top", "worth_a_look", "worth_a_look", "later"],
+ 3,
+ ),
+ (
+ "full_worth_a_look_spills_into_later",
+ ["top", "top", "top", "worth_a_look"],
+ 2,
+ 1,
+ ["top", "top", "worth_a_look", "later"],
+ 2,
+ ),
+ ]
+ )
+ def test_entries_past_a_tier_cap_move_down_and_keep_their_rank(
+ self,
+ _name: str,
+ tiers: list[str],
+ top_max: int,
+ worth_a_look_max: int,
+ expected_tiers: list[str],
+ expected_demotions: int,
+ ) -> None:
+ ranked = [_entry(ref, rank, tier=tier) for rank, (ref, tier) in enumerate(zip(REFS, tiers), start=1)]
+
+ result = _validate(_answer(ranked), top_max=top_max, worth_a_look_max=worth_a_look_max)
+
+ assert [(entry.ref, entry.rank, entry.tier) for entry in result.entries] == [
+ (ref, rank, tier) for rank, (ref, tier) in enumerate(zip(REFS, expected_tiers), start=1)
+ ]
+ assert result.counts.tier_demotions == expected_demotions
+ assert result.counts.tier_corrections == 0
+
@parameterized.expand(
[
("empty", None),
@@ -247,6 +288,12 @@ class TestPrompt(SimpleTestCase):
assert "p" * 100 in message and "p" * 101 not in message
assert "- Checkout (mode build, strength strong, last seen 2026-10-29)" in message
+ def test_system_prompt_states_the_tier_caps(self) -> None:
+ prompt = system_prompt(PersonalRankingConfig(top_max=3, worth_a_look_max=7), limit=25)
+
+ assert '"top" for at most 3 reports' in prompt
+ assert '"worth_a_look" for at most 7 other' in prompt
+
class TestConfig(SimpleTestCase):
@parameterized.expand(
@@ -471,6 +518,7 @@ class TestBuildPersonalRanking(BaseTest):
assert event["event"] == BUILT_EVENT
assert event["properties"]["ranking_id"] == str(row.id)
assert event["properties"]["personalized"] is with_summary
+ assert event["properties"]["tier_counts"] == {"top": 0, "worth_a_look": 2, "later": 1}
serialized = json.dumps(event["properties"])
assert "Waiting" not in serialized and "reason c" not in serialized and "checkout" not in serialized