Skip to content

ref(crons): Reorganize incident creation / issue occurrence logic#3

Open
ShashankFC wants to merge 1 commit into
monitor-incident-refactor-beforefrom
monitor-incident-refactor-after
Open

ref(crons): Reorganize incident creation / issue occurrence logic#3
ShashankFC wants to merge 1 commit into
monitor-incident-refactor-beforefrom
monitor-incident-refactor-after

Conversation

@ShashankFC

Copy link
Copy Markdown

Test 8

Summary by CodeRabbit

Release Notes

  • New Features
    • Implemented automatic incident creation and detection for monitor failures, respecting configurable failure thresholds.
    • Enhanced incident context with human-readable failure reason summaries, environment details, and tracking of last successful check-in times to aid in incident diagnosis and resolution.

✏️ Tip: You can customize this high-level summary in your review settings.


Replicated from ai-code-review-evaluation/sentry-coderabbit#8

…0528)

Since we'll be doing more with issue occurrences split out the concept
of incidents into it's own logic module, as well as incident_occurrence
into it's own module

Part of GH-80527
@ShashankFC

Copy link
Copy Markdown
Author

@cubic-dev-ai review this pull request

@cubic-dev-ai

cubic-dev-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

@cubic-dev-ai review this pull request

@ShashankFC I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/sentry/monitors/logic/incident_occurrence.py">

<violation number="1" location="src/sentry/monitors/logic/incident_occurrence.py:132">
P3: Typo in docstring: "humam readible" should be "human readable".</violation>

<violation number="2" location="src/sentry/monitors/logic/incident_occurrence.py:168">
P1: Bug: Returns the original `monitor_environment.monitor.config` instead of the locally modified `config` copy. The `schedule_type` display transformation on line 167 is silently discarded.</violation>
</file>

<file name="src/sentry/monitors/logic/incidents.py">

<violation number="1" location="src/sentry/monitors/logic/incidents.py:52">
P1: Missing check that enough check-ins exist to meet the failure threshold. If fewer check-ins exist than `failure_issue_threshold` (e.g., a newly created monitor), an incident will be created prematurely because the code only verifies that none of the returned check-ins are OK, not that there are *enough* failures to meet the threshold.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

"id": str(monitor_environment.monitor.guid),
"slug": str(monitor_environment.monitor.slug),
"name": monitor_environment.monitor.name,
"config": monitor_environment.monitor.config,

@cubic-dev-ai cubic-dev-ai Bot Feb 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Bug: Returns the original monitor_environment.monitor.config instead of the locally modified config copy. The schedule_type display transformation on line 167 is silently discarded.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/sentry/monitors/logic/incident_occurrence.py, line 168:

<comment>Bug: Returns the original `monitor_environment.monitor.config` instead of the locally modified `config` copy. The `schedule_type` display transformation on line 167 is silently discarded.</comment>

<file context>
@@ -0,0 +1,171 @@
+        "id": str(monitor_environment.monitor.guid),
+        "slug": str(monitor_environment.monitor.slug),
+        "name": monitor_environment.monitor.name,
+        "config": monitor_environment.monitor.config,
+        "status": monitor_environment.get_status_display(),
+        "type": monitor_environment.monitor.get_type_display(),
</file context>
Fix with Cubic


# If we have any successful check-ins within the threshold of
# commits we have NOT reached an incident state
if any([checkin["status"] == CheckInStatus.OK for checkin in previous_checkins]):

@cubic-dev-ai cubic-dev-ai Bot Feb 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Missing check that enough check-ins exist to meet the failure threshold. If fewer check-ins exist than failure_issue_threshold (e.g., a newly created monitor), an incident will be created prematurely because the code only verifies that none of the returned check-ins are OK, not that there are enough failures to meet the threshold.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/sentry/monitors/logic/incidents.py, line 52:

<comment>Missing check that enough check-ins exist to meet the failure threshold. If fewer check-ins exist than `failure_issue_threshold` (e.g., a newly created monitor), an incident will be created prematurely because the code only verifies that none of the returned check-ins are OK, not that there are *enough* failures to meet the threshold.</comment>

<file context>
@@ -0,0 +1,104 @@
+
+            # If we have any successful check-ins within the threshold of
+            # commits we have NOT reached an incident state
+            if any([checkin["status"] == CheckInStatus.OK for checkin in previous_checkins]):
+                return False
+
</file context>
Fix with Cubic


def get_failure_reason(failed_checkins: Sequence[SimpleCheckIn]):
"""
Builds a humam readible string from a list of failed check-ins.

@cubic-dev-ai cubic-dev-ai Bot Feb 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Typo in docstring: "humam readible" should be "human readable".

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/sentry/monitors/logic/incident_occurrence.py, line 132:

<comment>Typo in docstring: "humam readible" should be "human readable".</comment>

<file context>
@@ -0,0 +1,171 @@
+
+def get_failure_reason(failed_checkins: Sequence[SimpleCheckIn]):
+    """
+    Builds a humam readible string from a list of failed check-ins.
+
+    "3 missed check-ins detected"
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants