: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(max): give the conversation list a stable page order (#102574)
posthog[bot]a0647ff9c4b3
diff --git a/ee/api/conversation.py b/ee/api/conversation.pyindex 1a4d53ba8011..c9579729bf5c 100644--- a/ee/api/conversation.py+++ b/ee/api/conversation.py@@ -346,7 +346,8 @@ class ConversationViewSet(# Hide internal conversations from customers, but show them to support agents during impersonationif not is_impersonated_session(self.request):queryset = queryset.filter(is_internal=False)- queryset = queryset.order_by("-updated_at")+ # `id` breaks ties, because equal `updated_at` values give no stable page order+ queryset = queryset.order_by("-updated_at", "-id")if self.action == "list":queryset = queryset.defer("approval_decisions", "messages_json", "sandbox_task_id", "sandbox_run_id")return querysetdiff --git a/ee/api/tests/test_conversation.py b/ee/api/tests/test_conversation.pyindex b1d884e27fed..96a3537a2fd3 100644--- a/ee/api/tests/test_conversation.py+++ b/ee/api/tests/test_conversation.py@@ -625,6 +625,29 @@ class TestConversation(APIBaseTest):self.assertEqual(results[1]["id"], str(conversation1.id))self.assertEqual(results[1]["title"], "Older conversation")+ def test_list_pagination_is_stable_when_updated_at_ties(self):+ conversations = [+ Conversation.objects.create(+ user=self.user, team=self.team, title=f"Conversation {i}", type=Conversation.Type.ASSISTANT+ )+ for i in range(4)+ ]+ Conversation.objects.filter(id__in=[conversation.id for conversation in conversations]).update(+ updated_at=timezone.now()+ )++ with patch("langgraph.graph.state.CompiledStateGraph.aget_state", new_callable=AsyncMock):+ first_page = self.client.get(f"/api/environments/{self.team.id}/conversations/?limit=2")+ second_page = self.client.get(f"/api/environments/{self.team.id}/conversations/?limit=2&offset=2")++ self.assertEqual(first_page.status_code, status.HTTP_200_OK)+ self.assertEqual(second_page.status_code, status.HTTP_200_OK)++ paginated_ids = [result["id"] for result in first_page.json()["results"]] + [+ result["id"] for result in second_page.json()["results"]+ ]+ self.assertEqual(paginated_ids, sorted((str(conversation.id) for conversation in conversations), reverse=True))+@override_settings(DEBUG=False)def test_get_throttles_returns_empty_for_create_action(self):"""Test that get_throttles returns empty list for create action (throttling is handled in check_throttles)."""