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(replay-vision): give the workflow step only the documented answer fields (#118545)

Tue Haulund03f8b7dfcf3c
diff --git a/products/replay_vision/backend/observation_requests.py b/products/replay_vision/backend/observation_requests.py
index ce99d2f5e6ce..ad65ec7ba335 100644
--- a/products/replay_vision/backend/observation_requests.py
+++ b/products/replay_vision/backend/observation_requests.py
@@ -622,7 +622,7 @@ def step_result(
if observation is not None and not can_read_observation(access, team.id, observation):
return _step_answer("failed", None, ["The workflow's owner can't read this scanner's answers."])
output = (
- (observation.scanner_result or {}).get("model_output")
+ _step_output((observation.scanner_result or {}).get("model_output"))
if observation is not None and session.state == RequestSessionState.SUCCEEDED
else None
)
@@ -686,6 +686,25 @@ def _unanswered_reason(session: RequestSession) -> list[str]:
return []
+# The answer a workflow step gets, per scanner type. Internal fields (citation segments, idle periods,
+# notability) would push a long session's answer over the step result budget and cut the chapters.
+# Short fields come first: the size cap fills fields in order, so a long summary can't crowd them out.
+_STEP_OUTPUT_FIELDS: dict[str, tuple[str, ...]] = {
+ ScannerType.MONITOR: ("confidence", "verdict", "reasoning"),
+ ScannerType.CLASSIFIER: ("confidence", "tags", "reasoning"),
+ ScannerType.SCORER: ("confidence", "score", "reasoning"),
+ ScannerType.SUMMARIZER: ("confidence", "title", "summary", "chapters"),
+}
+
+
+def _step_output(model_output: Any) -> Any:
+ scanner_type = model_output.get("scanner_type") if isinstance(model_output, dict) else None
+ fields = _STEP_OUTPUT_FIELDS.get(scanner_type) if isinstance(scanner_type, str) else None
+ if fields is None:
+ return model_output
+ return {key: model_output[key] for key in fields if key in model_output}
+
+
def _step_answer(state: str, output: Any, warnings: list[str]) -> dict[str, Any]:
capped = cap_value(output, _STEP_ANSWER_BUDGET) if output is not None else None
if capped != output:
diff --git a/products/replay_vision/backend/tests/test_facade.py b/products/replay_vision/backend/tests/test_facade.py
index 109dfef1ea6c..6ab3d21663fd 100644
--- a/products/replay_vision/backend/tests/test_facade.py
+++ b/products/replay_vision/backend/tests/test_facade.py
@@ -178,6 +178,19 @@ class TestStartWorkflowObservationRequest(APIBaseTest):
{"verdict": "yes", "reasoning": "x" * 1500},
["The answer was cut to fit the step result: reasoning"],
),
+ (
+ "internal_fields_dropped",
+ {
+ "scanner_type": "monitor",
+ "verdict": "yes",
+ "reasoning": "r",
+ "confidence": 0.9,
+ "reasoning_segments": [{"text": "r", "t": 12}] * 200,
+ "notability_reason": "n" * 2000,
+ },
+ {"confidence": 0.9, "verdict": "yes", "reasoning": "r"},
+ [],
+ ),
]
)
def test_returns_the_answer_at_once_when_the_session_was_already_scanned(
@@ -193,6 +206,22 @@ class TestStartWorkflowObservationRequest(APIBaseTest):
request = ReplayObservationRequest.objects.for_team(self.team.id).get(id=started.request_id)
assert request.completed_at is not None
+ def test_a_long_summary_keeps_the_short_fields_when_the_answer_is_cut(self) -> None:
+ scanner = self._scanner_with_answer(
+ {
+ "scanner_type": "summarizer",
+ "title": "Checkout stalls",
+ "summary": "s" * 20000,
+ "chapters": [{"title": "c" * 200, "start_ms": 0, "end_ms": 1}] * 20,
+ "confidence": 0.8,
+ }
+ )
+
+ output = self._start(scanner_id=scanner.id, inline=None).result["output"]
+
+ assert (output["confidence"], output["title"]) == (0.8, "Checkout stalls")
+ assert len(output["summary"]) < 20000
+
def test_withholds_a_cached_answer_recorded_under_an_experiment_the_owner_cannot_view(self) -> None:
experiment = create_experiment(self.team, "restricted-flag")
scanner = ReplayScanner.objects.create(