: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
chore: ticket status in elegibility (#67109)
Alex V6c00263cb45e
diff --git a/products/conversations/backend/temporal/coordinator.py b/products/conversations/backend/temporal/coordinator.pyindex 21f88309dbdf..a781f51dffad 100644--- a/products/conversations/backend/temporal/coordinator.py+++ b/products/conversations/backend/temporal/coordinator.py@@ -25,6 +25,7 @@ with workflow.unsafe.imports_passed_through():from products.business_knowledge.backend.logic import has_ready_sourcesfrom products.conversations.backend.models import Ticket+ from products.conversations.backend.models.constants import Statusfrom products.conversations.backend.temporal.pipeline import SupportReplyInput, SupportReplyWorkflowlogger = structlog.get_logger(__name__)@@ -112,7 +113,8 @@ def _collect_eligible(lookback_minutes: int = TICKET_LOOKBACK_MINUTES) -> list[E# last_message_at is the debounce axis; fall back to created_at for tickets whose denormalized# timestamp hasn't landed yet (set via a post-commit signal, so there's a brief null window).recent_tickets = Ticket.objects.filter(- Q(last_message_at__gte=cutoff) | Q(last_message_at__isnull=True, created_at__gte=cutoff)+ Q(last_message_at__gte=cutoff) | Q(last_message_at__isnull=True, created_at__gte=cutoff),+ status__in=[Status.NEW, Status.OPEN],).select_related("team__organization")# First pass: the cheap per-ticket gates that don't touch the comments table. We keepdiff --git a/products/conversations/backend/temporal/tests/test_coordinator.py b/products/conversations/backend/temporal/tests/test_coordinator.pyindex 7ae05edffa94..9081dc7fe339 100644--- a/products/conversations/backend/temporal/tests/test_coordinator.py+++ b/products/conversations/backend/temporal/tests/test_coordinator.py@@ -324,6 +324,50 @@ class TestCollectEligibleScanWindow:assert [t.ticket_id for t in result] == ([str(ticket.id)] if expected_collected else [])+class TestCollectEligibleStatus:+ @parameterized.expand(+ [+ ("new", "new", True),+ ("open", "open", True),+ ("pending", "pending", False),+ ("on_hold", "on_hold", False),+ ("resolved", "resolved", False),+ ]+ )+ @pytest.mark.django_db+ @patch(f"{COORD_MODULE}._is_master_flag_enabled", return_value=True)+ def test_only_new_and_open_tickets_collected(+ self,+ _name,+ ticket_status,+ expected_collected,+ mock_master_flag,+ ):+ from posthog.models import Organization, Team++ from products.conversations.backend.models.ticket import Ticket as TicketModel++ org = Organization.objects.create(name="Org")+ team = Team.objects.create(+ organization=org, name="Team", conversations_settings={"ai_suggestions_enabled": True}+ )+ ticket = TicketModel.objects.create_with_number(+ team=team,+ widget_session_id=f"aabbccdd-0000-0000-0000-{uuid.uuid4().hex[:12]}",+ distinct_id="u1",+ channel_source="widget",+ status=ticket_status,+ )+ settled_at = timezone.now() - timedelta(minutes=3)+ TicketModel.objects.filter(id=ticket.id).update(+ created_at=settled_at,+ last_message_at=settled_at,+ )++ result = _collect_eligible()+ assert [t.ticket_id for t in result] == ([str(ticket.id)] if expected_collected else [])++class TestCoordinatorWorkflow:@pytest.mark.asyncio@patch(f"{COORD_MODULE}._collect_eligible")