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 monitoring read fallback (#114766)

Mikayla Thompsonbe8df3a258bb
diff --git a/docs/internal/signals-pr-lifecycle.md b/docs/internal/signals-pr-lifecycle.md
index 997368369f61..88795431638e 100644
--- a/docs/internal/signals-pr-lifecycle.md
+++ b/docs/internal/signals-pr-lifecycle.md
@@ -5,6 +5,8 @@ At least one merged PR resolves the report; otherwise all closed PRs suppress it
The schema reserves `monitoring` and a nullable `monitoring_started_at`, but current report transitions do not enter that state. The organization-level `signals-report-monitoring` gate requires explicit enablement, including in local development, and treats evaluation failures as disabled.
+When that gate is disabled, report list, detail, evidence, PR checks, and PR comments reads treat stored Monitoring reports as Resolved. Resolved filters and counts include them, status sorting uses the Resolved position, and their work state is done. The Monitoring gate uses local flag evaluation; a missing or unevaluable definition is disabled. The Monitoring status filter remains unavailable. The `feedback_state` endpoint exposes each person's saved rating for a fallback report. The `viewed` and `feedback` endpoints record consumption evidence without changing the stored status. This compatibility covers reads and their consumption records; status-changing actions and background processing require separate support before any production path can enter Monitoring.
+
Attaching a new open, draft, or unknown PR to a resolved report returns it to ready.
The shared PR-linking service applies this rule to task outputs and agent attachments.
An existing attachment retry does not reopen a report, and importing legacy assignments preserves its status.
diff --git a/products/signals/backend/report_content_gates.py b/products/signals/backend/report_content_gates.py
index c36594525987..4fcb32b12eff 100644
--- a/products/signals/backend/report_content_gates.py
+++ b/products/signals/backend/report_content_gates.py
@@ -24,10 +24,12 @@ REPORT_MONITORING_FLAG = "signals-report-monitoring"
RESEARCH_REVIEWER_SELECTION_FLAG = "signals-research-reviewer-selection"
-def _organization_flag_enabled(flag: str, organization_id: UUID, *, enable_in_debug: bool = True) -> bool:
+def _organization_flag_enabled(
+ flag: str, organization_id: UUID, *, enable_in_debug: bool = True, only_evaluate_locally: bool = False
+) -> bool:
"""Read one organization-keyed rollout flag.
- The flag is evaluated for every call so a flip takes effect immediately. Content flags are on
+ The flag is evaluated for every call. Content flags are on
in DEBUG for local coverage; lifecycle flags can require explicit enablement. It fails closed,
because a flag-service error must not add content to reports of an organization that is not opted in.
"""
@@ -40,6 +42,7 @@ def _organization_flag_enabled(flag: str, organization_id: UUID, *, enable_in_de
groups={"organization": str(organization_id)},
group_properties={"organization": {"id": str(organization_id)}},
send_feature_flag_events=False,
+ only_evaluate_locally=only_evaluate_locally,
)
except Exception:
logger.warning(
@@ -48,7 +51,9 @@ def _organization_flag_enabled(flag: str, organization_id: UUID, *, enable_in_de
return False
-def _team_flag_enabled(flag: str, team_id: int, *, enable_in_debug: bool = True) -> bool:
+def _team_flag_enabled(
+ flag: str, team_id: int, *, enable_in_debug: bool = True, only_evaluate_locally: bool = False
+) -> bool:
"""The `team_id` adapter for callers that hold an id instead of a `Team`, such as a Temporal
activity input. Fails closed, so a team that cannot be read gets no report content."""
if settings.DEBUG and enable_in_debug:
@@ -60,7 +65,9 @@ def _team_flag_enabled(flag: str, team_id: int, *, enable_in_debug: bool = True)
"signals report content flag check could not resolve the team", flag=flag, team_id=team_id, exc_info=True
)
return False
- return _organization_flag_enabled(flag, organization_id, enable_in_debug=enable_in_debug)
+ return _organization_flag_enabled(
+ flag, organization_id, enable_in_debug=enable_in_debug, only_evaluate_locally=only_evaluate_locally
+ )
def organization_report_metrics_enabled(organization_id: UUID) -> bool:
@@ -71,8 +78,14 @@ def team_report_metrics_enabled(team_id: int) -> bool:
return _team_flag_enabled(REPORT_METRICS_FLAG, team_id)
+def organization_report_monitoring_enabled(organization_id: UUID) -> bool:
+ return _organization_flag_enabled(
+ REPORT_MONITORING_FLAG, organization_id, enable_in_debug=False, only_evaluate_locally=True
+ )
+
+
def team_report_monitoring_enabled(team_id: int) -> bool:
- return _team_flag_enabled(REPORT_MONITORING_FLAG, team_id, enable_in_debug=False)
+ return _team_flag_enabled(REPORT_MONITORING_FLAG, team_id, enable_in_debug=False, only_evaluate_locally=True)
def team_research_reviewer_selection_enabled(team_id: int) -> bool:
diff --git a/products/signals/backend/serializers.py b/products/signals/backend/serializers.py
index dc36505d779c..1e660c561c66 100644
--- a/products/signals/backend/serializers.py
+++ b/products/signals/backend/serializers.py
@@ -44,6 +44,7 @@ from products.signals.backend.report_checks import (
MetricThresholdConfig,
parse_check_config,
)
+from products.signals.backend.report_content_gates import team_report_monitoring_enabled
from products.warehouse_sources.backend.facade.models import ExternalDataSchema
from products.warehouse_sources.backend.facade.types import ExternalDataSchemaStatus
@@ -1227,6 +1228,9 @@ class SignalReportPriorityUpdateSerializer(serializers.Serializer):
class SignalReportSerializer(serializers.ModelSerializer):
+ status = serializers.SerializerMethodField(
+ help_text="Current report status. Monitoring reads as resolved when its rollout is disabled.",
+ )
artefact_count = serializers.IntegerField(read_only=True)
charts = ReportChartSerializer(
many=True,
@@ -1441,6 +1445,15 @@ class SignalReportSerializer(serializers.ModelSerializer):
},
}
+ @extend_schema_field(serializers.ChoiceField(choices=SignalReport.Status.choices))
+ def get_status(self, obj: SignalReport) -> str:
+ if obj.status != SignalReport.Status.MONITORING:
+ return obj.status
+ enabled_by_team = cast(dict[int, bool], self.context.setdefault("report_monitoring_enabled_by_team", {}))
+ if obj.team_id not in enabled_by_team:
+ enabled_by_team[obj.team_id] = team_report_monitoring_enabled(obj.team_id)
+ return obj.status if enabled_by_team[obj.team_id] else SignalReport.Status.RESOLVED
+
def _get_actionability_artefact_data(self, obj: SignalReport) -> dict | None:
prefetched = getattr(obj, "prefetched_actionability_artefacts", None)
if prefetched is not None:
@@ -1731,7 +1744,7 @@ class SignalReportSerializer(serializers.ModelSerializer):
@extend_schema_field(serializers.ChoiceField(choices=SignalReportWorkState.choices))
def get_work_state(self, obj: SignalReport) -> str:
- if obj.status == SignalReport.Status.RESOLVED:
+ if self.get_status(obj) == SignalReport.Status.RESOLVED:
return "done"
if any(pr.state in {"open", "draft", "unknown"} for pr in self._get_pull_requests(obj)):
return "in_review"
diff --git a/products/signals/backend/test/test_feedback_scout_notes.py b/products/signals/backend/test/test_feedback_scout_notes.py
index ebd7da5d8dd0..e8700725d1c0 100644
--- a/products/signals/backend/test/test_feedback_scout_notes.py
+++ b/products/signals/backend/test/test_feedback_scout_notes.py
@@ -190,26 +190,52 @@ class TestFeedbackScoutNotes(APIBaseTest):
assert action.count == 2
assert action.metadata == {"sentiment": "negative"}
- @parameterized.expand([("positive", "negative", "ready"), ("negative", "positive", "suppressed")])
- def test_feedback_can_be_read_changed_and_cleared(self, first: str, second: str, report_status: str) -> None:
+ @parameterized.expand(
+ [
+ ("ready", "positive", "negative", SignalReport.Status.READY, False, True),
+ ("suppressed", "negative", "positive", SignalReport.Status.SUPPRESSED, False, True),
+ ("monitoring_disabled", "positive", "negative", SignalReport.Status.MONITORING, False, True),
+ ("monitoring_enabled", "positive", "negative", SignalReport.Status.MONITORING, True, False),
+ ]
+ )
+ def test_feedback_can_be_read_changed_and_cleared(
+ self, _name: str, first: str, second: str, report_status: str, flag_enabled: bool, visible: bool
+ ) -> None:
self._set_task_access("viewer")
report = self._create_report()
report.status = report_status
report.save(update_fields=["status"])
read_url = self._feedback_url(str(report.id)).replace("/feedback/", "/feedback_state/")
- assert self.client.get(read_url).json() == {"sentiment": None, "note": ""}
-
- self._feedback(report, sentiment=first, note="Useful evidence")
- assert self.client.get(read_url).json() == {"sentiment": first, "note": "Useful evidence"}
-
- self._feedback(report, sentiment=second)
- assert self.client.get(read_url).json() == {"sentiment": second, "note": ""}
+ with patch("products.signals.backend.report_content_gates.feature_enabled_or_false", return_value=flag_enabled):
+ initial = self.client.get(read_url)
+ if not visible:
+ assert initial.status_code == status.HTTP_404_NOT_FOUND
+ response = self.client.post(
+ self._feedback_url(str(report.id)),
+ {"sentiment": first, "note": "Useful evidence"},
+ format="json",
+ )
+ assert response.status_code == status.HTTP_404_NOT_FOUND
+ assert not SignalReportAction.objects.for_team(self.team.id).filter(report=report).exists()
+ else:
+ assert initial.status_code == status.HTTP_200_OK
+ assert initial.json() == {"sentiment": None, "note": ""}
+
+ self._feedback(report, sentiment=first, note="Useful evidence")
+ assert self.client.get(read_url).json() == {"sentiment": first, "note": "Useful evidence"}
+
+ self._feedback(report, sentiment=second)
+ assert self.client.get(read_url).json() == {"sentiment": second, "note": ""}
+
+ self._feedback(report, sentiment=None)
+ assert self.client.get(read_url).json() == {"sentiment": None, "note": ""}
+ self._feedback(report, sentiment=None)
+ action = SignalReportAction.objects.for_team(self.team.id).get(report=report, user=self.user)
+ assert action.type == SignalReportAction.ActionType.FEEDBACK
+ assert action.count == 2
- self._feedback(report, sentiment=None)
- assert self.client.get(read_url).json() == {"sentiment": None, "note": ""}
- self._feedback(report, sentiment=None)
- action = SignalReportAction.objects.for_team(self.team.id).get(report=report, user=self.user)
- assert action.count == 2
+ report.refresh_from_db()
+ assert report.status == report_status
def test_feedback_is_private_to_each_user(self) -> None:
report = self._create_report()
diff --git a/products/signals/backend/test/test_report_content_gates.py b/products/signals/backend/test/test_report_content_gates.py
index 445121e12184..9ad9e9c07a8b 100644
--- a/products/signals/backend/test/test_report_content_gates.py
+++ b/products/signals/backend/test/test_report_content_gates.py
@@ -4,10 +4,16 @@ from unittest.mock import patch
from django.test import SimpleTestCase, override_settings
+import posthoganalytics
from parameterized import parameterized
from products.signals.backend.models import InvalidStatusTransition, SignalReport
-from products.signals.backend.report_content_gates import team_report_metrics_enabled, team_report_monitoring_enabled
+from products.signals.backend.report_content_gates import (
+ organization_report_metrics_enabled,
+ organization_report_monitoring_enabled,
+ team_report_metrics_enabled,
+ team_report_monitoring_enabled,
+)
_TEAM_LOOKUP = "products.signals.backend.report_content_gates.Team.objects.values_list"
_FLAG_EVALUATION = "products.signals.backend.report_content_gates.feature_enabled_or_false"
@@ -35,8 +41,26 @@ class TestReportContentGates(SimpleTestCase):
groups={"organization": str(organization_id)},
group_properties={"organization": {"id": str(organization_id)}},
send_feature_flag_events=False,
+ only_evaluate_locally=True,
)
+ @override_settings(DEBUG=False)
+ def test_missing_local_monitoring_flag_fails_closed_without_changing_metrics(self) -> None:
+ organization_id = UUID("00000000-0000-0000-0000-000000000001")
+ sdk = posthoganalytics.Client("phc_test_monitoring", send=False, enable_local_evaluation=False)
+ sdk.feature_flags = []
+ self.addCleanup(sdk.shutdown)
+ with (
+ patch.multiple(posthoganalytics, default_client=sdk, disabled=False),
+ patch(
+ "posthoganalytics.client.flags", return_value={"featureFlags": {"signals-report-metrics": True}}
+ ) as remote_flags,
+ ):
+ assert not organization_report_monitoring_enabled(organization_id)
+ remote_flags.assert_not_called()
+ assert organization_report_metrics_enabled(organization_id)
+ remote_flags.assert_called_once()
+
@override_settings(DEBUG=True)
def test_monitoring_fails_closed_when_flag_evaluation_fails(self) -> None:
with patch(_TEAM_LOOKUP) as team_lookup, patch(_FLAG_EVALUATION, side_effect=RuntimeError("unavailable")):
diff --git a/products/signals/backend/test/test_signal_report_actions.py b/products/signals/backend/test/test_signal_report_actions.py
index 463d4ae6f04e..460a0874f73d 100644
--- a/products/signals/backend/test/test_signal_report_actions.py
+++ b/products/signals/backend/test/test_signal_report_actions.py
@@ -181,12 +181,29 @@ class TestSignalReportViewedEndpoint(APIBaseTest):
if call.kwargs["event"] == "signals_background_report_dismissed"
]
- def test_a_suppressed_report_still_records_its_view(self) -> None:
- # The Dismissed tab renders the same detail view, so its opens must count too instead of
- # 404ing like mutating-by-ID actions on suppressed reports do.
- report = self._create_report(status=SignalReport.Status.SUPPRESSED)
-
- response = self.client.post(self._viewed_url(str(report.pk)))
-
- assert response.status_code == status.HTTP_204_NO_CONTENT
- assert SignalReportAction.objects.for_team(self.team.id).filter(report=report, user=self.user).exists()
+ @parameterized.expand(
+ [
+ ("suppressed", SignalReport.Status.SUPPRESSED, False, True),
+ ("monitoring_disabled", SignalReport.Status.MONITORING, False, True),
+ ("monitoring_enabled", SignalReport.Status.MONITORING, True, False),
+ ]
+ )
+ def test_visible_reports_record_their_views(
+ self, _name: str, report_status: str, flag_enabled: bool, visible: bool
+ ) -> None:
+ report = self._create_report(status=report_status)
+ with patch("products.signals.backend.report_content_gates.feature_enabled_or_false", return_value=flag_enabled):
+ detail = self.client.get(f"/api/projects/{self.team.pk}/signals/reports/{report.pk}/")
+ response = self.client.post(self._viewed_url(str(report.pk)))
+
+ assert detail.status_code == (status.HTTP_200_OK if visible else status.HTTP_404_NOT_FOUND)
+ assert response.status_code == (status.HTTP_204_NO_CONTENT if visible else status.HTTP_404_NOT_FOUND)
+ actions = SignalReportAction.objects.for_team(self.team.id).filter(report=report, user=self.user)
+ if visible:
+ action = actions.get()
+ assert action.type == SignalReportAction.ActionType.VIEW
+ assert action.count == 1
+ else:
+ assert not actions.exists()
+ report.refresh_from_db()
+ assert report.status == report_status
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 97a81d07fda1..65ede3805577 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -16,6 +16,7 @@ from django.test import SimpleTestCase
from django.test.utils import CaptureQueriesContext
from django.utils import timezone
+import posthoganalytics
from parameterized import parameterized
from rest_framework import exceptions, status
from rest_framework.request import Request
@@ -24,7 +25,7 @@ from social_django.models import UserSocialAuth
from posthog.constants import AvailableFeature
from posthog.egress.github.transport import GitHubEgressBudgetExhausted, GitHubRateLimitError
from posthog.egress.limiter.policies import Priority
-from posthog.models import EventDefinition, OAuthApplication, User
+from posthog.models import EventDefinition, OAuthApplication, Organization, User
from posthog.models.integration import GitHubIntegration
from posthog.models.team.team import Team
from posthog.models.user_integration import UserIntegration
@@ -1082,6 +1083,115 @@ class TestSignalReportListAPI(APIBaseTest):
ids = {r["id"] for r in response.json()["results"]}
assert ids == {str(resolved.id)}
+ @parameterized.expand(
+ [("disabled", False), ("enabled", True), ("unavailable", RuntimeError("flag service unavailable"))]
+ )
+ def test_monitoring_read_fallback_matches_resolved_filters_and_counts(
+ self, _name: str, flag_result: bool | Exception
+ ) -> None:
+ monitoring = self._create_report(status=SignalReport.Status.MONITORING, total_weight=99)
+ resolved = self._create_report(status=SignalReport.Status.RESOLVED, total_weight=1)
+ ready = self._create_report(status=SignalReport.Status.READY, total_weight=0)
+ enabled = flag_result is True
+ expected_resolved = {str(resolved.id)} if enabled else {str(monitoring.id), str(resolved.id)}
+ with patch(
+ "products.signals.backend.report_content_gates.feature_enabled_or_false",
+ return_value=flag_result if isinstance(flag_result, bool) else False,
+ side_effect=flag_result if isinstance(flag_result, Exception) else None,
+ ):
+ for query in [{"status": "resolved"}, {"view": "resolved"}]:
+ response = self.client.get(self._list_url(**query))
+ assert response.status_code == status.HTTP_200_OK
+ rows = response.json()["results"]
+ assert {row["id"] for row in rows} == expected_resolved
+ assert all(row["status"] == "resolved" and row["work_state"] == "done" for row in rows)
+ count = self.client.get(self._list_url(**query, count_only="true"))
+ assert count.status_code == status.HTTP_200_OK
+ assert count.json()["count"] == len(expected_resolved)
+
+ unclaimed = self.client.get(self._list_url(unclaimed="true"))
+ assert unclaimed.status_code == status.HTTP_200_OK
+ assert [row["id"] for row in unclaimed.json()["results"]] == [str(ready.id)]
+
+ ordered = self.client.get(self._list_url(ordering="status,-total_weight"))
+ assert ordered.status_code == status.HTTP_200_OK
+ expected_order = [str(ready.id), *([] if enabled else [str(monitoring.id)]), str(resolved.id)]
+ assert [row["id"] for row in ordered.json()["results"]] == expected_order
+
+ detail = self.client.get(f"{self._list_url()}{monitoring.id}/")
+ assert detail.status_code == (status.HTTP_404_NOT_FOUND if enabled else status.HTTP_200_OK)
+ if not enabled:
+ assert detail.json()["status"] == "resolved"
+ assert detail.json()["work_state"] == "done"
+ assert "monitoring_started_at" not in detail.json()
+ evidence = self.client.get(f"{self._list_url()}{monitoring.id}/signals/")
+ assert evidence.status_code == (status.HTTP_404_NOT_FOUND if enabled else status.HTTP_200_OK)
+ if not enabled:
+ assert evidence.json()["report"]["status"] == "resolved"
+ assert evidence.json()["report"]["work_state"] == "done"
+
+ monitoring.refresh_from_db()
+ assert monitoring.status == SignalReport.Status.MONITORING
+
+ def test_monitoring_reads_do_not_evaluate_missing_flags_remotely(self) -> None:
+ report = self._create_report(status=SignalReport.Status.MONITORING)
+ sdk = posthoganalytics.Client("phc_test_monitoring", send=False, enable_local_evaluation=False)
+ sdk.feature_flags = []
+ self.addCleanup(sdk.shutdown)
+ with (
+ patch.multiple(posthoganalytics, default_client=sdk, disabled=False),
+ patch("posthoganalytics.client.flags", return_value={"featureFlags": {}}) as remote_flags,
+ ):
+ response = self.client.get(self._list_url(status="resolved"))
+ assert response.status_code == status.HTTP_200_OK
+ assert [row["id"] for row in response.json()["results"]] == [str(report.id)]
+ count = self.client.get(self._list_url(status="resolved", count_only="true"))
+ assert count.status_code == status.HTTP_200_OK
+ assert count.json()["count"] == 1
+ detail = self.client.get(f"{self._list_url()}{report.id}/")
+ assert detail.status_code == status.HTTP_200_OK
+ assert detail.json()["status"] == "resolved"
+ evidence = self.client.get(f"{self._list_url()}{report.id}/signals/")
+ assert evidence.status_code == status.HTTP_200_OK
+ assert evidence.json()["report"]["status"] == "resolved"
+
+ remote_flags.assert_not_called()
+
+ def test_monitoring_read_fallback_takes_effect_when_the_flag_is_disabled(self) -> None:
+ other_team = Team.objects.create(organization=self.organization)
+ other_monitoring = self._create_report(team=other_team, status=SignalReport.Status.MONITORING)
+ monitoring = self._create_report(status=SignalReport.Status.MONITORING)
+ with patch(
+ "products.signals.backend.report_content_gates.feature_enabled_or_false", return_value=True
+ ) as evaluate:
+ enabled = self.client.get(self._list_url(status="resolved"))
+ assert enabled.status_code == status.HTTP_200_OK
+ assert enabled.json()["results"] == []
+ evaluate.return_value = False
+ disabled = self.client.get(self._list_url(status="resolved"))
+
+ assert disabled.status_code == status.HTTP_200_OK
+ assert [row["id"] for row in disabled.json()["results"]] == [str(monitoring.id)]
+ assert str(other_monitoring.id) not in [row["id"] for row in disabled.json()["results"]]
+
+ def test_monitoring_read_fallback_is_scoped_to_each_organization(self) -> None:
+ other_organization = Organization.objects.create(name="Monitoring test organization")
+ other_organization.members.add(self.user)
+ other_team = Team.objects.create(organization=other_organization)
+ monitoring = self._create_report(status=SignalReport.Status.MONITORING)
+ self._create_report(team=other_team, status=SignalReport.Status.MONITORING)
+
+ def evaluate(flag: str, distinct_id: str, **kwargs: object) -> bool:
+ return distinct_id == str(other_organization.id)
+
+ with patch("products.signals.backend.report_content_gates.feature_enabled_or_false", side_effect=evaluate):
+ disabled = self.client.get(self._list_url(status="resolved"))
+ enabled = self.client.get(f"/api/projects/{other_team.id}/signals/reports/?status=resolved")
+
+ assert disabled.status_code == enabled.status_code == status.HTTP_200_OK
+ assert [row["id"] for row in disabled.json()["results"]] == [str(monitoring.id)]
+ assert enabled.json()["results"] == []
+
@parameterized.expand(
[
("monitoring", "monitoring"),
@@ -4599,20 +4709,43 @@ class TestSignalReportPrEndpoints(APIBaseTest):
@parameterized.expand(
[
- ("checks", "_checks_url", "get_pull_request_checks", "checks"),
- ("comments", "_comments_url", "get_pull_request_comments", "comments"),
+ (f"{endpoint}_{visibility}", url_attr, fetch_name, key, report_status, flag_enabled, expected_status)
+ for endpoint, url_attr, fetch_name, key in [
+ ("checks", "_checks_url", "get_pull_request_checks", "checks"),
+ ("comments", "_comments_url", "get_pull_request_comments", "comments"),
+ ]
+ for visibility, report_status, flag_enabled, expected_status in [
+ ("suppressed", SignalReport.Status.SUPPRESSED, False, status.HTTP_200_OK),
+ ("monitoring_disabled", SignalReport.Status.MONITORING, False, status.HTTP_200_OK),
+ ("monitoring_enabled", SignalReport.Status.MONITORING, True, status.HTTP_404_NOT_FOUND),
+ ]
]
)
- def test_pr_reads_serve_a_suppressed_report(self, _name, url_attr, fetch_name, key):
- # The Archive tab renders the PR panel of a dismissed report, so both read-only PR
- # endpoints must reach a suppressed report by ID like `retrieve` does.
- report = self._create_report(report_status=SignalReport.Status.SUPPRESSED)
- github = patch("products.signals.backend.views.GitHubIntegration.first_for_team_repository").start()
- self.addCleanup(patch.stopall)
- getattr(github.return_value, fetch_name).return_value = {"success": True, key: []}
- response = self.client.get(getattr(self, url_attr)(str(report.id)))
- assert response.status_code == status.HTTP_200_OK
- assert response.json() == {key: []}
+ def test_pr_reads_follow_report_visibility(
+ self,
+ _name: str,
+ url_attr: str,
+ fetch_name: str,
+ key: str,
+ report_status: str,
+ flag_enabled: bool,
+ expected_status: int,
+ ) -> None:
+ report = self._create_report(report_status=report_status)
+ with (
+ patch("products.signals.backend.views.GitHubIntegration.first_for_team_repository") as github,
+ patch("products.signals.backend.report_content_gates.feature_enabled_or_false", return_value=flag_enabled),
+ ):
+ fetch = getattr(github.return_value, fetch_name)
+ fetch.return_value = {"success": True, key: []}
+ response = self.client.get(getattr(self, url_attr)(str(report.id)))
+
+ assert response.status_code == expected_status
+ if expected_status == status.HTTP_200_OK:
+ assert response.json() == {key: []}
+ fetch.assert_called_once_with("PostHog/posthog", 7)
+ else:
+ github.assert_not_called()
def test_pr_checks_maps_upstream_failure_to_502(self):
report = self._create_report()
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index 82daf477fe8c..1f7791cb1ac2 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -168,6 +168,7 @@ from products.signals.backend.report_claims import (
get_active_claims,
reports_with_active_claim,
)
+from products.signals.backend.report_content_gates import organization_report_monitoring_enabled
from products.signals.backend.report_generation.research import ActionabilityChoice
from products.signals.backend.report_generation.resolve_reviewers import (
ReviewerPayloadIndex,
@@ -1417,11 +1418,28 @@ class SignalReportViewSet(
SignalReportBulkStateOutcome.NOT_FOUND: "No report with this id is visible to you.",
}
+ _MONITORING_FALLBACK_READ_ACTIONS = frozenset(
+ {"list", "retrieve", "signals", "viewed", "feedback_state", "feedback", "pr_checks", "pr_comments"}
+ )
+
+ @cached_property
+ def _report_monitoring_enabled(self) -> bool:
+ return organization_report_monitoring_enabled(self.organization.id)
+
+ def _resolved_read_statuses(self) -> frozenset[str]:
+ statuses = frozenset({SignalReport.Status.RESOLVED})
+ if self.action in self._MONITORING_FALLBACK_READ_ACTIONS and not self._report_monitoring_enabled:
+ return statuses | {SignalReport.Status.MONITORING}
+ return statuses
+
def _apply_signal_report_status_filter(self, queryset):
# Always a positive `status__in`, never a negated equality: Postgres can put an IN into the
# `(team, status, promoted_at)` index condition, while `exclude(status=...)` leaves the
# status as a filter that runs on rows the index already made it read.
- return queryset.filter(status__in=sorted(self._visible_statuses()))
+ statuses = self._visible_statuses()
+ if SignalReport.Status.RESOLVED in statuses:
+ statuses |= self._resolved_read_statuses()
+ return queryset.filter(status__in=sorted(statuses))
def _visible_statuses(self) -> frozenset[str]:
status_filter = self.request.query_params.get("status")
@@ -1576,7 +1594,9 @@ class SignalReportViewSet(
return queryset
has_review_pr = implementation_pr_report_filter(team_id=self.team.id, active_only=True)
is_unclaimed = (
- ~Q(status=SignalReport.Status.RESOLVED) & ~reports_with_active_claim(team_id=self.team_id) & ~has_review_pr
+ ~Q(status__in=self._resolved_read_statuses())
+ & ~reports_with_active_claim(team_id=self.team_id)
+ & ~has_review_pr
)
return queryset.filter(is_unclaimed) if wants_unclaimed else queryset.exclude(is_unclaimed)
@@ -1777,7 +1797,7 @@ class SignalReportViewSet(
if inbox_view == "monitoring":
return queryset.filter(status=SignalReport.Status.READY).filter(self._implementation_pr_report_filter())
if inbox_view == "resolved":
- return queryset.filter(status=SignalReport.Status.RESOLVED)
+ return queryset.filter(status__in=self._resolved_read_statuses())
if inbox_view in {"dismissed", "held_back"}:
# Every path that suppresses a report on someone's behalf writes a dismissal artefact: a
# person or agent dismissing it, a merge, a closed pull request. A suppressed report with
@@ -1806,7 +1826,7 @@ class SignalReportViewSet(
When(status=SignalReport.Status.CANDIDATE, then=Value(4)),
When(status=SignalReport.Status.POTENTIAL, then=Value(5)),
When(status=SignalReport.Status.FAILED, then=Value(6)),
- When(status=SignalReport.Status.RESOLVED, then=Value(7)),
+ When(status__in=self._resolved_read_statuses(), then=Value(7)),
When(status=SignalReport.Status.SUPPRESSED, then=Value(8)),
When(status=SignalReport.Status.DELETED, then=Value(9)),
default=Value(50),
@@ -2094,6 +2114,11 @@ class SignalReportViewSet(
return {
**super().get_serializer_context(),
"team": self.team,
+ **(
+ {"report_monitoring_enabled_by_team": {self.team_id: self._report_monitoring_enabled}}
+ if self.action in self._MONITORING_FALLBACK_READ_ACTIONS
+ else {}
+ ),
# For the serializer's refund_ineligibility_reason field — computed once per request,
# not per report (the bounds are org-level).
"billing_period_bounds": current_billing_period_bounds(self.organization),
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index b9cd60c70f43..a6dcd3f00317 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -131,18 +131,6 @@ export interface PauseResponseApi {
paused_until: string
}
-/**
- * * `potential` - Potential
- * * `candidate` - Candidate
- * * `in_progress` - In Progress
- * * `pending_input` - Pending Input
- * * `ready` - Ready
- * * `monitoring` - Monitoring
- * * `resolved` - Resolved
- * * `failed` - Failed
- * * `deleted` - Deleted
- * * `suppressed` - Suppressed
- */
export type SignalReportStatusEnumApi = (typeof SignalReportStatusEnumApi)[keyof typeof SignalReportStatusEnumApi]
export const SignalReportStatusEnumApi = {
@@ -672,6 +660,7 @@ export interface SignalReportListApi {
readonly summary: string | null
/** The opening of `summary` as plain text on one line: the text before its first section heading, with chart links removed and other links reduced to their text. At most 450 characters. */
readonly summary_lead: string
+ /** Current report status. Monitoring reads as resolved when its rollout is disabled. */
readonly status: SignalReportStatusEnumApi
readonly total_weight: number
readonly signal_count: number
@@ -910,6 +899,7 @@ export interface SignalReportApi {
readonly summary: string | null
/** The opening of `summary` as plain text on one line: the text before its first section heading, with chart links removed and other links reduced to their text. At most 450 characters. */
readonly summary_lead: string
+ /** Current report status. Monitoring reads as resolved when its rollout is disabled. */
readonly status: SignalReportStatusEnumApi
readonly total_weight: number
readonly signal_count: number
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 86036e83dc78..9e928e63e3f9 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -73240,18 +73240,6 @@ export namespace Schemas {
results: SignalReportCheck[];
}
- /**
- * * `potential` - Potential
- * * `candidate` - Candidate
- * * `in_progress` - In Progress
- * * `pending_input` - Pending Input
- * * `ready` - Ready
- * * `monitoring` - Monitoring
- * * `resolved` - Resolved
- * * `failed` - Failed
- * * `deleted` - Deleted
- * * `suppressed` - Suppressed
- */
export type SignalReportStatusEnum = typeof SignalReportStatusEnum[keyof typeof SignalReportStatusEnum];
@@ -73647,6 +73635,7 @@ export namespace Schemas {
readonly summary: string | null;
/** The opening of `summary` as plain text on one line: the text before its first section heading, with chart links removed and other links reduced to their text. At most 450 characters. */
readonly summary_lead: string;
+ /** Current report status. Monitoring reads as resolved when its rollout is disabled. */
readonly status: SignalReportStatusEnum;
readonly total_weight: number;
readonly signal_count: number;
@@ -95331,6 +95320,7 @@ export namespace Schemas {
readonly summary: string | null;
/** The opening of `summary` as plain text on one line: the text before its first section heading, with chart links removed and other links reduced to their text. At most 450 characters. */
readonly summary_lead: string;
+ /** Current report status. Monitoring reads as resolved when its rollout is disabled. */
readonly status: SignalReportStatusEnum;
readonly total_weight: number;
readonly signal_count: number;