: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(replay-vision): classify failed gemini uploads as provider faults (#93194)
posthog[bot]4defb541cad8
diff --git a/products/replay_vision/backend/temporal/activities/upload_video_to_gemini.py b/products/replay_vision/backend/temporal/activities/upload_video_to_gemini.pyindex e9557d4bd16b..b7d7d276dcea 100644--- a/products/replay_vision/backend/temporal/activities/upload_video_to_gemini.py+++ b/products/replay_vision/backend/temporal/activities/upload_video_to_gemini.py@@ -140,7 +140,13 @@ def _write_and_upload(raw_client: RawGenAIClient, video_bytes: bytes, mime_type:with tempfile.NamedTemporaryFile() as tmp_file:tmp_file.write(video_bytes)tmp_file.flush()- return raw_client.files.upload(- file=tmp_file.name,- config=types.UploadFileConfig(mime_type=mime_type, display_name=workflow_id),- )+ try:+ return raw_client.files.upload(+ file=tmp_file.name,+ config=types.UploadFileConfig(mime_type=mime_type, display_name=workflow_id),+ )+ except (KeyError, ValueError, TypeError) as e:+ # google-genai does not check the finalize response's HTTP status; a failed upload surfaces as one of these.+ raise ScannerFailureError(+ "The AI provider did not finish the video upload", kind=FailureKind.PROVIDER_TRANSIENT+ ) from ediff --git a/products/replay_vision/backend/tests/test_temporal.py b/products/replay_vision/backend/tests/test_temporal.pyindex 508de484fdb8..a7c62a383980 100644--- a/products/replay_vision/backend/tests/test_temporal.py+++ b/products/replay_vision/backend/tests/test_temporal.py@@ -80,7 +80,10 @@ from products.replay_vision.backend.temporal.activities.observation_state importmark_observation_running_activity,mark_observation_succeeded_activity,)-from products.replay_vision.backend.temporal.activities.upload_video_to_gemini import upload_video_to_gemini_activity+from products.replay_vision.backend.temporal.activities.upload_video_to_gemini import (+ _write_and_upload,+ upload_video_to_gemini_activity,+)from products.replay_vision.backend.temporal.errors import (INELIGIBLE_SESSION_ERROR_TYPE,SCANNER_ADMISSION_BUSY_ERROR_TYPE,@@ -3076,6 +3079,28 @@ class TestClassifyGeminiError:assert classify_gemini_error(ValueError("bad arg")) is None+class TestUploadFinalizeFailures:+ @parameterized.expand(+ [+ ("missing_file_key", KeyError("file")),+ ("empty_body", TypeError("string indices must be integers, not 'str'")),+ ("status_not_final", ValueError("Failed to upload file: Upload status is not finalized.")),+ ("chunks_not_final", ValueError("All content has been uploaded, but the upload status is not finalized.")),+ (+ "no_upload_url",+ KeyError("Failed to create file. Upload URL did not returned from the create file request."),+ ),+ ]+ )+ def test_maps_sdk_upload_failures_to_provider_transient(self, _label: str, error: Exception) -> None:+ raw_client = MagicMock()+ raw_client.files.upload.side_effect = error+ with pytest.raises(ScannerFailureError) as exc_info:+ _write_and_upload(raw_client, b"mp4", "video/mp4", "wf-1")+ assert exc_info.value.kind is FailureKind.PROVIDER_TRANSIENT+ assert exc_info.value.message == "The AI provider did not finish the video upload"++class TestGeminiErrorRedaction:"""`error_reason` is shown to the user verbatim, and a Gemini error body can quote request content(prompt text, file references). The provider-facing activities must surface only the fixed summary."""