: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(hogai): write conversation stream events as JSON (#73369)
Tom Piccirello9a83d534a501
diff --git a/ee/hogai/stream/redis_stream.py b/ee/hogai/stream/redis_stream.pyindex 8f621b7d4ac9..9828d1f1e2e0 100644--- a/ee/hogai/stream/redis_stream.py+++ b/ee/hogai/stream/redis_stream.py@@ -157,12 +157,9 @@ class ConversationStreamSerializer:return Nonereturn {- # nosemgrep: python.lang.security.deserialization.pickle.avoid-pickle (internal Redis stream, data is self-generated)- self.serialization_key: pickle.dumps(- StreamEvent(- event=event,- )- ),+ # Migration Phase 2: emit JSON. Readers already understand both formats (Phase 1);+ # the legacy pickle read path is removed in Phase 3 once older entries have drained.+ self.serialization_key: StreamEvent(event=event).model_dump_json().encode("utf-8"),}def _to_message_event(self, message: AssistantStreamedMessageUnion) -> MessageEvent:diff --git a/ee/hogai/stream/test/test_redis_stream.py b/ee/hogai/stream/test/test_redis_stream.pyindex 0bbfe2539cd7..80f9306dbebd 100644--- a/ee/hogai/stream/test/test_redis_stream.py+++ b/ee/hogai/stream/test/test_redis_stream.py@@ -708,3 +708,12 @@ class TestConversationStreamSerializerJson(SimpleTestCase):self.assertEqual(result.event.type, "STREAM_STATUS")payload = cast(StatusPayload, result.event.payload)self.assertEqual(payload.status, "complete")++ def test_dumps_emits_json(self):+ # Phase 2: the writer now emits JSON rather than pickle.+ serializer = ConversationStreamSerializer()++ result = serializer.dumps((AssistantEventType.MESSAGE, AssistantMessage(content="hi")))++ assert result is not None+ self.assertEqual(result["data"][:1], b"{")