Skip to content

: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.

fix(wizard): return 204 from stream endpoints under WSGI (#130343)

Fernando Gomesd00699740368
diff --git a/products/wizard/backend/presentation/runs/views.py b/products/wizard/backend/presentation/runs/views.py
index c7be90635a04..6d9674cd4f32 100644
--- a/products/wizard/backend/presentation/runs/views.py
+++ b/products/wizard/backend/presentation/runs/views.py
@@ -184,8 +184,9 @@ class WizardRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
if _wizard_sync_killswitch_enabled(str(getattr(request.user, "distinct_id", self.team_id))):
return HttpResponse(status=204)
run = self._get_run()
+ # The event stream is async, which WSGI can't consume; 204 stops EventSource reconnecting.
if getattr(settings, "SERVER_GATEWAY_INTERFACE", "ASGI") != "ASGI":
- raise RuntimeError("wizard_runs.stream requires ASGI.")
+ return HttpResponse(status=204)
return sse_streaming_response(wizard_run_event_stream(self.team_id, run.id), endpoint="wizard_run")
@extend_schema(
diff --git a/products/wizard/backend/presentation/sessions/views.py b/products/wizard/backend/presentation/sessions/views.py
index 4190341c08cf..cb4bf7d829f5 100644
--- a/products/wizard/backend/presentation/sessions/views.py
+++ b/products/wizard/backend/presentation/sessions/views.py
@@ -326,9 +326,10 @@ class WizardSessionViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
workflow_id = query.validated_data["workflow_id"]
skill_id = query.validated_data.get("skill_id") or None
- # The generator is `async def` — WSGI can't consume an async iterator.
+ # The generator is `async def` — WSGI can't consume an async iterator. A 204
+ # tells EventSource to stop reconnecting, so the client winds down cleanly.
if getattr(settings, "SERVER_GATEWAY_INTERFACE", "ASGI") != "ASGI":
- raise RuntimeError("wizard_sessions.stream requires ASGI.")
+ return HttpResponse(status=204)
generator = _wizard_session_event_stream(
team_id=self.team_id,
diff --git a/products/wizard/backend/tests/runs/test_task_presentation.py b/products/wizard/backend/tests/runs/test_task_presentation.py
index 5e805711ce0b..2adc4cf6596c 100644
--- a/products/wizard/backend/tests/runs/test_task_presentation.py
+++ b/products/wizard/backend/tests/runs/test_task_presentation.py
@@ -4,6 +4,7 @@ from uuid import uuid4
from posthog.test.base import APIBaseTest
from unittest.mock import patch
+from django.test import override_settings
from django.utils import timezone
from parameterized import parameterized
@@ -129,6 +130,14 @@ class TestWizardRunTasks(APIBaseTest):
assert response.status_code == 200
assert response.json()["status"] == "completed"
+ @override_settings(SERVER_GATEWAY_INTERFACE="WSGI")
+ def test_run_stream_under_wsgi_returns_204(self) -> None:
+ response = self.client.get(
+ f"/api/projects/{self.team.id}/wizard/runs/{self.wizard_run.id}/stream/",
+ HTTP_ACCEPT="text/event-stream",
+ )
+ assert response.status_code == 204
+
def test_run_stream_honors_killswitch(self) -> None:
with patch(
"products.wizard.backend.presentation.runs.views._wizard_sync_killswitch_enabled", return_value=True
diff --git a/products/wizard/backend/tests/sessions/test_session_presentation.py b/products/wizard/backend/tests/sessions/test_session_presentation.py
index ce09ecb4c8af..a3aa77aa2941 100644
--- a/products/wizard/backend/tests/sessions/test_session_presentation.py
+++ b/products/wizard/backend/tests/sessions/test_session_presentation.py
@@ -1,6 +1,8 @@
from posthog.test.base import APIBaseTest
from unittest.mock import patch
+from django.test import override_settings
+
from parameterized import parameterized
from rest_framework import status
@@ -417,6 +419,11 @@ class TestWizardSessionViewSet(APIBaseTest):
response = self.client.get(f"{self._url()}stream/?workflow_id=onboarding")
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
+ @override_settings(SERVER_GATEWAY_INTERFACE="WSGI")
+ def test_stream_under_wsgi_returns_204(self):
+ response = self.client.get(f"{self._url()}stream/?workflow_id=onboarding")
+ self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
+
@patch("products.wizard.backend.presentation.sessions.views.posthoganalytics.feature_enabled", return_value=True)
def test_latest_killswitch_returns_204_even_with_a_live_session(self, _mock_feature_enabled):
# Parity with stream: with the killswitch on, `latest` short-circuits to a 204