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.

fix(notifications): notify on any actionable report, add debug logs (#64780)

Joshua Snyderb11b2cd7fdf4
diff --git a/products/signals/backend/slack_inbox_notifications.py b/products/signals/backend/slack_inbox_notifications.py
index 0166b8c9bd51..c6b120306673 100644
--- a/products/signals/backend/slack_inbox_notifications.py
+++ b/products/signals/backend/slack_inbox_notifications.py
@@ -1,10 +1,11 @@
"""Slack notifications for signals inbox items.
-Each suggested reviewer on a ready report is routed to exactly one Slack channel:
-their own configured channel if they set one (filtered by their min-priority),
-otherwise the team-default channel, otherwise nowhere. Reviewers sharing a channel —
-notably everyone falling back to the team default — get a single post that mentions
-only the reviewers routed there. A report with no resolvable reviewers posts nothing.
+Mirrors the inbox Reports tab's actionability gate: a report notifies only if it's actionable
+(its latest actionability judgment is immediately_actionable or requires_human_input) — READY is
+enforced upstream — and has at least one suggested reviewer that resolves to a destination.
+Each reviewer is routed to one channel: their own configured channel if set (filtered by their
+min-priority), otherwise the team-default channel. Reviewers sharing a channel get a single post
+mentioning only the reviewers routed there. A report with no resolvable reviewer sends nothing.
All sends are best-effort.
"""
@@ -29,12 +30,19 @@ from products.signals.backend.models import (
SignalTeamConfig,
SignalUserAutonomyConfig,
)
+from products.signals.backend.report_generation.research import ActionabilityChoice
from products.signals.backend.report_generation.resolve_reviewers import (
enrich_reviewer_dicts_with_org_members,
normalized_github_logins_from_suggested_reviewer_artefacts,
resolve_org_github_login_to_users,
)
+# Actionability values shown in the inbox Reports tab. Slack notifications mirror that tab, so a
+# report notifies iff its latest actionability judgment is one of these (and it's READY).
+_ACTIONABLE_VALUES = frozenset(
+ {ActionabilityChoice.IMMEDIATELY_ACTIONABLE.value, ActionabilityChoice.REQUIRES_HUMAN_INPUT.value}
+)
+
logger = logging.getLogger(__name__)
_SUMMARY_EXCERPT_MAX_LEN = 600
@@ -136,6 +144,24 @@ def _latest_priority(report: SignalReport) -> str | None:
return value if isinstance(value, str) else None
+def _latest_actionability(report: SignalReport) -> str | None:
+ art = (
+ report.artefacts.filter(type=SignalReportArtefact.ArtefactType.ACTIONABILITY_JUDGMENT)
+ .order_by("-created_at")
+ .first()
+ )
+ if art is None:
+ return None
+ try:
+ data = json.loads(art.content)
+ except (json.JSONDecodeError, TypeError, ValueError):
+ return None
+ if not isinstance(data, dict):
+ return None
+ value = data.get("actionability")
+ return value if isinstance(value, str) else None
+
+
def _resolve_suggested_reviewer_user_ids(report: SignalReport) -> set[int]:
"""Resolve the suggested-reviewer GitHub logins on the report to PostHog user IDs.
@@ -550,10 +576,11 @@ def _build_reviewer_routes(
) -> list[_ChannelRoute]:
"""Route each resolvable suggested reviewer to a single destination channel.
- Own channel (filtered by the reviewer's min-priority) if set, else the team
- default, else nowhere. A reviewer filtered out of their own channel does not fall
- back to the team channel — that was their choice. Reviewers sharing a destination
- are grouped so each channel is posted to once, mentioning only its own reviewers.
+ Own channel (filtered by the reviewer's min-priority) if set, else the team default,
+ else nowhere. A reviewer filtered out of their own channel does not fall back to the
+ team channel — that was their choice. Reviewers sharing a destination are grouped so
+ each channel is posted to once, mentioning only its own reviewers. A report whose
+ reviewers don't resolve to a channel sends nothing.
"""
reviewer_user_ids = _resolve_suggested_reviewer_user_ids(report)
if not reviewer_user_ids:
@@ -621,11 +648,17 @@ def dispatch_inbox_item_notifications(
)
return 0
- priority = _latest_priority(report)
- # Don't notify until a priority is persisted — an unprioritised report isn't ready for the inbox.
- if _priority_rank(priority) is None:
+ # Mirror the inbox Reports tab: notify only for actionable reports (READY is enforced upstream
+ # in the notification activity). Priority is read below for the message label and min-priority
+ # routing, but it's optional now — an actionable report notifies even without a priority.
+ if _latest_actionability(report) not in _ACTIONABLE_VALUES:
+ logger.info(
+ "dispatch_inbox_item_notifications: report not actionable, skipping",
+ extra={"report_id": report_id, "team_id": team_id},
+ )
return 0
+ priority = _latest_priority(report)
team_integration = _get_team_slack_integration(team_id)
team_channel = _team_notification_channel(team_id) if team_integration is not None else None
@@ -636,6 +669,19 @@ def dispatch_inbox_item_notifications(
team_channel=team_channel,
)
if not routes:
+ # No reviewer resolved to a destination: no suggested reviewers linked to a user, none met
+ # their min-priority, or there's no own/team channel to fall back to. This is the most
+ # common reason an actionable report sends nothing — log the inputs so it's diagnosable.
+ logger.info(
+ "dispatch_inbox_item_notifications: no reviewer routes resolved, skipping",
+ extra={
+ "report_id": report_id,
+ "team_id": team_id,
+ "priority": priority,
+ "has_team_integration": team_integration is not None,
+ "has_team_channel": team_channel is not None,
+ },
+ )
return 0
sources = source_products or []
@@ -677,4 +723,8 @@ def dispatch_inbox_item_notifications(
_post_signal_evidence_thread(slack, channel_id, str(thread_ts), signals)
except Exception:
logger.exception("Failed to deliver signals inbox-item Slack notification", extra=log_context)
+ logger.info(
+ "dispatch_inbox_item_notifications: complete",
+ extra={"report_id": report_id, "team_id": team_id, "messages_sent": sent, "routes": len(routes)},
+ )
return sent
diff --git a/products/signals/backend/temporal/inbox_notification.py b/products/signals/backend/temporal/inbox_notification.py
index 66118404383e..e4f515b0a061 100644
--- a/products/signals/backend/temporal/inbox_notification.py
+++ b/products/signals/backend/temporal/inbox_notification.py
@@ -1,12 +1,9 @@
-"""Decides when (and whether) to send a report's inbox Slack notification.
-
-A notification is only sent when the report has an implementation PR to link — otherwise
-there's nothing actionable, so it's suppressed (it still appears in the inbox UI). A report
-that auto-starts an implementation task waits for the PR to open (so the card can carry a
-"Review PR" button), bounded by a timeout; if that task never opens a PR (it fails, is
-cancelled, or the wait times out) the notification is suppressed. A report with no auto-start
-task can never produce a PR, so it's suppressed immediately without waiting. Posting itself
-stays in `dispatch_inbox_item_notifications`; this governs timing and suppression.
+"""Decides when to send a report's inbox Slack notification.
+
+Every actionable report notifies; the PR is enrichment, not a gate. With an auto-start task we
+wait (bounded by a timeout) for the PR so the card can link it, then notify either way; with no
+task we notify immediately. Actionability is enforced downstream (READY status + persisted
+priority). Posting lives in `dispatch_inbox_item_notifications`; this workflow governs timing.
"""
from __future__ import annotations
@@ -127,8 +124,14 @@ class SignalReportInboxNotificationWorkflow:
timeout_seconds = settings.SIGNALS_INBOX_PR_NOTIFICATION_TIMEOUT_SECONDS
poll_seconds = max(1, settings.SIGNALS_INBOX_PR_NOTIFICATION_POLL_SECONDS)
+ log_ctx = {"report_id": inputs.report_id, "team_id": inputs.team_id}
+
state = await self._fetch_state(inputs)
if state.has_implementation_task and not state.pr_available and not state.task_terminal:
+ workflow.logger.info(
+ "inbox notification: implementation task present, waiting for its PR",
+ extra={**log_ctx, "timeout_seconds": timeout_seconds},
+ )
elapsed = 0
while elapsed < timeout_seconds:
await workflow.sleep(timedelta(seconds=poll_seconds))
@@ -136,32 +139,44 @@ class SignalReportInboxNotificationWorkflow:
state = await self._fetch_state(inputs)
if state.pr_available or state.task_terminal:
break
-
- # A report with no implementation PR has nothing actionable to link, so suppress its
- # notification (it still shows in the inbox). The patch guards keep workflows already in
- # flight at deploy on their prior, narrower behavior to preserve replay determinism:
- # `signals-inbox-skip-any-no-pr` suppresses any PR-less report; the older
- # `signals-inbox-skip-no-pr` only suppressed reports whose implementation task produced no PR.
- if workflow.patched("signals-inbox-skip-any-no-pr"):
- should_skip = not state.pr_available
- elif workflow.patched("signals-inbox-skip-no-pr"):
- should_skip = state.has_implementation_task and not state.pr_available
+ if state.pr_available:
+ wait_outcome = "pr_opened"
+ elif state.task_terminal:
+ wait_outcome = "task_ended_without_pr"
+ else:
+ wait_outcome = "timed_out_without_pr"
+ workflow.logger.info(
+ "inbox notification: PR wait finished",
+ extra={
+ **log_ctx,
+ "outcome": wait_outcome,
+ "elapsed_seconds": elapsed,
+ "pr_available": state.pr_available,
+ },
+ )
+ elif not state.has_implementation_task:
+ workflow.logger.info("inbox notification: no implementation task, notifying now", extra=log_ctx)
else:
- should_skip = False
-
- if should_skip:
workflow.logger.info(
- "inbox notification skipped: no implementation PR to link",
- extra={"report_id": inputs.report_id, "team_id": inputs.team_id},
+ "inbox notification: PR already resolved on first check",
+ extra={**log_ctx, "pr_available": state.pr_available},
)
- return 0
- return await workflow.execute_activity(
+ # Transitional shim: keep replaying the now-removed `signals-inbox-skip-any-no-pr` patch so
+ # executions in flight during rollout stay deterministic. Drop once they drain.
+ workflow.deprecate_patch("signals-inbox-skip-any-no-pr")
+
+ sent = await workflow.execute_activity(
send_report_inbox_notifications_activity,
inputs,
start_to_close_timeout=timedelta(minutes=2),
retry_policy=RetryPolicy(maximum_attempts=2),
)
+ workflow.logger.info(
+ "inbox notification: dispatch complete",
+ extra={**log_ctx, "messages_sent": sent, "pr_available": state.pr_available},
+ )
+ return sent
async def _fetch_state(self, inputs: InboxNotificationInput) -> InboxNotificationState:
return await workflow.execute_activity(
diff --git a/products/signals/backend/test/test_inbox_notification_workflow.py b/products/signals/backend/test/test_inbox_notification_workflow.py
index a2d70eaaaa8c..457c283932c7 100644
--- a/products/signals/backend/test/test_inbox_notification_workflow.py
+++ b/products/signals/backend/test/test_inbox_notification_workflow.py
@@ -147,21 +147,24 @@ async def test_workflow_waits_then_notifies_when_pr_opens():
@pytest.mark.parametrize(
"states,timeout_seconds,polls",
[
- ([NO_TASK], 10, False), # a task-less report can never produce a PR, so skip on the first fetch
- ([WAIT, TERMINAL], 10, True), # task reaches a terminal state without ever opening a PR
- ([WAIT], 3, True), # PR never opens, so the wait runs out the timeout
+ ([NO_TASK], 10, False), # task-less report: no PR possible, notify immediately on the first fetch
+ ([WAIT, TERMINAL], 10, True), # task reaches a terminal state without a PR — notify once we know
+ ([WAIT], 3, True), # PR never opens, so notify after the wait runs out the timeout
],
)
-async def test_workflow_skips_when_no_pr_is_produced(states, timeout_seconds, polls):
+async def test_workflow_notifies_even_without_pr(states, timeout_seconds, polls):
+ # The PR is enrichment, not a gate: an actionable report still notifies even when no PR
+ # is ever produced. We only poll first when an implementation task exists (to attach the
+ # PR link); a task-less report notifies right away.
recorder = _Recorder(states)
with override_settings(
SIGNALS_INBOX_PR_NOTIFICATION_TIMEOUT_SECONDS=timeout_seconds,
SIGNALS_INBOX_PR_NOTIFICATION_POLL_SECONDS=1,
):
sent = await _run_workflow(recorder)
- assert sent == 0
- assert recorder.dispatch_calls == 0
+ assert sent == 1
+ assert recorder.dispatch_calls == 1
if polls:
- assert recorder.state_calls >= 2 # initial fetch + at least one poll before giving up
+ assert recorder.state_calls >= 2 # initial fetch + at least one poll while waiting for the PR
else:
assert recorder.state_calls == 1 # decided on the first fetch — no task means no polling
diff --git a/products/signals/backend/test/test_slack_inbox_notifications.py b/products/signals/backend/test/test_slack_inbox_notifications.py
index 9ab566a84645..d3a2a8d71333 100644
--- a/products/signals/backend/test/test_slack_inbox_notifications.py
+++ b/products/signals/backend/test/test_slack_inbox_notifications.py
@@ -461,11 +461,68 @@ def test_dispatch_posts_nothing_without_suggested_reviewers(org_and_team):
slack_cls.return_value.client = fake_client
sent = dispatch_inbox_item_notifications(str(report.id), team.id)
- # No reviewers to route → the team channel is not posted to.
+ # No suggested reviewer → nothing sent, even with a team channel configured (no fallback).
assert sent == 0
assert fake_client.chat_postMessage.call_count == 0
+def test_dispatch_posts_nothing_without_reviewers_or_team_channel(org_and_team):
+ org, team = org_and_team
+ _make_reviewer_user(org, "[email protected]", "creator-bot")
+ report = _make_ready_report(team, priority=AutonomyPriority.P2) # no reviewers, no team channel
+
+ fake_client = MagicMock()
+ with patch("products.signals.backend.slack_inbox_notifications.SlackIntegration") as slack_cls:
+ slack_cls.return_value.client = fake_client
+ sent = dispatch_inbox_item_notifications(str(report.id), team.id)
+
+ # No destination at all → nothing sent.
+ assert sent == 0
+ assert fake_client.chat_postMessage.call_count == 0
+
+
+def test_dispatch_skips_non_actionable_report(org_and_team):
+ org, team = org_and_team
+ creator = _make_reviewer_user(org, "[email protected]", "creator-bot")
+ _make_slack_integration(team, creator)
+ _set_team_channel(team, "CTEAM|#posthog-signals")
+ # Not in the inbox Reports tab → must not notify, even with a team channel.
+ report = _make_ready_report(team, actionability=ActionabilityChoice.NOT_ACTIONABLE)
+
+ fake_client = MagicMock()
+ with patch("products.signals.backend.slack_inbox_notifications.SlackIntegration") as slack_cls:
+ slack_cls.return_value.client = fake_client
+ sent = dispatch_inbox_item_notifications(str(report.id), team.id)
+
+ assert sent == 0
+ assert fake_client.chat_postMessage.call_count == 0
+
+
+def test_dispatch_notifies_requires_human_input_report_without_priority(org_and_team):
+ org, team = org_and_team
+ reviewer = _make_reviewer_user(org, "[email protected]", "rhi-bot")
+ _make_slack_integration(team, reviewer)
+ _set_team_channel(team, "CTEAM|#posthog-signals")
+ # Actionable (requires_human_input) with no priority but a resolvable reviewer → still notifies.
+ report = _make_ready_report(
+ team, actionability=ActionabilityChoice.REQUIRES_HUMAN_INPUT, priority=None, suggested_logins=["rhi-bot"]
+ )
+
+ fake_client = MagicMock()
+ with (
+ patch("products.signals.backend.slack_inbox_notifications.SlackIntegration") as slack_cls,
+ patch("products.signals.backend.slack_inbox_notifications.lookup_slack_user_id_by_email", return_value=None),
+ ):
+ slack_cls.return_value.client = fake_client
+ sent = dispatch_inbox_item_notifications(str(report.id), team.id)
+
+ assert sent == 1
+ assert fake_client.chat_postMessage.call_args.kwargs["channel"] == "CTEAM"
+
+
@pytest.mark.django_db
def test_dispatch_groups_own_and_fallback_reviewers_sharing_a_channel(org_and_team):
# One reviewer's own channel resolves to the same channel as the team default that