: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(signals): record why a report lands in pending_input (#77187)
posthog[bot]683aa01dc860
diff --git a/products/signals/backend/receivers.py b/products/signals/backend/receivers.pyindex 2f685397f62e..25cafbed0672 100644--- a/products/signals/backend/receivers.py+++ b/products/signals/backend/receivers.py@@ -470,6 +470,13 @@ def capture_status_change_analytics(if prior_status is None or prior_status == instance.status:return+ # Set by mark_report_pending_input_activity right before this save, so the pipeline's two+ # doors into PENDING_INPUT (repo-selection failure vs. the agent requesting human input) are+ # distinguishable in the training stream — mirrors failure_reason on signal_report_completed.+ pending_reason = (+ getattr(instance, "_pending_reason", None) if instance.status == SignalReport.Status.PENDING_INPUT else None+ )+# Snapshot now — the instance may be mutated again before the commit callback runs.properties = {"team_id": instance.team_id,@@ -481,6 +488,7 @@ def capture_status_change_analytics("run_count": instance.run_count,"report_created_at": instance.created_at.isoformat() if instance.created_at else None,"promoted_at": instance.promoted_at.isoformat() if instance.promoted_at else None,+ "pending_reason": pending_reason,}report_id = str(instance.id)new_status = instance.statusdiff --git a/products/signals/backend/temporal/summary.py b/products/signals/backend/temporal/summary.pyindex 29f2fdb48024..ab41145fac29 100644--- a/products/signals/backend/temporal/summary.py+++ b/products/signals/backend/temporal/summary.py@@ -67,6 +67,7 @@ def _capture_report_event(source_products: list[str],result: str | None = None,failure_reason: str | None = None,+ pending_reason: str | None = None,) -> None:properties: dict = {"report_id": report_id,@@ -78,6 +79,8 @@ def _capture_report_event(properties["result"] = resultif failure_reason is not None:properties["failure_reason"] = failure_reason+ if pending_reason is not None:+ properties["pending_reason"] = pending_reasonif event == "signal_report_completed" and result is not None:metrics.increment_report_completed(result)@@ -109,6 +112,10 @@ class ReportDecision:# a JSON set, `[]` to clear, or `None` to leave the column alone. `None` for the no-repo branch,# which does no research.charts: list[dict[str, Any]] | None = None+ # Which of the two doors into PENDING_INPUT produced this decision, so telemetry can tell a+ # broken repo-selection integration apart from the agent legitimately asking for human input.+ # Irrelevant (left `None`) unless `choice == ActionabilityChoice.REQUIRES_HUMAN_INPUT`.+ pending_reason: str | None = None@temporalio.workflow.defn(name="signal-report-summary")@@ -255,6 +262,7 @@ class SignalReportSummaryWorkflow:summary=f"Could not automatically select a repository: {repo_result.reason}",choice=ActionabilityChoice.REQUIRES_HUMAN_INPUT,explanation=repo_result.reason,+ pending_reason="repo_selection_required",)else:# 5. Run the agentic report research flow with the selected repository to use code/MCP data to assess signals@@ -277,6 +285,7 @@ class SignalReportSummaryWorkflow:choice=agentic_result.choice,explanation=agentic_result.explanation,charts=agentic_result.charts,+ pending_reason="agent_requested",)if decision.choice == ActionabilityChoice.NOT_ACTIONABLE:log.info(@@ -313,6 +322,7 @@ class SignalReportSummaryWorkflow:signal_count=signal_count,source_products=source_products,charts=decision.charts,+ pending_reason=decision.pending_reason,),start_to_close_timeout=timedelta(minutes=1),retry_policy=RetryPolicy(maximum_attempts=3),@@ -617,6 +627,9 @@ class MarkReportPendingInput:source_products: list[str] = field(default_factory=list)# See MarkReportReadyInput.charts — written in the same transaction as the draft title/summary.charts: list[dict[str, Any]] | None = None+ # Coarse cause of the transition ("repo_selection_required" / "agent_requested"), see+ # ReportDecision.pending_reason.+ pending_reason: str | None = None@temporalio.activity.defn@@ -637,6 +650,9 @@ async def mark_report_pending_input_activity(input: MarkReportPendingInput) -> Nif input.charts is not None:report.charts = input.chartsupdated_fields = [*updated_fields, "charts"]+ # Read by capture_status_change_analytics's post_save receiver (same instance, same+ # transaction) — not a model field, so it never persists past this save.+ report._pending_reason = input.pending_reason # type: ignore[attr-defined]report.save(update_fields=updated_fields)return report.run_count, False@@ -665,6 +681,7 @@ async def mark_report_pending_input_activity(input: MarkReportPendingInput) -> Nrun_count=run_count,source_products=input.source_products,result="pending_input",+ pending_reason=input.pending_reason,)logger.debug(f"Marked report {input.report_id} as pending_input",diff --git a/products/signals/backend/test/test_report_telemetry.py b/products/signals/backend/test/test_report_telemetry.pyindex 9618fe86e45b..8d67c65b3e14 100644--- a/products/signals/backend/test/test_report_telemetry.py+++ b/products/signals/backend/test/test_report_telemetry.py@@ -202,6 +202,41 @@ async def test_ready_is_idempotent_after_partial_commit(ateam, preexisting_statuassert refreshed.summary == "existing summary"+ "pending_reason",+ ["repo_selection_required", "agent_requested"],+)+async def test_pending_input_fires_completed_and_status_changed_with_pending_reason(ateam, pending_reason):+ report = await database_sync_to_async(SignalReport.objects.create)(+ team=ateam,+ status=SignalReport.Status.IN_PROGRESS,+ signal_count=3,+ total_weight=2.0,+ )+ report_id = str(report.id)++ with patch(f"{PIPELINE_MODULE_PATH}.posthoganalytics.capture") as capture:+ await mark_report_pending_input_activity(+ MarkReportPendingInput(+ team_id=ateam.id,+ report_id=report_id,+ title="title",+ summary="summary",+ reason="Requires human input: some reason",+ signal_count=3,+ source_products=["zendesk"],+ pending_reason=pending_reason,+ )+ )++ calls_by_event = {call.kwargs["event"]: call.kwargs for call in capture.call_args_list}+ assert calls_by_event["signal_report_completed"]["properties"]["result"] == "pending_input"+ assert calls_by_event["signal_report_completed"]["properties"]["pending_reason"] == pending_reason+ assert calls_by_event["signal_report_status_changed"]["properties"]["pending_reason"] == pending_reason++@pytest.mark.asyncio@pytest.mark.django_dbasync def test_pending_input_is_idempotent_when_already_pending_input(ateam):