Skip to content

feat(workflow_engine): Add in hook for producing occurrences from the stateful detector#1

Open
ShashankFC wants to merge 1 commit into
workflow-engine-stateful-detector-beforefrom
workflow-engine-stateful-detector-after
Open

feat(workflow_engine): Add in hook for producing occurrences from the stateful detector#1
ShashankFC wants to merge 1 commit into
workflow-engine-stateful-detector-beforefrom
workflow-engine-stateful-detector-after

Conversation

@ShashankFC

@ShashankFC ShashankFC commented Feb 13, 2026

Copy link
Copy Markdown

User description

Test 10

Summary by CodeRabbit

  • Refactor
    • Restructured metric alert detection system to use group-based result tracking instead of list-based aggregation.
    • Enhanced detector evaluation framework with improved state management and occurrence data handling.

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


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


CodeAnt-AI Description

Produce issue occurrences from stateful detectors and return results keyed by group

What Changed

  • Stateful detectors can now create IssueOccurrence objects (plus associated event data) through a new handler hook; occurrences returned by detectors are sent to the issues producer.
  • Detector evaluation results are returned as a mapping keyed by group key instead of a list, preventing duplicate group-key results and making per-group outcomes explicit.
  • The Detector model exposes the resolved GroupType as a property so detectors reliably know their issue type; metric-alert group handlers were switched to the new stateful handler API and tests updated to assert occurrence production.

Impact

✅ Issues emitted as occurrences to Kafka when detectors fire
✅ Fewer duplicate detector results for the same group key
✅ Deterministic group type resolution for detectors

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

… stateful detector (#80168)

This adds a hook that can be implemented to produce an occurrence
specific to the detector that is subclassing the StatefulDetector.

Also change the signature of evaluate to return a dict keyed by groupkey
instead of a list. This helps avoid the chance of duplicate results for
the same group key.

<!-- Describe your PR here. -->
@ShashankFC

Copy link
Copy Markdown
Author

@CodeAnt-AI: review

@codeant-ai

codeant-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

CodeAnt AI is running the review.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Feb 13, 2026
@codeant-ai

codeant-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

Sequence Diagram

Shows the core change where stateful detectors return group-keyed results and can build IssueOccurrences; the processor then converts those results into produced occurrences (Kafka). This captures the main success path introduced in the PR.

sequenceDiagram
    participant DataPacket
    participant Processor as process_detectors
    participant DetectorModel as Detector
    participant Handler as StatefulDetectorHandler
    participant IssueProducer as produce_occurrence_to_kafka

    DataPacket->>Processor: process_detectors(data_packet, [detector])
    Processor->>DetectorModel: get detector.detector_handler
    Processor->>Handler: evaluate(data_packet)  -- returns dict[group_key -> DetectorEvaluationResult]
    Handler-->>Processor: dict of DetectorEvaluationResult (includes IssueOccurrence + event_data for new issues)
    Processor->>IssueProducer: create_issue_occurrence_from_result -> produce_occurrence_to_kafka (OCCURRENCE, occurrence, event_data)
Loading

Generated by CodeAnt AI

@codeant-ai

codeant-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • API change
    The return type of process_detectors and DetectorHandler.evaluate changed from lists to dicts keyed by group key. Confirm all callers (internal and external) have been updated to handle dict results and that any downstream code that expected lists won't break.

  • Kafka error handling
    create_issue_occurrence_from_result calls produce_occurrence_to_kafka directly. A failure in Kafka production could raise and interrupt detector processing. Consider retrying, isolating failures, or at least catching exceptions and logging to avoid halting processing of other detectors/results.

  • Type-safety / Concatenation
    build_fingerprint concatenates group_key into a string using ':' + group_key. If group_key is not a string (e.g., an int), this will raise a TypeError at runtime. Ensure group_key is coerced to str before concatenation.

@codeant-ai

codeant-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

CodeAnt AI finished running the review.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants