Repository navigation
feat(alerts): record insight alert investigations for platform evaluations #123622
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e75437a
feat(alerts): record insight alert investigations for platform evalua…
jzhu13 b009440
fix(alerts): register the investigation model and index its notebook …
jzhu13 abea385
fix(alerts): move the investigation model's semgrep entry clear of th…
jzhu13 accca4e
Merge remote-tracking branch 'origin/master' into jimmy/insight-alert…
jzhu13 23278ae
chore(alerts): list InsightAlertInvestigation in the IDOR model rules
jzhu13 7951940
Merge branch 'jimmy/insight-alert-investigation-idor-rule' into jimmy…
jzhu13 4673a22
Merge remote-tracking branch 'origin/master' into jimmy/insight-alert…
jzhu13 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
125 changes: 125 additions & 0 deletions
125
products/alerts/backend/migrations/0015_insight_alert_investigation.py
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,125 @@ | ||
| # Generated by Django 5.2.18 on 2026-10-26 19:46 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
| import posthog.uuidt | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("alerts", "0014_strip_llm_detector_threshold_and_window"), | ||
| ("notebooks", "0027_notebook_unlisted_visibility"), | ||
| ("posthog", "1413_event_filter_pipeline_override"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="InsightAlertInvestigation", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.UUIDField( | ||
| default=posthog.uuidt.uuid7, | ||
| editable=False, | ||
| primary_key=True, | ||
| serialize=False, | ||
| ), | ||
| ), | ||
| ("configuration_id", models.UUIDField()), | ||
| ("evaluation_key", models.CharField(max_length=255)), | ||
| ("episode_started_at", models.DateTimeField(blank=True, null=True)), | ||
| ( | ||
| "kind", | ||
| models.CharField( | ||
| choices=[("agent", "Agent"), ("metrics", "Metrics")], | ||
| max_length=16, | ||
| ), | ||
| ), | ||
| ( | ||
| "status", | ||
| models.CharField( | ||
| choices=[ | ||
| ("pending", "pending"), | ||
| ("running", "running"), | ||
| ("done", "done"), | ||
| ("failed", "failed"), | ||
| ("skipped", "skipped"), | ||
| ], | ||
| max_length=10, | ||
| ), | ||
| ), | ||
| ( | ||
| "verdict", | ||
| models.CharField( | ||
| blank=True, | ||
| choices=[ | ||
| ("true_positive", "true_positive"), | ||
| ("false_positive", "false_positive"), | ||
| ("inconclusive", "inconclusive"), | ||
| ], | ||
| max_length=20, | ||
| null=True, | ||
| ), | ||
| ), | ||
| ("summary", models.TextField(blank=True, null=True)), | ||
| ("error", models.JSONField(blank=True, null=True)), | ||
| ("evaluated", models.JSONField(default=dict)), | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ("updated_at", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "alert_configuration", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="+", | ||
| to="alerts.alertconfiguration", | ||
| ), | ||
| ), | ||
| ( | ||
| "notebook", | ||
| models.ForeignKey( | ||
| blank=True, | ||
| db_constraint=False, | ||
| db_index=False, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="+", | ||
| to="notebooks.notebook", | ||
| ), | ||
| ), | ||
| ( | ||
| "team", | ||
| models.ForeignKey( | ||
| db_constraint=False, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="+", | ||
| to="posthog.team", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "alerts_insightalertinvestigation", | ||
| "indexes": [ | ||
| models.Index( | ||
| fields=["configuration_id", "episode_started_at", "created_at"], | ||
| name="insight_alert_inv_episode_idx", | ||
| ), | ||
| models.Index( | ||
| condition=models.Q(("notebook__isnull", False)), | ||
| fields=["notebook"], | ||
| name="insight_alert_inv_notebook_idx", | ||
| ), | ||
| models.Index( | ||
| fields=["configuration_id", "created_at"], | ||
| name="insight_alert_inv_recent_idx", | ||
| ), | ||
| ], | ||
| "constraints": [ | ||
| models.UniqueConstraint( | ||
| fields=("configuration_id", "evaluation_key"), | ||
| name="insight_alert_investigation_one_per_evaluation", | ||
| ) | ||
| ], | ||
| }, | ||
| ), | ||
| ] |
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0014_strip_llm_detector_threshold_and_window | ||
| 0015_insight_alert_investigation |
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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| from .alert import Alert, AlertCheck, AlertConfiguration, AlertSubscription, Threshold | ||
| from .investigation import InsightAlertInvestigation | ||
|
|
||
| __all__ = [ | ||
| "Alert", | ||
| "AlertCheck", | ||
| "AlertConfiguration", | ||
| "AlertSubscription", | ||
| "InsightAlertInvestigation", | ||
| "Threshold", | ||
| ] |
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,69 @@ | ||
| from django.db import models | ||
|
|
||
| from posthog.models.scoping.root_mixin import TeamScopedRootMixin | ||
| from posthog.models.utils import UUIDModel | ||
|
|
||
| from products.alerts.backend.models.alert import AlertConfiguration, InvestigationStatus, InvestigationVerdict | ||
|
|
||
|
|
||
| class InsightAlertInvestigation(TeamScopedRootMixin, UUIDModel): | ||
| """One investigation of one platform evaluation of an insight alert. | ||
|
|
||
| The platform never writes `AlertCheck`, so an alert the platform evaluates keeps its | ||
| investigations here. A row exists for every evaluation that asked for one, including one the | ||
| claim refused, which is recorded as SKIPPED and spends no budget. | ||
| """ | ||
|
|
||
| class Kind(models.TextChoices): | ||
| AGENT = "agent", "Agent" | ||
| METRICS = "metrics", "Metrics" | ||
|
|
||
| team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, db_constraint=False, related_name="+") | ||
| alert_configuration = models.ForeignKey(AlertConfiguration, on_delete=models.CASCADE, related_name="+") | ||
| # The platform's configuration. Not a foreign key, because that model belongs to another product. | ||
| configuration_id = models.UUIDField() | ||
| evaluation_key = models.CharField(max_length=255) | ||
| # The firing the evaluation belongs to, which is what the per-episode budget counts. Null for | ||
| # the firing that was already open when the platform took the alert over. | ||
| episode_started_at = models.DateTimeField(null=True, blank=True) | ||
|
|
||
| kind = models.CharField(max_length=16, choices=Kind.choices) | ||
| status = models.CharField(max_length=10, choices=InvestigationStatus.choices) | ||
| verdict = models.CharField(max_length=20, choices=InvestigationVerdict.choices, null=True, blank=True) | ||
| summary = models.TextField(null=True, blank=True) | ||
| notebook = models.ForeignKey( | ||
| "notebooks.Notebook", | ||
| on_delete=models.SET_NULL, | ||
| db_constraint=False, | ||
| db_index=False, | ||
| null=True, | ||
| blank=True, | ||
| related_name="+", | ||
| ) | ||
| error = models.JSONField(null=True, blank=True) | ||
| # What the evaluation measured, as the agent reads it: value, triggered dates and points, | ||
| # anomaly scores, interval and triggered metadata. | ||
| evaluated = models.JSONField(default=dict) | ||
|
|
||
| created_at = models.DateTimeField(auto_now_add=True) | ||
| updated_at = models.DateTimeField(auto_now=True) | ||
|
|
||
| class Meta: | ||
| db_table = "alerts_insightalertinvestigation" | ||
| constraints = [ | ||
| models.UniqueConstraint( | ||
| fields=["configuration_id", "evaluation_key"], name="insight_alert_investigation_one_per_evaluation" | ||
| ) | ||
| ] | ||
| indexes = [ | ||
| # The episode's budget and its last verdict. | ||
| models.Index( | ||
| fields=["configuration_id", "episode_started_at", "created_at"], name="insight_alert_inv_episode_idx" | ||
| ), | ||
| # Deleting a notebook nulls the link through this, and most rows have no notebook. | ||
| models.Index( | ||
| fields=["notebook"], name="insight_alert_inv_notebook_idx", condition=models.Q(notebook__isnull=False) | ||
| ), | ||
| # The claim's in-flight and cooldown checks. | ||
| models.Index(fields=["configuration_id", "created_at"], name="insight_alert_inv_recent_idx"), | ||
| ] | ||
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.