Repository navigation
feat(alerts): investigate platform-owned insight firings with the agent #127923
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 8 commits into
jimmy/insight-investigation-agent-rows
from
jimmy/insight-investigation-adapter
Nov 3, 2026
+512
−10
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf93cb0
feat(alerts): investigate platform-owned insight firings with the agent
jzhu13 4413dac
Merge branch 'jimmy/insight-investigation-agent-rows' into jimmy/insi…
jzhu13 09759d7
Merge branch 'jimmy/insight-investigation-agent-rows' into jimmy/insi…
jzhu13 bc02ccc
Merge branch 'jimmy/insight-investigation-agent-rows' into jimmy/insi…
jzhu13 2208bae
fix(alerts): skip investigations for skipped checks and claim off the…
jzhu13 7d60245
Merge branch 'jimmy/insight-investigation-agent-rows' into jimmy/insi…
jzhu13 2775218
fix(alerts-platform): drop a released hold's trigger once its firing …
jzhu13 c10005e
fix(alerts-platform): compare a held trigger's episode in UTC
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """The investigation an insight firing asks for in its `source_detail`, claimed after the record. | ||
|
|
||
| A check only decides that its firing gets an investigation, because its evaluation can be retried. | ||
| The evaluation workflow claims it once the firing is recorded, and starts the agent. This module | ||
| has no Django imports, so the workflow can call it. | ||
| """ | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from posthog.dataclasses import frozen | ||
|
|
||
| from products.alerts_platform.backend.facade.contracts import AlertDeliveryRequest, PlatformAlertOutcome | ||
|
|
||
| # The legacy alert whose agent investigates the firing. Recorded with the firing, so history shows | ||
| # which checks asked for an investigation. | ||
| INVESTIGATION_REQUESTED_KEY = "investigation_alert_id" | ||
|
|
||
|
|
||
| @frozen | ||
| class InvestigationStart: | ||
| """An agent run the claim granted, as the workflow starts it.""" | ||
|
|
||
| team_id: int | ||
| alert_id: str | ||
| investigation_id: str | ||
| configuration_id: str | ||
| evaluation_key: str | ||
| user_id: int | None = None | ||
|
|
||
| @property | ||
| def workflow_id(self) -> str: | ||
| return f"anomaly-investigation-{self.configuration_id}:{self.evaluation_key}" | ||
|
|
||
| def workflow_inputs(self) -> dict[str, object]: | ||
| """The agent's `AnomalyInvestigationWorkflowInputs`, as JSON. The agent's module imports Django, | ||
| which the workflow sandbox refuses, so the inputs cross by name.""" | ||
| return { | ||
| "team_id": self.team_id, | ||
| "alert_id": self.alert_id, | ||
| "investigation_id": self.investigation_id, | ||
| "user_id": self.user_id, | ||
| } | ||
|
|
||
|
|
||
| @frozen | ||
| class InvestigationClaims: | ||
| starts: tuple[InvestigationStart, ...] = () | ||
| # Held firings whose claim was refused, released by the firing's last verdict and due to start. | ||
| deliveries: tuple[AlertDeliveryRequest, ...] = () | ||
|
|
||
|
|
||
| @frozen | ||
| class RequestedInvestigation: | ||
| alert_id: str | ||
| episode_started_at: datetime | None | ||
|
|
||
|
|
||
| def requested_investigation(outcome: PlatformAlertOutcome) -> RequestedInvestigation | None: | ||
| """The investigation an outcome asks for, or None. Only an ungrouped firing asks for one.""" | ||
| for group in outcome.groups: | ||
| alert_id = group.source_detail.get(INVESTIGATION_REQUESTED_KEY) | ||
| if alert_id is not None: | ||
| started_at = group.firing_episode.started_at if group.firing_episode else None | ||
| return RequestedInvestigation(alert_id=str(alert_id), episode_started_at=started_at) | ||
| return None |
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.