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): let personal rankings read summaries of every generated organization (#128469)

posthog[bot]127f040d32c6
diff --git a/products/signals/backend/activity_summary/queue.py b/products/signals/backend/activity_summary/queue.py
index d3f2798933f3..037e51aa5abe 100644
--- a/products/signals/backend/activity_summary/queue.py
+++ b/products/signals/backend/activity_summary/queue.py
@@ -236,6 +236,15 @@ class Enrollment:
team_organization_ids: dict[int, uuid.UUID] = dataclasses.field(default_factory=dict)
+def _unblocked_teams(config: ActivitySummaryConfig, teams: QuerySet[Team]) -> QuerySet[Team]:
+ """The teams of `teams` that AI data processing approval, `skip_team_ids` and the denylist keep."""
+ return (
+ teams.filter(organization__is_ai_data_processing_approved=True)
+ .exclude(id__in=config.skip_team_ids)
+ .exclude(organization_id__in=_parse_organization_ids(config.deny_organization_ids))
+ )
+
+
def enrollment(config: ActivitySummaryConfig) -> Enrollment:
"""The teams that `is_team_enrolled_for_generation` enrolls, in a fixed number of queries."""
if not config.enabled:
@@ -245,11 +254,7 @@ def enrollment(config: ActivitySummaryConfig) -> Enrollment:
)
listed = _parse_organization_ids(config.organization_ids)
- teams = (
- Team.objects.filter(organization__is_ai_data_processing_approved=True)
- .exclude(id__in=config.skip_team_ids)
- .exclude(organization_id__in=_parse_organization_ids(config.deny_organization_ids))
- )
+ teams = _unblocked_teams(config, Team.objects.all())
# The teams with an enabled source come first, because they are far fewer than the approved teams.
with_source: dict[int, uuid.UUID] = dict(
teams.filter(id__in=team_ids_with_enabled_source()).values_list("id", "organization_id")
@@ -312,25 +317,20 @@ def is_team_enrolled_for_generation(config: ActivitySummaryConfig, team: Team) -
def is_team_enrolled_for_read(config: ActivitySummaryConfig, team: Team) -> bool:
- """The API and MCP tools read summaries only for these teams. The percentage rollout and the denylist do not apply.
+ """The API, the MCP tools and personal ranking read summaries only for these teams.
- A disabled config enrolls no team.
+ Read enrollment is generation enrollment, so every generated summary is readable.
"""
- if not config.enabled or team.id in config.skip_team_ids:
- return False
- if team.organization.is_ai_data_processing_approved is not True:
- return False
- return config.enroll_all_approved or team.organization_id in _parse_organization_ids(config.organization_ids)
+ return is_team_enrolled_for_generation(config, team)
def read_enrolled_teams(config: ActivitySummaryConfig, teams: QuerySet[Team]) -> QuerySet[Team]:
- """The teams of `teams` that `is_team_enrolled_for_read` enrolls, in one query."""
+ """The teams of `teams` that `is_team_enrolled_for_read` enrolls, in a fixed number of queries."""
if not config.enabled:
return teams.none()
- teams = teams.filter(organization__is_ai_data_processing_approved=True).exclude(id__in=config.skip_team_ids)
if config.enroll_all_approved:
- return teams
- return teams.filter(organization_id__in=_parse_organization_ids(config.organization_ids))
+ return _unblocked_teams(config, teams)
+ return teams.filter(id__in=enrollment(config).team_ids)
_parse_organization_ids = org_rollout.parse_organization_ids
diff --git a/products/signals/backend/management/AGENTS.md b/products/signals/backend/management/AGENTS.md
index 34faf23bf665..2c363770a618 100644
--- a/products/signals/backend/management/AGENTS.md
+++ b/products/signals/backend/management/AGENTS.md
@@ -338,7 +338,7 @@ The `tick` object of the `personal-inbox-ranking` payload holds its levers. With
}
```
-- **Enrollment:** every project of the listed organizations, plus the salted `self_driving_organization_percentage` of the organizations with a project that has an enabled signal source. The percentage enrolls only those projects, and a higher percentage keeps the organizations of a lower one. The organization must approve AI data processing, and the activity summary must be readable for the project. The deny list and `skip_team_ids` win. Enrollment decides who gets scheduled builds. It does not change who can read `for_me`.
+- **Enrollment:** every project of the listed organizations, plus the salted `self_driving_organization_percentage` of the organizations with a project that has an enabled signal source. The percentage enrolls only those projects, and a higher percentage keeps the organizations of a lower one. The organization must approve AI data processing, and the activity summary must be readable for the project. A summary is readable for every project that activity summary generation enrolls, including its own percentage rollout. The deny list and `skip_team_ids` win. Enrollment decides who gets scheduled builds. It does not change who can read `for_me`.
- **Due pairs:** a member with a ready activity summary, activity in the last `active_days`, and a latest list that was built or checked longer ago than `target_interval_minutes`, or no list.
- **Order:** paying organizations first, then the most recent activity, then the oldest list. One organization takes at most `max_org_share` of `max_pairs_per_tick`.
- **Unchanged inputs:** the pair activity compares the input hash first. A match calls no model and sets `checked_at` on the latest row, so the pair is not due again until `target_interval_minutes` passes, and `for_me` serves that row as fresh. An enabled tick raises `freshness_minutes` to at least `target_interval_minutes`, so a plain read does not rebuild a list inside the tick's interval. A row whose model call failed, timed out or answered outside the schema, or that skipped the model without AI approval, is built again instead.
diff --git a/products/signals/backend/test/test_activity_summary_api.py b/products/signals/backend/test/test_activity_summary_api.py
index 80e7e03b23c4..ae4f8a393011 100644
--- a/products/signals/backend/test/test_activity_summary_api.py
+++ b/products/signals/backend/test/test_activity_summary_api.py
@@ -130,16 +130,6 @@ class TestActivitySummaryAPI(APIBaseTest):
assert self._get().status_code == 404
assert self._get("versions/").status_code == 404
- def test_read_access_does_not_follow_the_generation_check(self) -> None:
- self._versions(1)
- self.config = dataclasses.replace(self.config, skip_team_ids=(self.team.id,))
-
- with patch(
- "products.signals.backend.activity_summary.queue.is_team_enrolled_for_generation", return_value=True
- ):
- assert self._get().status_code == 404
- assert self._get("versions/").status_code == 404
-
def test_enroll_all_approved_enrolls_an_unlisted_organization(self) -> None:
self.config = ActivitySummaryConfig(enabled=True, enroll_all_approved=True)
self._summary()
diff --git a/products/signals/backend/test/test_activity_summary_tick.py b/products/signals/backend/test/test_activity_summary_tick.py
index 24af42a89c51..22d1b033356c 100644
--- a/products/signals/backend/test/test_activity_summary_tick.py
+++ b/products/signals/backend/test/test_activity_summary_tick.py
@@ -57,6 +57,7 @@ from products.signals.backend.activity_summary.queue import (
max_update_cost_usd,
mcp_buffer_team_ids,
organization_rollout_bucket,
+ read_enrolled_teams,
seed_queue,
select_pairs,
)
@@ -553,20 +554,19 @@ class TestActivitySummaryQueue(BaseTest):
@parameterized.expand(
[
- ("listed", {}, True, False, True, True),
- ("disabled", {"enabled": False}, True, False, False, False),
- ("not_listed", {"organization_ids": ("00000000-0000-0000-0000-000000000001",)}, True, False, False, False),
- ("invalid_listed_id", {"organization_ids": ("not-a-uuid",)}, True, False, False, False),
- ("team_skipped", {"skip_team_ids": ("own",)}, True, False, False, False),
- ("not_approved", {}, False, False, False, False),
- ("all_approved", {"organization_ids": (), "enroll_all_approved": True}, True, False, True, True),
+ ("listed", {}, True, False, True),
+ ("disabled", {"enabled": False}, True, False, False),
+ ("not_listed", {"organization_ids": ("00000000-0000-0000-0000-000000000001",)}, True, False, False),
+ ("invalid_listed_id", {"organization_ids": ("not-a-uuid",)}, True, False, False),
+ ("team_skipped", {"skip_team_ids": ("own",)}, True, False, False),
+ ("not_approved", {}, False, False, False),
+ ("all_approved", {"organization_ids": (), "enroll_all_approved": True}, True, False, True),
(
"all_approved_not_approved",
{"organization_ids": (), "enroll_all_approved": True},
False,
False,
False,
- False,
),
(
"all_approved_team_skipped",
@@ -574,15 +574,13 @@ class TestActivitySummaryQueue(BaseTest):
True,
False,
False,
- False,
),
- ("listed_and_denied", {"deny_organization_ids": ("own",)}, True, True, True, False),
+ ("listed_and_denied", {"deny_organization_ids": ("own",)}, True, True, False),
(
"all_approved_and_denied",
{"enroll_all_approved": True, "deny_organization_ids": ("own",)},
True,
True,
- True,
False,
),
(
@@ -590,7 +588,6 @@ class TestActivitySummaryQueue(BaseTest):
{"organization_ids": (), "self_driving_organization_percentage": 100.0},
True,
True,
- False,
True,
),
(
@@ -599,7 +596,6 @@ class TestActivitySummaryQueue(BaseTest):
True,
False,
False,
- False,
),
(
"rollout_at_zero",
@@ -607,7 +603,6 @@ class TestActivitySummaryQueue(BaseTest):
True,
True,
False,
- False,
),
(
"rollout_disabled",
@@ -615,7 +610,6 @@ class TestActivitySummaryQueue(BaseTest):
True,
True,
False,
- False,
),
(
"rollout_denied",
@@ -627,7 +621,6 @@ class TestActivitySummaryQueue(BaseTest):
True,
True,
False,
- False,
),
(
"rollout_team_skipped",
@@ -635,7 +628,6 @@ class TestActivitySummaryQueue(BaseTest):
True,
True,
False,
- False,
),
(
"rollout_not_approved",
@@ -643,7 +635,6 @@ class TestActivitySummaryQueue(BaseTest):
False,
True,
False,
- False,
),
]
)
@@ -653,8 +644,7 @@ class TestActivitySummaryQueue(BaseTest):
overrides: dict[str, Any],
approved: bool,
has_source: bool,
- readable: bool,
- generated: bool,
+ enrolled: bool,
) -> None:
self.organization.is_ai_data_processing_approved = approved
self.organization.save()
@@ -670,9 +660,10 @@ class TestActivitySummaryQueue(BaseTest):
config = dataclasses.replace(self._config(), **overrides)
team = Team.objects.get(id=self.team.id)
- assert is_team_enrolled_for_read(config, team) is readable
- assert is_team_enrolled_for_generation(config, team) is generated
- assert (self.team.id in enrolled_team_ids(config)) is generated
+ assert is_team_enrolled_for_read(config, team) is enrolled
+ assert is_team_enrolled_for_generation(config, team) is enrolled
+ assert (self.team.id in enrolled_team_ids(config)) is enrolled
+ assert read_enrolled_teams(config, Team.objects.filter(id=self.team.id)).exists() is enrolled
if config.self_driving_organization_percentage and not config.organization_ids:
assert sourceless.id not in enrolled_team_ids(config)
diff --git a/products/signals/backend/test/test_personal_ranking_tick.py b/products/signals/backend/test/test_personal_ranking_tick.py
index 489cf4360cbd..f873d59e47cf 100644
--- a/products/signals/backend/test/test_personal_ranking_tick.py
+++ b/products/signals/backend/test/test_personal_ranking_tick.py
@@ -28,6 +28,7 @@ from products.signals.backend.models import (
PersonalInboxRanking,
SignalReport,
SignalReportAssignment,
+ SignalSourceConfig,
UserActivitySummary,
UserActivitySummaryQueueState,
)
@@ -61,6 +62,7 @@ class _TickTest(BaseTest):
self.tick: dict[str, Any] = {"enabled": True, "organization_ids": [str(self.organization.id)]}
self.payload: dict[str, Any] = {}
self.source_team_ids: set[int] = set()
+ self.activity_summary_config = ActivitySummaryConfig(enabled=True, enroll_all_approved=True)
for target, value in (
(
"products.signals.backend.personal_ranking.config.read_flag_payload",
@@ -68,7 +70,7 @@ class _TickTest(BaseTest):
),
(
f"{_TICK}.read_activity_summary_config",
- MagicMock(return_value=ActivitySummaryConfig(enabled=True, enroll_all_approved=True)),
+ MagicMock(side_effect=lambda: self.activity_summary_config),
),
(f"{_TICK}.team_ids_with_enabled_source", MagicMock(side_effect=lambda: self.source_team_ids)),
(f"{_TICK}.has_enabled_source", MagicMock(side_effect=lambda team_id: team_id in self.source_team_ids)),
@@ -117,6 +119,13 @@ class TestTickEnrollment(_TickTest):
("a_denied_organization", {"deny": True}, False, True, False),
("a_skipped_team", {"skip": True}, False, True, False),
("every_team_with_a_source_at_100", {"organization_ids": [], "percentage": 100}, True, True, True),
+ (
+ "a_team_with_a_summary_from_the_summary_rollout",
+ {"organization_ids": [], "percentage": 100, "summary_rollout": True},
+ True,
+ True,
+ True,
+ ),
("no_team_without_a_source_at_100", {"organization_ids": [], "percentage": 100}, False, True, False),
("the_tick_off", {"enabled": False}, True, True, False),
]
@@ -128,6 +137,11 @@ class TestTickEnrollment(_TickTest):
self.organization.save()
if has_source:
self.source_team_ids = {self.team.id}
+ if overrides.get("summary_rollout"):
+ SignalSourceConfig.objects.create(
+ team=self.team, source_product="error_tracking", source_type="issue_created", enabled=True
+ )
+ self.activity_summary_config = ActivitySummaryConfig(enabled=True, self_driving_organization_percentage=100)
self.tick = {
**self.tick,
"enabled": overrides.get("enabled", True),