: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(posthog-ai): accept retired voice_mode ui_context from stale tabs (#120726)
Shy Alter2bfeca71c82b
diff --git a/ee/api/conversation.py b/ee/api/conversation.pyindex 3ce019f14468..2cc7fd60c2a5 100644--- a/ee/api/conversation.py+++ b/ee/api/conversation.py@@ -122,6 +122,8 @@ class MessageSerializer(MessageMinimalSerializer):def validate(self, attrs):data = attrs+ if isinstance(data.get("ui_context"), dict):+ data["ui_context"].pop("voice_mode", None)if data["content"] is not None:try:message = HumanMessage.model_validate(@@ -166,6 +168,8 @@ class QueueMessageSerializer(serializers.Serializer):def validate(self, attrs):data = attrs+ if isinstance(data.get("ui_context"), dict):+ data["ui_context"].pop("voice_mode", None)try:HumanMessage.model_validate({diff --git a/ee/api/tests/test_conversation.py b/ee/api/tests/test_conversation.pyindex ec4a75330217..5050724adb09 100644--- a/ee/api/tests/test_conversation.py+++ b/ee/api/tests/test_conversation.py@@ -7,10 +7,11 @@ from unittest.mock import AsyncMock, patchfrom django.db import connectionfrom django.http import StreamingHttpResponse-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom django.test.utils import CaptureQueriesContextfrom django.utils import timezone+from parameterized import parameterizedfrom rest_framework import statusfrom rest_framework.exceptions import Throttledfrom rest_framework.test import APIRequestFactory@@ -39,7 +40,7 @@ from products.posthog_ai.backend.message_routing import SandboxRouteResultfrom products.posthog_ai.backend.models.assistant import Conversationfrom products.tasks.backend.models import Channel, Task, TaskRun-from ee.api.conversation import ConversationViewSet+from ee.api.conversation import ConversationViewSet, MessageSerializer, QueueMessageSerializerasync def _async_generator():@@ -2116,3 +2117,18 @@ class TestConversationCreateRuntime(APIBaseTest):self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)m_routing.assert_not_called()+++class TestRetiredUIContextFields(SimpleTestCase):+ @parameterized.expand(+ [+ ("message", MessageSerializer, {"conversation": str(uuid.uuid4()), "trace_id": str(uuid.uuid4())}),+ ("queue_message", QueueMessageSerializer, {}),+ ]+ )+ def test_voice_mode_from_stale_frontend_is_dropped(self, _name, serializer_class, extra_data):+ ui_context = {"voice_mode": False, "form_answers": {"question": "answer"}}+ serializer = serializer_class(data={"content": "test query", "ui_context": ui_context, **extra_data})++ self.assertTrue(serializer.is_valid(), serializer.errors)+ self.assertEqual(serializer.validated_data["ui_context"], {"form_answers": {"question": "answer"}})