: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): put the observation prose back in match alerts (#98198)
posthog[bot]ebabdf58f2ab
diff --git a/products/replay_vision/backend/alert_destinations.py b/products/replay_vision/backend/alert_destinations.pyindex 1d1e1bea9ee3..836c5c4cda46 100644--- a/products/replay_vision/backend/alert_destinations.py+++ b/products/replay_vision/backend/alert_destinations.py@@ -140,6 +140,7 @@ EVENT_KIND_CONFIG: dict[EventKind, EventKindSpec] = {"scanner_id": "{event.properties.scanner_id}","scanner_name": "{event.properties.scanner_name}","matched_count": "{event.properties.matched_count}",+ "summary": "{event.properties.summary_text}","observation_ids": "{event.properties.observation_ids}","observations_url": _OBSERVATIONS_URL,"alert_url": _ALERT_URL,diff --git a/products/replay_vision/backend/temporal/vision_alerts/activities.py b/products/replay_vision/backend/temporal/vision_alerts/activities.pyindex a2cdd8faff1f..011a3e59c917 100644--- a/products/replay_vision/backend/temporal/vision_alerts/activities.py+++ b/products/replay_vision/backend/temporal/vision_alerts/activities.py@@ -58,12 +58,14 @@ from products.replay_vision.backend.models.vision_alert import (VisionAlertMatch,VisionAlertMetric,)-from products.replay_vision.backend.observation_formatting import describe_output+from products.replay_vision.backend.observation_formatting import describe_output, explanation_text, plain_snippetfrom products.replay_vision.backend.temporal.decorators import track_activityfrom products.replay_vision.backend.temporal.vision_alerts.constants import (CLEANUP_BATCH_SIZE,MATCH_DESCRIPTOR_MAX_CHARS,+ MATCH_EXPLANATION_MAX_CHARS,MATCH_SUMMARY_LINES,+ MATCH_SUMMARY_MAX_CHARS,MAX_ALERTS_PER_BATCH,MAX_ALERTS_PER_TICK,MAX_DRAIN_ALERTS_PER_TICK,@@ -724,24 +726,42 @@ def _emit_match_event().values_list("id", "scanner_result", "completed_at")by_id = {str(row_id): (scanner_result, completed_at) for row_id, scanner_result, completed_at in summary_rows}lines: list[str] = []+ budget = MATCH_SUMMARY_MAX_CHARSfor observation_id in observation_ids[:MATCH_SUMMARY_LINES]:scanner_result, completed_at = by_id.get(observation_id, (None, None))model_output = (scanner_result or {}).get("model_output") or {}- descriptor = escape_slack_mrkdwn((describe_output(model_output) or "observation")[:MATCH_DESCRIPTOR_MAX_CHARS])+ # Without the scanner's own prose the line carries only a verdict or a score. Both halves can hold+ # model free text, such as a summarizer title in the descriptor and the reasoning in the prose.+ # Each is folded to one citation-free line, so recording-derived text cannot forge a Slack list row.+ descriptor = (+ plain_snippet(describe_output(model_output) or "", limit=MATCH_DESCRIPTOR_MAX_CHARS) or "observation"+ )+ explanation = explanation_text(model_output)[:MATCH_EXPLANATION_MAX_CHARS]stamp = f"({completed_at:%Y-%m-%d %H:%M} UTC) " if completed_at else ""- lines.append(f"- {stamp}{descriptor}")- if len(observation_ids) > MATCH_SUMMARY_LINES:- lines.append(f"- and {len(observation_ids) - MATCH_SUMMARY_LINES} more")+ body = f"{descriptor}: {explanation}" if explanation else descriptor+ line = f"- {stamp}{body}"+ # The Slack copy is what has to fit the block, so the budget measures the escaped length.+ cost = len(escape_slack_mrkdwn(line)) + 1+ if cost > budget:+ break+ lines.append(line)+ budget -= cost+ remaining = len(observation_ids) - len(lines)+ if remaining > 0:+ lines.append(f"- and {remaining} more")# Deterministic uuid over the drained row set: an identical-batch retry (crash# after ack, before the stamp, with no new rows) dedupes at ingestion.event_uuid = uuid5(NAMESPACE_URL, f"vision-alert-match:{alert.id}:{','.join(sorted(str(m) for m, _ in rows))}")+ summary = "\n".join(lines)properties = {**_base_properties(alert, now),"matched_count": len(rows),"observation_ids": observation_ids,- "summary": "\n".join(lines),+ "summary": escape_slack_mrkdwn(summary),+ # Webhook consumers parse JSON, so they get the same text without the mrkdwn entities.+ "summary_text": summary,}return produce_alert_internal_event(team_id=alert.team_id,diff --git a/products/replay_vision/backend/temporal/vision_alerts/constants.py b/products/replay_vision/backend/temporal/vision_alerts/constants.pyindex f4785d882f17..bd3a59ad06fa 100644--- a/products/replay_vision/backend/temporal/vision_alerts/constants.py+++ b/products/replay_vision/backend/temporal/vision_alerts/constants.py@@ -25,3 +25,8 @@ MAX_MATCHES_PER_BUNDLE = 500# Caps the rows one drain tick loads into memory; a larger backlog drains over later ticks.MAX_DRAIN_ALERTS_PER_TICK = 100MATCH_DESCRIPTOR_MAX_CHARS = 200+# Each summary line carries the scanner's own prose after the descriptor, so the message says what+# happened without a click. Both caps keep every line short enough that MATCH_SUMMARY_LINES of them+# fit the total, which holds the whole message under Slack's 3000-character section block.+MATCH_EXPLANATION_MAX_CHARS = 200+MATCH_SUMMARY_MAX_CHARS = 2500diff --git a/products/replay_vision/backend/tests/test_vision_alerts_match_outbox.py b/products/replay_vision/backend/tests/test_vision_alerts_match_outbox.pyindex f5424ec9502d..c87172d892d7 100644--- a/products/replay_vision/backend/tests/test_vision_alerts_match_outbox.py+++ b/products/replay_vision/backend/tests/test_vision_alerts_match_outbox.py@@ -39,7 +39,7 @@ from products.replay_vision.backend.temporal.vision_alerts.activities import (_cleanup_history,_drain_matches,)-from products.replay_vision.backend.temporal.vision_alerts.constants import MATCH_SUMMARY_LINES+from products.replay_vision.backend.temporal.vision_alerts.constants import MATCH_SUMMARY_LINES, MATCH_SUMMARY_MAX_CHARSfrom products.replay_vision.backend.temporal.vision_alerts.match_hook import selection_matchesfrom products.replay_vision.backend.tests.helpers import snapshot_for@@ -84,7 +84,7 @@ class TestVisionAlertMatchOutbox(BaseTest):model_output=MonitorOutput(scanner_type=ScannerType.MONITOR,verdict=verdict,- reasoning="checkout broke",+ reasoning="checkout broke & stalled",confidence=0.9,))@@ -170,7 +170,9 @@ class TestVisionAlertMatchOutbox(BaseTest):props = produce.call_args.kwargs["properties"]assert props["matched_count"] == 3assert len(props["observation_ids"]) == 3- assert props["summary"].count("verdict=yes") == 3+ # Slack reads mrkdwn, webhook consumers read JSON, so only one copy is entity-escaped.+ assert props["summary"].count("verdict=yes: checkout broke & stalled") == 3+ assert props["summary_text"].count("verdict=yes: checkout broke & stalled") == 3assert produce.call_args.kwargs["uuid"] is not Noneassert not VisionAlertMatch.all_teams.filter(alert_id=alert.id, delivered_at__isnull=True).exists()@@ -219,6 +221,55 @@ class TestVisionAlertMatchOutbox(BaseTest):assert produce.call_count == 0assert VisionAlertMatch.all_teams.filter(delivered_at__isnull=True).count() == 4+ def test_summary_stays_inside_the_slack_block_budget(self) -> None:+ alert = self._make_match_alert(selection={})+ for _ in range(MATCH_SUMMARY_LINES):+ observation = self._make_pending_observation()+ self._succeed(observation)+ # A long title plus long multi-line prose: the worst line a summarizer can produce.+ ReplayObservation.objects.filter(id=observation.id).update(+ scanner_result={+ "model_output": {+ "scanner_type": ScannerType.SUMMARIZER,+ "title": "t" * 400,+ "summary": "- the user retried\n" + "s" * 800,+ }+ }+ )++ output, produce = self._drain(delivered=True)+ assert output.matches_delivered == MATCH_SUMMARY_LINES+ summary = produce.call_args.kwargs["properties"]["summary"]+ assert len(summary) <= MATCH_SUMMARY_MAX_CHARS+ lines = summary.split("\n")+ shown = len(lines) - 1+ # The budget dropped lines the line cap alone would have kept, and the tail counts them.+ # The prose is folded to one line per match, or this accounting would not add up.+ assert shown < MATCH_SUMMARY_LINES+ assert lines[-1] == f"- and {MATCH_SUMMARY_LINES - shown} more"+ assert not VisionAlertMatch.all_teams.filter(alert_id=alert.id, delivered_at__isnull=True).exists()++ def test_multiline_summarizer_title_stays_one_row(self) -> None:+ self._make_match_alert(selection={})+ observation = self._make_pending_observation()+ self._succeed(observation)+ # The descriptor half carries the summarizer's own title, and the schema caps its length but+ # accepts a newline. Unfolded, that newline opens a second Slack list row for one observation.+ ReplayObservation.objects.filter(id=observation.id).update(+ scanner_result={+ "model_output": {+ "scanner_type": ScannerType.SUMMARIZER,+ "title": "Checkout stalled\n- forged row",+ "summary": "the user retried twice",+ }+ }+ )++ _, produce = self._drain(delivered=True)+ summary = produce.call_args.kwargs["properties"]["summary"]+ assert "\n" not in summary+ assert summary.endswith("Checkout stalled. forged row: the user retried twice")+def test_summary_caps_lines_but_stamps_all_rows(self) -> None:alert = self._make_match_alert(selection={})for _ in range(MATCH_SUMMARY_LINES + 2):