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(error-tracking): stop the on-create summary from stating a count (#125763)

James Gill6eb1b2e4c77d
diff --git a/products/error_tracking/backend/logic/issue_summaries.py b/products/error_tracking/backend/logic/issue_summaries.py
index 68af55f52f1c..5e608fd32016 100644
--- a/products/error_tracking/backend/logic/issue_summaries.py
+++ b/products/error_tracking/backend/logic/issue_summaries.py
@@ -85,6 +85,8 @@ from products.error_tracking.backend.logic.issue_summary_config import (
from products.error_tracking.backend.logic.issue_summary_prompt import (
ISSUE_SUMMARY_CATEGORY_QUESTION,
ISSUE_SUMMARY_CATEGORY_QUESTION_ID,
+ ISSUE_SUMMARY_IMPACT_LINE,
+ ISSUE_SUMMARY_IMPACT_NOT_KNOWN_YET,
ISSUE_SUMMARY_INPUT_TEMPLATE,
ISSUE_SUMMARY_PROMPT_VERSION,
ISSUE_SUMMARY_SYSTEM_PROMPT,
@@ -817,7 +819,6 @@ def build_issue_summary_inputs_from_event(
stack_trace = _summary_stack_trace(source_properties)
if not stack_trace:
return IssueSummaryOutcome.NO_EXCEPTION
- session_id = event_properties.get("$session_id")
return _summary_inputs(
team,
issue_id,
@@ -825,7 +826,7 @@ def build_issue_summary_inputs_from_event(
event_properties=source_properties,
first_event_properties=source_properties,
stack_trace=stack_trace,
- impact={"occurrences": 1, "users": 1, "sessions": 1 if isinstance(session_id, str) and session_id else 0},
+ impact=None,
trend={},
)
@@ -848,7 +849,7 @@ def _summary_inputs(
event_properties: dict[str, object],
first_event_properties: dict[str, object],
stack_trace: str,
- impact: dict[str, object],
+ impact: dict[str, object] | None,
trend: dict[str, object],
) -> IssueSummaryInputs:
latest_release = extract_release(event_properties).get("version")
@@ -870,9 +871,7 @@ def _summary_inputs(
"trend_direction": _text(trend.get("direction")),
"previous_occurrences": _count(trend.get("previous_occurrences")),
"current_occurrences": _count(trend.get("current_occurrences")),
- "occurrences": _count(impact.get("occurrences")),
- "users": _count(impact.get("users")),
- "sessions": _count(impact.get("sessions")),
+ "impact": _impact_line(impact),
}
prompt = ISSUE_SUMMARY_INPUT_TEMPLATE.format(
**{name: ISSUE_FENCE_TAG.sub("", value) for name, value in fields.items()}
@@ -882,7 +881,9 @@ def _summary_inputs(
"fingerprint", flat=True
)
)
- occurrences = to_number(impact.get("occurrences"))
+ # A new issue holds only its first event, so it hashes as the one occurrence the read path counts.
+ # The first read then finds the hash unchanged unless the issue grew.
+ occurrences = to_number(impact.get("occurrences")) if impact is not None else 1
return IssueSummaryInputs(
prompt=prompt,
input_hash=compute_input_hash(
@@ -931,6 +932,16 @@ def _count(value: object) -> str:
return str(int(number)) if number is not None else UNKNOWN
+def _impact_line(impact: dict[str, object] | None) -> str:
+ if impact is None:
+ return ISSUE_SUMMARY_IMPACT_NOT_KNOWN_YET
+ return ISSUE_SUMMARY_IMPACT_LINE.format(
+ occurrences=_count(impact.get("occurrences")),
+ users=_count(impact.get("users")),
+ sessions=_count(impact.get("sessions")),
+ )
+
+
def _exception_event_properties(
team: Team, issue_id: UUID | str, *, after: datetime, before: datetime, latest: bool
) -> dict[str, object]:
diff --git a/products/error_tracking/backend/logic/issue_summary_prompt.py b/products/error_tracking/backend/logic/issue_summary_prompt.py
index dbf6719aa8d1..56e1dac37fb9 100644
--- a/products/error_tracking/backend/logic/issue_summary_prompt.py
+++ b/products/error_tracking/backend/logic/issue_summary_prompt.py
@@ -42,9 +42,12 @@ Facts:
- First seen: {first_seen}, first release: {first_release}
- Latest release: {latest_release}
- Trend: {trend_direction} ({previous_occurrences} -> {current_occurrences} occurrences)
-- Impact in range: {occurrences} occurrences, {users} users, {sessions} sessions
+- {impact}
</issue>"""
+ISSUE_SUMMARY_IMPACT_LINE = "Impact in range: {occurrences} occurrences, {users} users, {sessions} sessions"
+ISSUE_SUMMARY_IMPACT_NOT_KNOWN_YET = "Impact: not known yet, because the issue was just created from its first event"
+
class IssueSummaryResponse(BaseModel):
# extra="forbid" makes the JSON schema carry additionalProperties: false, which strict mode requires.
diff --git a/products/error_tracking/backend/tests/test_issue_summaries.py b/products/error_tracking/backend/tests/test_issue_summaries.py
index 7ca88ddb99ce..0d358234c33b 100644
--- a/products/error_tracking/backend/tests/test_issue_summaries.py
+++ b/products/error_tracking/backend/tests/test_issue_summaries.py
@@ -971,12 +971,10 @@ class TestIssueSummaryInputs(ClickhouseTestMixin, BaseTest):
assert isinstance(from_clickhouse, IssueSummaryInputs)
assert isinstance(from_event, IssueSummaryInputs)
assert from_event.input_hash == from_clickhouse.input_hash
- assert "Impact in range: 1 occurrences, 1 users, 1 sessions" in from_event.prompt
-
- without_session = {key: value for key, value in properties.items() if key != "$session_id"}
- from_sessionless_event = build_issue_summary_inputs_from_event(self.team, issue.id, without_session)
- assert isinstance(from_sessionless_event, IssueSummaryInputs)
- assert "Impact in range: 1 occurrences, 1 users, 0 sessions" in from_sessionless_event.prompt
+ assert "Impact in range: 1 occurrences, 1 users, 1 sessions" in from_clickhouse.prompt
+ assert "- Impact: not known yet" in from_event.prompt
+ assert "users" not in from_event.prompt
+ assert "sessions" not in from_event.prompt
def test_issue_without_exception_events_has_no_inputs(self) -> None:
issue = ErrorTrackingIssue.objects.create(team=self.team, name="TypeError")