: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
fix(signals): tag implementation task runs with ai_stage=implementation (#65212)
Joshua Snyder4c7e2189d95a
diff --git a/products/signals/backend/auto_start.py b/products/signals/backend/auto_start.pyindex a532b9bc6f88..db394837d698 100644--- a/products/signals/backend/auto_start.py+++ b/products/signals/backend/auto_start.py@@ -198,6 +198,7 @@ async def maybe_autostart_implementation_task(signal_report_id=report_id,posthog_mcp_scopes="read_only",interaction_origin="signal_report", # Makes the agent auto-push and open a draft PR+ ai_stage="implementation",)if created.latest_run is None:raise RuntimeError(f"Task {created.task_id} auto-started without producing a TaskRun")diff --git a/products/signals/backend/test/test_auto_start.py b/products/signals/backend/test/test_auto_start.pyindex 66c5c75f0384..3e2c346fe783 100644--- a/products/signals/backend/test/test_auto_start.py+++ b/products/signals/backend/test/test_auto_start.py@@ -1,13 +1,27 @@+import uuid+from types import SimpleNamespace+import pytest+from unittest.mock import AsyncMock, MagicMock, patchfrom social_django.models import UserSocialAuthfrom posthog.models import Organization, Team, Userfrom posthog.models.organization import OrganizationMembership-from products.signals.backend.auto_start import ReviewerContent, _resolve_autostart_assignee-from products.signals.backend.models import SignalUserAutonomyConfig-from products.signals.backend.report_generation.research import Priority+from products.signals.backend.auto_start import (+ ReviewerContent,+ _resolve_autostart_assignee,+ maybe_autostart_implementation_task,+)+from products.signals.backend.models import SignalReportTask, SignalUserAutonomyConfig+from products.signals.backend.report_generation.research import (+ ActionabilityAssessment,+ ActionabilityChoice,+ Priority,+ PriorityAssessment,+)+from products.tasks.backend.facade import api as tasks_facade@pytest.fixture@@ -57,3 +71,38 @@ def test_resolve_autostart_assignee(organization, team, autostart_priority, repoassert assignee.id == user.idelse:assert assignee is None+++async def test_autostart_tags_implementation_ai_stage(ateam):+ """The autostart implementation run is tagged ai_stage="implementation" so its+ $ai_generation traces are attributed instead of landing in the "(none)" bucket."""+ assignee = SimpleNamespace(id=123)+ created = SimpleNamespace(task_id=uuid.uuid4(), team_id=ateam.id, latest_run=object())+ create_and_run_task = MagicMock(return_value=created)++ with (+ patch.object(tasks_facade, "create_and_run_task", create_and_run_task),+ patch("products.signals.backend.auto_start._resolve_autostart_assignee", return_value=assignee),+ patch.object(SignalReportTask.objects, "acreate", AsyncMock()),+ ):+ await maybe_autostart_implementation_task(+ team_id=ateam.id,+ report_id=str(uuid.uuid4()),+ repository="PostHog/posthog",+ title="Fix the thing",+ summary="A short summary",+ actionability=ActionabilityAssessment(+ explanation="Clearly actionable.",+ actionability=ActionabilityChoice.IMMEDIATELY_ACTIONABLE,+ already_addressed=False,+ ),+ reviewers_content=[_reviewer("octocat")],+ priority=PriorityAssessment(explanation="High impact.", priority=Priority.P0),+ )++ create_and_run_task.assert_called_once()+ kwargs = create_and_run_task.call_args.kwargs+ assert kwargs["origin_product"] == tasks_facade.TaskOriginProduct.SIGNAL_REPORT+ assert kwargs["ai_stage"] == "implementation"