Repository navigation
feat(alerts): word platform insight firings with their investigation #127907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
trunk-io
merged 2 commits into
master
from
claude/insight-investigation-describer-d2156f
Nov 3, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """The lines an investigated insight alert notification states. | ||
|
|
||
| The insight stack and the alerts platform both send these, so one definition keeps the two word | ||
| for word the same. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Sequence | ||
| from typing import Final | ||
|
|
||
| from posthog.dataclasses import frozen | ||
| from posthog.tasks.alerts.utils import InvestigationSummaryLine, investigation_summary_teaser | ||
| from posthog.utils import absolute_uri | ||
|
|
||
| VERDICT_LABELS: Final = { | ||
| "true_positive": "True positive", | ||
| "false_positive": "False positive", | ||
| "inconclusive": "Inconclusive", | ||
| } | ||
|
|
||
| SAFETY_NET_LINE: Final = "(Investigation agent did not complete before the notification grace period expired.)" | ||
|
|
||
|
|
||
| @frozen | ||
| class InvestigationBreaches: | ||
| lines: list[str] | ||
| summary: InvestigationSummaryLine | None | ||
|
|
||
|
|
||
| def notebook_url(notebook_short_id: str) -> str: | ||
| return absolute_uri(f"/notebooks/{notebook_short_id}") | ||
|
|
||
|
|
||
| def _anomaly_head(triggered_dates: Sequence[str], value: float | None) -> str: | ||
| if triggered_dates: | ||
| if len(triggered_dates) == 1: | ||
| return f"Anomaly detected on {triggered_dates[0]}." | ||
| return f"Anomaly detected from {triggered_dates[0]} to {triggered_dates[-1]}." | ||
| if value is not None: | ||
| return f"Calculated value at fire: {value}." | ||
| return "Anomaly detected." | ||
|
|
||
|
|
||
| def verdict_breaches( | ||
| *, | ||
| triggered_dates: Sequence[str], | ||
| value: float | None, | ||
| verdict: str | None, | ||
| previous_verdict: str | None, | ||
| summary: str, | ||
| notebook_short_id: str | None, | ||
| ) -> InvestigationBreaches: | ||
| """The breach lines of a notification sent once the agent reached its verdict. | ||
|
|
||
| The summary line holds a plain-text teaser. Email renders the full Markdown in its place. | ||
| """ | ||
| lines: list[str] = [] | ||
| if previous_verdict and verdict and verdict != previous_verdict: | ||
| lines.append( | ||
| f"Investigation verdict changed from {VERDICT_LABELS.get(previous_verdict, previous_verdict)} " | ||
| f"to {VERDICT_LABELS.get(verdict, verdict)} while this alert keeps firing." | ||
| ) | ||
| lines.append(_anomaly_head(triggered_dates, value)) | ||
|
|
||
| verdict_label = VERDICT_LABELS.get(verdict or "", "") | ||
| if verdict_label: | ||
| lines.append(f"Investigation verdict: {verdict_label}.") | ||
| summary_line = None | ||
| teaser = investigation_summary_teaser(summary) | ||
| if teaser: | ||
| summary_line = InvestigationSummaryLine(index=len(lines), markdown=summary) | ||
| lines.append(teaser) | ||
| if notebook_short_id: | ||
| lines.append(f"See {notebook_url(notebook_short_id)} for the full investigation.") | ||
| return InvestigationBreaches(lines=lines, summary=summary_line) | ||
|
|
||
|
|
||
| def safety_net_breaches(*, triggered_dates: Sequence[str], value: float | None) -> list[str]: | ||
| """Minimal breach description for a notification the safety net sent without a verdict.""" | ||
| return [_anomaly_head(triggered_dates, value), SAFETY_NET_LINE] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.