: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): keep inline scanners to template questions (#109435)
Tue Haulund27f372f48595
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex ebb5c5f57d01..3ec8db75e566 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11834,6 +11834,10 @@ snapshots:hash: v1.k794b7964.46c3676ea704fe9e4f852ad3d2cfc4cbf52b73702f85ab5dcd8da3e5f9942e11.tDpspUfV1-0J6Je388a-zL5Hz4GF08OZxN07HDDjaSIscenes-app-replay-vision--observation-detail-feedback-prompt--light:hash: v1.k794b7964.a6f7ac9bb7bf41efdf053f3ddbb1197a34a1520338163ce7f62bd9cdf4eccdc8.1USpUTscp78iHSfe0PsOCAZQc7OvoJjbFswIbwH-byA+ scenes-app-replay-vision--observation-detail-inline-scan--dark:+ hash: v1.k794b7964.469118c967c1853dac03f00d28c4e7d7e188bb1d8ae75b3d511adea3342dd2dd.mEelxIjF-c3I38H9laWSDr0ifGTsU3uARojIGp-L0o4+ scenes-app-replay-vision--observation-detail-inline-scan--light:+ hash: v1.k794b7964.0bb6a64fd2139185b9d87b50dfb0944d0f6ca8a41a9ecd295703ce0b890b3f27.EVRjxz1f12rueYw5_6Y02wLMEEFPk-3dcSyPX1xnaPgscenes-app-replay-vision--observation-detail-monitor--dark:hash: v1.k794b7964.1e35aa5e9f235571af2f50dde85f00309d3da79d05c703ba240ec3cdc3c7a879.70bC14X0u8NTb7_zoTehmiN4cQCy61tmjKiEgEHZV-Uscenes-app-replay-vision--observation-detail-monitor--light:@@ -11854,6 +11858,10 @@ snapshots:hash: v1.k794b7964.2517a855343f68c1423542c539840c5398a38fa2ac275fde776d25ef4669c68c.wIVR49t9ZcB53TpdbiV-N-1jq9ISB4jHWg4drk1m3cAscenes-app-replay-vision--observation-detail-scorer--light:hash: v1.k794b7964.d2913d4e783c2f87536a851a63426e083d286806b064e2d42e34849b633f3a3e.9D-FS9PdTLBLBV9kIWUzvapu97SHdq0MrQB3F0fYMnQ+ scenes-app-replay-vision--observation-detail-summarize-button--dark:+ hash: v1.k794b7964.de611d0919ecdbf574e0cc68b87ff8b43d4b693a48925708ac38dc8222af6ad5.Cebsg_fmVC59ZMN6ibQn30wWdRYEzymxgtM06GnDWCU+ scenes-app-replay-vision--observation-detail-summarize-button--light:+ hash: v1.k794b7964.9b24f17d0296ba5dcfb8e2f03af9a0e13b0277160c24381c502f12189c4f8861.eWuSEs61l3ZPVMmiB3dxWKyehhuyoczwyZYaScexYMAscenes-app-replay-vision--scanner-alerts--dark:hash: v1.k794b7964.07adaa26f0b868d6c64d7d99e3d1a317307dff376b1dc5d740c9c9cc9c2ff926.c9kS5X0nGVIU2VHq4sxwidzwpjG5bpqnlvPM-r8yEf8scenes-app-replay-vision--scanner-alerts--light:diff --git a/products/replay_vision/backend/inline_scan.py b/products/replay_vision/backend/inline_scan.pyindex 10a130c7f36f..e10d0bc62d85 100644--- a/products/replay_vision/backend/inline_scan.py+++ b/products/replay_vision/backend/inline_scan.py@@ -18,7 +18,7 @@ from posthog.models.team import Teamfrom products.replay_vision.backend.fingerprint import config_fingerprintfrom products.replay_vision.backend.models.replay_scanner import ReplayScanner, ScannerOrigin, ScannerType-from products.replay_vision.backend.prompt_questions import condense_prompt+from products.replay_vision.backend.prompt_questions import template_questiondef inline_scan_key(*, scanner_type: str, scanner_config: dict[str, Any], model: str) -> str:@@ -51,7 +51,8 @@ def create_inline_scanner(moment, and it wraps the losing INSERT in a savepoint so the unique violation doesn't poison anenclosing transaction."""- question = condense_prompt(team_id=team.id, scanner_type=scanner_type, scanner_config=scanner_config)+ # One-off scans skip the model call; only a template's written question, such as the Summarize button's, is kept.+ question = template_question(scanner_config)scanner, _ = ReplayScanner.all_origins.get_or_create(team=team,origin=ScannerOrigin.INLINE,@@ -66,7 +67,7 @@ def create_inline_scanner("created_by": None,"scanner_type": scanner_type,"scanner_config": scanner_config,- **question.as_fields(),+ **(question.as_fields() if question else {}),"model": model,# Nothing to sweep: no query, and disabled, which is what actually gates scheduling."enabled": False,diff --git a/products/replay_vision/backend/management/commands/backfill_replay_scanner_prompt_questions.py b/products/replay_vision/backend/management/commands/backfill_replay_scanner_prompt_questions.pyindex c9bdfda4db48..e04d6f7f1a3a 100644--- a/products/replay_vision/backend/management/commands/backfill_replay_scanner_prompt_questions.py+++ b/products/replay_vision/backend/management/commands/backfill_replay_scanner_prompt_questions.py@@ -11,7 +11,9 @@ class Command(BaseCommand):def add_arguments(self, parser: CommandParser) -> None:parser.add_argument("--team-id", type=int, default=None, help="Only this team's scanners")parser.add_argument(- "--include-inline", action="store_true", help="Also cover inline scanners minted by one-off scans"+ "--include-inline",+ action="store_true",+ help="Also give inline scanners a template's question; they never get a model-written one",)parser.add_argument("--limit", type=int, default=None, help="Stop after writing this many questions")parser.add_argument("--dry-run", action="store_true", help="Count the scanners due a question, write nothing")diff --git a/products/replay_vision/backend/models/replay_scanner.py b/products/replay_vision/backend/models/replay_scanner.pyindex 4177dca09f3a..292428c85eab 100644--- a/products/replay_vision/backend/models/replay_scanner.py+++ b/products/replay_vision/backend/models/replay_scanner.py@@ -283,8 +283,8 @@ class ReplayScanner(Taggable, ModelActivityMixin, UUIDModel):help_text="When the Search tab last asked for this scanner's suggestions. Only viewed scanners refresh.",)- # Written with the prompt by every path that sets one, see `prompt_questions`. Not version-tracked: it- # restates the prompt and changes nothing about how the scanner scans.+ # Written with the prompt by every path that sets one, see `prompt_questions`; inline scanners keep only a+ # template's question. Not version-tracked: it restates the prompt and changes nothing about how the scanner scans.prompt_question = models.TextField(blank=True,default="",diff --git a/products/replay_vision/backend/prompt_questions.py b/products/replay_vision/backend/prompt_questions.pyindex 66043628a2b0..6a36d7ae167d 100644--- a/products/replay_vision/backend/prompt_questions.py+++ b/products/replay_vision/backend/prompt_questions.py@@ -146,6 +146,14 @@ def _take_model_call(team_id: int) -> bool:return calls <= MAX_MODEL_CALLS_PER_TEAM_PER_HOUR+def template_question(scanner_config: object) -> PromptQuestion | None:+ """The written question for a template's exact prompt, or None for any other prompt. Needs no model call."""+ prompt = _prompt_of(scanner_config)+ if prompt not in TEMPLATE_QUESTIONS:+ return None+ return PromptQuestion(question=TEMPLATE_QUESTIONS[prompt], source=prompt_fingerprint(prompt))++def condense_prompt(*, team_id: int, scanner_type: str, scanner_config: object, metered: bool = True) -> PromptQuestion:"""The question for this prompt. Never raises: without a usable model answer it falls back to the prompt'sfirst line, so every scanner carries a question to show. `metered` counts the call against the team's@@ -154,8 +162,8 @@ def condense_prompt(*, team_id: int, scanner_type: str, scanner_config: object,source = prompt_fingerprint(prompt)if not prompt.strip():return PromptQuestion(question="", source=source)- if prompt in TEMPLATE_QUESTIONS:- return PromptQuestion(question=TEMPLATE_QUESTIONS[prompt], source=source)+ if (template := template_question(scanner_config)) is not None:+ return templatequestion = None# The prompt is the team's own text, but it still only goes to the model under the org's AI consent.if is_ai_data_processing_approved(team_id) and (not metered or _take_model_call(team_id)):@@ -214,6 +222,7 @@ def backfill_prompt_questions(Writes through a queryset update, so the scanner's version, updated_at and activity log stay untouched.The update is conditional on the prompt still being the one condensed, so an edit that lands mid-run wins.Each distinct prompt is condensed once per run and scanner type, since many scanners share one word for word.+ Inline scanners only take a template's question, the same rule `create_inline_scanner` follows."""scanners = ReplayScanner.all_origins.order_by("created_at")if not include_inline:@@ -223,7 +232,7 @@ def backfill_prompt_questions(checked = written = 0condensed: dict[tuple[str, str], PromptQuestion] = {}for scanner in scanners.only(- "id", "team_id", "scanner_type", "scanner_config", "prompt_question_source"+ "id", "team_id", "origin", "scanner_type", "scanner_config", "prompt_question_source").iterator():if limit is not None and written >= limit:break@@ -231,12 +240,15 @@ def backfill_prompt_questions(source = prompt_fingerprint(_prompt_of(scanner.scanner_config))if source == scanner.prompt_question_source:continue+ inline_template = template_question(scanner.scanner_config) if scanner.origin == ScannerOrigin.INLINE else None+ if scanner.origin == ScannerOrigin.INLINE and inline_template is None:+ continueif dry_run:written += 1continue# The phrasing depends on the scanner type, so the same prompt on another type gets its own question.key = (source, scanner.scanner_type)- question = condensed.get(key)+ question = inline_template or condensed.get(key)if question is None:question = condense_prompt(team_id=scanner.team_id,diff --git a/products/replay_vision/backend/tests/test_prompt_questions.py b/products/replay_vision/backend/tests/test_prompt_questions.pyindex 288937cf0050..9dd4be6115fb 100644--- a/products/replay_vision/backend/tests/test_prompt_questions.py+++ b/products/replay_vision/backend/tests/test_prompt_questions.py@@ -9,6 +9,7 @@ from django.utils import timezonefrom parameterized import parameterized+from products.replay_vision.backend.inline_scan import create_inline_scannerfrom products.replay_vision.backend.models.replay_observation import (ObservationStatus,ObservationTrigger,@@ -235,3 +236,29 @@ class TestPromptQuestions(APIBaseTest):assert stale.prompt_question_source == prompt_fingerprint(PROMPT)assert stale.scanner_version == versionassert ReplayScanner.objects.get(pk=fresh.pk).prompt_question == "Kept as is?"++ def test_inline_scanners_only_ever_get_a_template_question(self) -> None:+ self.client_mock.return_value.models.generate_content.reset_mock()+ summarize = create_inline_scanner(+ team=self.team,+ key="summarize-button",+ scanner_type=ScannerType.MONITOR,+ scanner_config={"prompt": TEMPLATE_PROMPT},+ model=ScannerModel.GEMINI_3_8_FLASH,+ )+ custom = create_inline_scanner(+ team=self.team,+ key="one-off",+ scanner_type=ScannerType.MONITOR,+ scanner_config={"prompt": "Did the user open the pricing page?"},+ model=ScannerModel.GEMINI_3_8_FLASH,+ )+ assert (summarize.prompt_question, custom.prompt_question) == (TEMPLATE_QUESTION, "")+ ReplayScanner.all_origins.filter(pk=summarize.pk).update(prompt_question="", prompt_question_source="")++ result = backfill_prompt_questions(team_id=self.team.id, include_inline=True)++ assert result.written == 1+ assert ReplayScanner.all_origins.get(pk=summarize.pk).prompt_question == TEMPLATE_QUESTION+ assert ReplayScanner.all_origins.get(pk=custom.pk).prompt_question == ""+ self.client_mock.return_value.models.generate_content.assert_not_called()diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsxindex 4881aedc51d0..c26b43abc4b6 100644--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx@@ -1628,6 +1628,56 @@ const inconclusiveObservationDetail = observation({export const ObservationDetailMonitorInconclusive: StoryObj = observationDetailStory(inconclusiveObservationDetail)+// The Session Replay "Summarize" button mints an inline scanner with the session summary template's prompt, so+// its observations carry that template's written question.+const summarizeButtonObservationDetail = observation({+ id: '00000000-0000-0000-0000-0000000000da',+ scanner_id: '00000000-0000-0000-0000-00000000001a',+ scanner_origin: 'inline',+ recording_subject_email: '[email protected]',+ distinct_id: 'user_2m1x9d',+ prompt_question: 'What did the user do in this session?',+ scanner_snapshot: {+ ...observation().scanner_snapshot!,+ name: '',+ scanner_config: {+ prompt: "Summarize what the user did in this session: which pages they visited, what they tried to accomplish, and any notable moments like errors, confusion, or successful completions. Be concrete and don't speculate.",+ length: 'medium',+ },+ },+})++export const ObservationDetailSummarizeButton: StoryObj = observationDetailStory(summarizeButtonObservationDetail)++// A one-off scan asked through PostHog AI or MCP: an inline scanner with its own prompt and no written question.+const inlineScanObservationDetail = observation({+ ...monitorObservationDetail,+ id: '00000000-0000-0000-0000-0000000000db',+ scanner_id: '00000000-0000-0000-0000-00000000001b',+ scanner_origin: 'inline',+ prompt_question: null,+ previous_observation_id: null,+ next_observation_id: null,+ scanner_snapshot: {+ ...monitorObservationDetail.scanner_snapshot!,+ name: '',+ scanner_config: { prompt: 'Did the user open the pricing page and leave without upgrading?' },+ },+ scanner_result: {+ model_output: {+ scanner_type: 'monitor',+ confidence: 0.9,+ verdict: 'yes',+ reasoning:+ 'The user opened the pricing page twice, expanded the plan comparison, and left the app from there both times without starting a checkout.',+ },+ signals_count: 0,+ verification: null,+ },+})++export const ObservationDetailInlineScan: StoryObj = observationDetailStory(inlineScanObservationDetail)+export const ObservationDetailFeedbackPrompt: StoryObj = {parameters: {pageUrl: urls.replayVisionObservation(thumbsDownObservationDetail.id),