feat(seer): Add candidate issue selection to night shift#112521
feat(seer): Add candidate issue selection to night shift#112521
Conversation
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>
| 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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes this table is currently undergoing migration, reads from this table will be under the feature flag organizations:seer-project-settings-read-from-sentry!
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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 |
There was a problem hiding this comment.
This is an arbitrary baseline for now, will iterate on in some future PRs.

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:
_fixability_score_strategy) with a shared signature, making it easy to swap in different approaches (LLM-based scoring, agent triage, etc.)_ScoredCandidatecaptures raw signals (fixability, severity, times_seen) with ascoreproperty driven by configurable weights. Only fixability is active to start — other weights are set to 0.first_seenfilter — night shift can look at older issuesSeerProjectRepositoryDB query instead of per-project Seer API calls