: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
feat(replay-vision): report chunk error types on the sweep judged event (#109677)
Kim Svatos Dugan9cfd168b0579
diff --git a/products/replay_vision/backend/jev_watch_feed.py b/products/replay_vision/backend/jev_watch_feed.pyindex 18cbae88846c..e8deb880ea9b 100644--- a/products/replay_vision/backend/jev_watch_feed.py+++ b/products/replay_vision/backend/jev_watch_feed.py@@ -172,6 +172,10 @@ class WindowJudgment:model: str | Nonechunks: intfailed_chunks: int+ # Failed chunks keyed by exception class name. The Prometheus counter carries the same+ # breakdown, but prod workers do not ship their metrics into the product; the sweep's+ # judged event does, so a failing sweep names its error without log or cluster access.+ chunk_error_types: dict[str, int]input_tokens: intestimated_cost_usd: float@@ -277,6 +281,7 @@ def judge_scanner_window(batch_failed_ids: list[str] = []model: str | None = Nonefailed_chunks = 0+ chunk_error_types: dict[str, int] = {}input_tokens = 0estimated_cost = 0.0for chunk in chunks:@@ -288,8 +293,10 @@ def judge_scanner_window()except Exception as error:_LATENCY.observe(perf_counter() - started)- _CALLS.labels(type(error).__name__).inc()+ error_type = type(error).__name__+ _CALLS.labels(error_type).inc()failed_chunks += 1+ chunk_error_types[error_type] = chunk_error_types.get(error_type, 0) + 1# An invalid answer or a batch-caused gateway refusal charges the retry budget. A# missing gateway config raises a ValueError subclass and must not sneak in through# the invalid-answer check: it fails every chunk alike, so its rows retry free, the@@ -304,7 +311,7 @@ def judge_scanner_window("Jev watch rank chunk failed",team_id=team_id,scanner_id=str(scanner_id),- error_type=type(error).__name__,+ error_type=error_type,)continue_LATENCY.observe(perf_counter() - started)@@ -323,6 +330,7 @@ def judge_scanner_window(model=model,chunks=len(chunks),failed_chunks=failed_chunks,+ chunk_error_types=chunk_error_types,input_tokens=input_tokens,estimated_cost_usd=estimated_cost,)diff --git a/products/replay_vision/backend/temporal/jev_watch_rank/activities.py b/products/replay_vision/backend/temporal/jev_watch_rank/activities.pyindex e78359ad0c66..5414841e359e 100644--- a/products/replay_vision/backend/temporal/jev_watch_rank/activities.py+++ b/products/replay_vision/backend/temporal/jev_watch_rank/activities.py@@ -241,6 +241,7 @@ async def _judge_watch_ranks(inputs: JevWatchRankSweepInputs) -> JevWatchRankSwe),"chunks": judgment.chunks,"failed_chunks": judgment.failed_chunks,+ "chunk_error_types": judgment.chunk_error_types,"jev_model": judgment.model,"input_tokens": judgment.input_tokens,"estimated_cost_usd": judgment.estimated_cost_usd,diff --git a/products/replay_vision/backend/tests/test_jev_watch_feed.py b/products/replay_vision/backend/tests/test_jev_watch_feed.pyindex 2fac02c28427..5a564a68d3a6 100644--- a/products/replay_vision/backend/tests/test_jev_watch_feed.py+++ b/products/replay_vision/backend/tests/test_jev_watch_feed.py@@ -124,6 +124,7 @@ class TestJudgeScannerWindow(SimpleTestCase):assert len(judgment.probabilities) == 6# An unavailable decision service is not the batch's fault, so no retry budget is charged.assert judgment.batch_failed_ids == ()+ assert judgment.chunk_error_types == {"DecisionsDisabledError": 1}def test_an_invalid_probability_fails_the_whole_chunk(self) -> None:rows = [_prose_row(uuid4(), "summary")]@@ -134,6 +135,7 @@ class TestJudgeScannerWindow(SimpleTestCase):assert judgment.failed_chunks == 1# An invalid answer is the batch's own fault, so its rows are charged a retry attempt.assert judgment.batch_failed_ids == (str(rows[0]["id"]),)+ assert judgment.chunk_error_types == {"ValueError": 1}@parameterized.expand([@@ -164,6 +166,7 @@ class TestJudgeScannerWindow(SimpleTestCase):judgment = judge_scanner_window(1, uuid4(), rows)assert judgment.failed_chunks == 1assert judgment.batch_failed_ids == ()+ assert judgment.chunk_error_types == {"GatewayNotConfiguredError": 1}def test_rows_without_prose_are_reported_instead_of_sent(self) -> None:no_output, no_result = uuid4(), uuid4()@@ -530,12 +533,18 @@ class TestJevWatchRankSweep(BaseTest):patch(f"{activities}.watch_feed_ranker", side_effect=self._flag_arm("jev-shadow")),patch(f"{activities}.decision_api.decisions_available_here", return_value=True),patch(_API) as api,- patch("posthoganalytics.capture"),+ patch("posthoganalytics.capture") as captured,):api.decide_when_available.side_effect = DecisionsDisabledError(self.team.id)result = async_to_sync(_judge_watch_ranks)(JevWatchRankSweepInputs())assert result.failed_chunks == 1assert result.observations_given_up == 0+ # The judged event names the failure class, so a broken sweep is diagnosable from the+ # product alone — worker logs and Prometheus never leave the cluster.+ judged = [+ call for call in captured.call_args_list if call.kwargs["event"] == "replay_vision_jev_watch_rank_judged"+ ]+ assert judged[0].kwargs["properties"]["chunk_error_types"] == {"DecisionsDisabledError": 1}for attempt in range(1, MAX_JUDGE_ATTEMPTS + 1):with (