Skip to content

ref(night-shift): Use seer-project-settings helpers for project eligibility#112936

Merged
chromy merged 1 commit into
masterfrom
chromy/ref/night-shift-seer-project-settings
Apr 15, 2026
Merged

ref(night-shift): Use seer-project-settings helpers for project eligibility#112936
chromy merged 1 commit into
masterfrom
chromy/ref/night-shift-seer-project-settings

Conversation

@chromy
Copy link
Copy Markdown
Contributor

@chromy chromy commented Apr 14, 2026

Add a unified `bulk_read_preferences()` helper in `autofix/utils.py` that
returns `dict[int, SeerProjectPreference | None]` regardless of whether
preferences are read from Sentry DB or the Seer API. The helper checks the
`seer-project-settings-read-from-sentry` feature flag internally so callers
don't need to duplicate that branching logic.

Use the new helper in the night-shift cron's `_get_eligible_projects`,
replacing the direct `SeerProjectRepository` query. The
`autofix_automation_tuning != OFF` filter is preserved on top of the
preference check.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 14, 2026
@chromy chromy marked this pull request as ready for review April 14, 2026 18:11
@chromy chromy requested a review from a team as a code owner April 14, 2026 18:11
Comment thread src/sentry/seer/autofix/utils.py Outdated
Comment thread src/sentry/tasks/seer/night_shift/cron.py
Comment thread src/sentry/seer/autofix/utils.py Outdated
Comment thread src/sentry/tasks/seer/night_shift/cron.py
@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from d01fd09 to e704614 Compare April 14, 2026 19:50
@chromy chromy requested a review from a team as a code owner April 14, 2026 19:50
Comment thread src/sentry/tasks/seer/night_shift/cron.py Outdated
Comment thread src/sentry/tasks/seer/night_shift/cron.py
Comment thread src/sentry/tasks/seer/night_shift/cron.py
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Backend Test Failures

Failures on f53c8b2 in this run:

tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py::OrganizationAutofixAutomationSettingsEndpointTest::test_post_creates_project_preferenceslog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py:228: in test_post_creates_project_preferences
    assert preferences == [
E   AssertionError: assert [{'autofix_au...3760544, ...}] == [{'automated_...3826080, ...}]
E     
E     At index 0 diff: {'organization_id': 4557968173760544, 'project_id': 4557968173826080, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None, 'autofix_automation_tuning': None} != {'organization_id': 4557968173760544, 'project_id': 4557968173826080, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None}
E     
E     Full diff:
E       [
E           {
E     +         'autofix_automation_tuning': None,
E               'automated_run_stopping_point': 'open_pr',
E               'automation_handoff': None,
E               'organization_id': 4557968173760544,
E               'project_id': 4557968173826080,
E               'repositories': [],
E           },
E       ]
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py::OrganizationAutofixAutomationSettingsEndpointTest::test_post_updates_each_preference_field_independentlylog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py:289: in test_post_updates_each_preference_field_independently
    assert preferences == [
E   AssertionError: assert [{'autofix_au...4940192, ...}] == [{'automated_...5005728, ...}]
E     
E     At index 0 diff: {'organization_id': 4557968174940192, 'project_id': 4557968175005728, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None, 'autofix_automation_tuning': None} != {'organization_id': 4557968174940192, 'project_id': 4557968175005728, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None}
E     
E     Full diff:
E       [
E           {
E     +         'autofix_automation_tuning': None,
E               'automated_run_stopping_point': 'open_pr',
E               'automation_handoff': None,
E               'organization_id': 4557968174940192,
E               'project_id': 4557968175005728,
E               'repositories': [],
E           },
E       ]

@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from e704614 to 8b8fe1d Compare April 14, 2026 19:59
Comment thread src/sentry/tasks/seer/night_shift/cron.py
@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from 8b8fe1d to a226560 Compare April 14, 2026 20:04
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Backend Test Failures

Failures on f3190e8 in this run:

tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py::OrganizationAutofixAutomationSettingsEndpointTest::test_post_updates_each_preference_field_independentlylog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py:289: in test_post_updates_each_preference_field_independently
    assert preferences == [
E   AssertionError: assert [{'autofix_au...4184736, ...}] == [{'automated_...4250272, ...}]
E     
E     At index 0 diff: {'organization_id': 4557968234184736, 'project_id': 4557968234250272, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None, 'autofix_automation_tuning': None} != {'organization_id': 4557968234184736, 'project_id': 4557968234250272, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None}
E     
E     Full diff:
E       [
E           {
E     +         'autofix_automation_tuning': None,
E               'automated_run_stopping_point': 'open_pr',
E               'automation_handoff': None,
E               'organization_id': 4557968234184736,
E               'project_id': 4557968234250272,
E               'repositories': [],
E           },
E       ]
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py::OrganizationAutofixAutomationSettingsEndpointTest::test_post_creates_project_preferenceslog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py:228: in test_post_creates_project_preferences
    assert preferences == [
E   AssertionError: assert [{'autofix_au...2939536, ...}] == [{'automated_...3005072, ...}]
E     
E     At index 0 diff: {'organization_id': 4557968232939536, 'project_id': 4557968233005072, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None, 'autofix_automation_tuning': None} != {'organization_id': 4557968232939536, 'project_id': 4557968233005072, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None}
E     
E     Full diff:
E       [
E           {
E     +         'autofix_automation_tuning': None,
E               'automated_run_stopping_point': 'open_pr',
E               'automation_handoff': None,
E               'organization_id': 4557968232939536,
E               'project_id': 4557968233005072,
E               'repositories': [],
E           },
E       ]

@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from a226560 to 99c5a91 Compare April 14, 2026 20:13
@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from 99c5a91 to b0f533f Compare April 14, 2026 20:19
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Backend Test Failures

Failures on 927853a in this run:

tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py::OrganizationAutofixAutomationSettingsEndpointTest::test_post_updates_each_preference_field_independentlylog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py:289: in test_post_updates_each_preference_field_independently
    assert preferences == [
E   AssertionError: assert [{'autofix_au...3167136, ...}] == [{'automated_...3232672, ...}]
E     
E     At index 0 diff: {'organization_id': 4557968293167136, 'project_id': 4557968293232672, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None, 'autofix_automation_tuning': None} != {'organization_id': 4557968293167136, 'project_id': 4557968293232672, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None}
E     
E     Full diff:
E       [
E           {
E     +         'autofix_automation_tuning': None,
E               'automated_run_stopping_point': 'open_pr',
E               'automation_handoff': None,
E               'organization_id': 4557968293167136,
E               'project_id': 4557968293232672,
E               'repositories': [],
E           },
E       ]
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py::OrganizationAutofixAutomationSettingsEndpointTest::test_post_creates_project_preferenceslog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/endpoints/test_organization_autofix_automation_settings.py:228: in test_post_creates_project_preferences
    assert preferences == [
E   AssertionError: assert [{'autofix_au...2642848, ...}] == [{'automated_...2642848, ...}]
E     
E     At index 0 diff: {'organization_id': 4557968292642848, 'project_id': 4557968292642848, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None, 'autofix_automation_tuning': None} != {'organization_id': 4557968292642848, 'project_id': 4557968292642848, 'repositories': [], 'automated_run_stopping_point': 'open_pr', 'automation_handoff': None}
E     
E     Full diff:
E       [
E           {
E     +         'autofix_automation_tuning': None,
E               'automated_run_stopping_point': 'open_pr',
E               'automation_handoff': None,
E               'organization_id': 4557968292642848,
E               'project_id': 4557968292642848,
E               'repositories': [],
E           },
E       ]

@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from b0f533f to cade023 Compare April 14, 2026 20:58
@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from cade023 to 63d1544 Compare April 14, 2026 21:01
Copy link
Copy Markdown
Member

@srest2021 srest2021 left a comment

Choose a reason for hiding this comment

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

Helper looks good, thanks for writing this!

Only one nit, which is adding the tuning to SeerProjectPreference--Seer will drop the field when it gets included in writes, and the write preference helpers to Sentry DB won't write it either. Mind adding a clarifying comment to the write helpers? Or alternatively could just return tuples

@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from 63d1544 to e8ff7ac Compare April 15, 2026 09:47
@chromy
Copy link
Copy Markdown
Contributor Author

chromy commented Apr 15, 2026

Helper looks good, thanks for writing this!

Only one nit, which is adding the tuning to SeerProjectPreference--Seer will drop the field when it gets included in writes, and the write preference helpers to Sentry DB won't write it either. Mind adding a clarifying comment to the write helpers? Or alternatively could just return tuples

Thanks! It seems like SeerProjectPreference was the right home for this setting long term (and the only reason it wasn't already there was that it happened to be one of the only bits of state that was already stored in the monolith db). If that's right I think long term the write methods should also support setting autofix_automation_tuning. I filed AIML-2753 for this so we don't lose track and added some warning comments to that effect.

Let me know if you think that is not right! If you think autofix_automation_tuning shouldn't eventually end up on SeerProjectPreference then I can solve this a different way.

I'll land this for now because it's blocking other work on autofix - but very happy to change it if needed!

…bility

Replace direct SeerProjectRepository queries in _get_eligible_projects
with bulk_read_preferences_from_sentry_db / bulk_get_project_preferences
behind the seer-project-settings-read-from-sentry feature flag, matching
the pattern used in context_engine_index and autofix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Agent transcript: https://claudescope.sentry.dev/share/TusCoPLrgCYHLxdSUeDTGIDPYU1f6BITAaO7rK6QDl0
@chromy chromy force-pushed the chromy/ref/night-shift-seer-project-settings branch from e8ff7ac to 784f60f Compare April 15, 2026 09:48
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.

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 784f60f. Configure here.

"sentry:seer_automation_handoff_target",
"sentry:seer_automation_handoff_integration_id",
"sentry:seer_automation_handoff_auto_create_pr",
"sentry:autofix_automation_tuning",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

New preference key breaks fallback repo resolution for autofix

Medium Severity

Adding "sentry:autofix_automation_tuning" to SEER_PROJECT_PREFERENCE_OPTION_KEYS changes the has_configured_options check in read_preference_from_sentry_db. A project with only autofix_automation_tuning explicitly set (e.g., via project settings UI) but no Seer repos now returns a SeerProjectPreference with repositories=[] instead of None. Downstream in _resolve_project_preference in autofix.py, the if preference: truthiness check on the model instance passes, skipping the fallback path that populates repos from code mappings. This causes autofix to run with an empty repo list for those projects.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 784f60f. Configure here.

@chromy chromy merged commit 549bb4c into master Apr 15, 2026
62 checks passed
@chromy chromy deleted the chromy/ref/night-shift-seer-project-settings branch April 15, 2026 09:59
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants