Skip to content

feat(seer): Add candidate issue selection to night shift#112521

Open
trevor-e wants to merge 5 commits intomasterfrom
trevor-e/feat/night-shift-candidate-selection
Open

feat(seer): Add candidate issue selection to night shift#112521
trevor-e wants to merge 5 commits intomasterfrom
trevor-e/feat/night-shift-candidate-selection

Conversation

@trevor-e
Copy link
Copy Markdown
Member

@trevor-e trevor-e commented Apr 8, 2026

Implements the per-org worker for the night shift cron to query and rank candidate issues for autofix. This is the selection/logging phase — no autofix triggering yet.

The task iterates eligible projects (automation enabled + connected repos via SeerProjectRepository), queries unresolved issues not already autofix-triggered, and ranks them globally across the org using a weighted scoring system. Top N candidates are logged with raw signals for inspection.

Key design choices:

  • Pluggable strategies: Selection logic is extracted into strategy functions (_fixability_score_strategy) with a shared signature, making it easy to swap in different approaches (LLM-based scoring, agent triage, etc.)
  • Weighted scoring: _ScoredCandidate captures raw signals (fixability, severity, times_seen) with a score property driven by configurable weights. Only fixability is active to start — other weights are set to 0.
  • No occurrence threshold: Unlike the post_process flow's 10-event minimum, night shift can serve lower-volume projects
  • No age cutoff: No 14-day first_seen filter — night shift can look at older issues
  • Bulk repo check: Uses SeerProjectRepository DB query instead of per-project Seer API calls

Implement the per-org worker task to query and rank candidate issues
for night shift autofix. Issues are selected across eligible projects
using a weighted scoring system with pluggable strategy functions.

- Add _get_eligible_projects: filters to active projects with automation
  enabled and connected repos via SeerProjectRepository
- Add _fixability_score_strategy: ranks unresolved issues by fixability
  score, severity, and times_seen with configurable weights
- Add _ScoredCandidate dataclass with raw signals and computed score
- Log ranked candidates for inspection before triggering autofix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 8, 2026
def _get_eligible_projects(organization: Organization) -> list[Project]:
"""Return active projects that have automation enabled and connected repos."""
projects_with_repos = set(
SeerProjectRepository.objects.filter(
Copy link
Copy Markdown
Member Author

@trevor-e trevor-e Apr 8, 2026

Choose a reason for hiding this comment

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

I think this depends on the current settings migration that's happening right now but ignoring to start, will look more closely in some follow-up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes this table is currently undergoing migration, reads from this table will be under the feature flag organizations:seer-project-settings-read-from-sentry!

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c4afe3f. Configure here.

- Single query across all projects instead of N+1 per-project queries
- Chunk project IDs in batches of 100 to avoid large IN clauses
- Use PriorityLevel.HIGH instead of magic number 75
- Use SeerProjectRepository DB query instead of Seer API call

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use real DB state (SeerProjectRepository rows + project options) instead
of mocking _get_eligible_projects. Only logger and scheduler dispatch
mocks remain.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix NULL fixability scores sorting first in DESC ordering by using
  F().desc(nulls_last=True)
- Rename NIGHT_SHIFT_ISSUES_PER_PROJECT to NIGHT_SHIFT_ISSUE_FETCH_LIMIT
  to reflect it's a per-batch limit, not per-project
- Increase fetch limit from 50 to 100
- Consolidate tests: 15 → 10 with same coverage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@property
def score(self) -> float:
return (
WEIGHT_FIXABILITY * self.fixability
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is an arbitrary baseline for now, will iterate on in some future PRs.

@trevor-e trevor-e marked this pull request as ready for review April 8, 2026 21:46
@trevor-e trevor-e requested a review from a team as a code owner April 8, 2026 21:46
@trevor-e trevor-e requested a review from chromy April 8, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants