Skip to content

fix(seer): Validate unvalidated coding agent org option values#111862

Closed
srest2021 wants to merge 3 commits intomasterfrom
srest2021/fix-coding-agent-options
Closed

fix(seer): Validate unvalidated coding agent org option values#111862
srest2021 wants to merge 3 commits intomasterfrom
srest2021/fix-coding-agent-options

Conversation

@srest2021
Copy link
Copy Markdown
Member

@srest2021 srest2021 commented Mar 30, 2026

There are currently 2 rows in prod for the org option sentry:seer_default_coding_agent that have unvalidated values (ie, "cursor" instead of "cursor_background_agent"). We want coding agent values to match the allowed values for automation handoff target. This is a low risk migration on org options that are currently only used in UI that is feature-flagged for internal use.

Followup PR that adds validation: #111697

@github-actions
Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1058_normalize_coding_agent_option_aliases.py

for 1058_normalize_coding_agent_option_aliases in sentry

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

@srest2021 srest2021 marked this pull request as ready for review March 31, 2026 16:04
@srest2021 srest2021 requested a review from a team as a code owner March 31, 2026 16:04
@github-actions
Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1059_normalize_coding_agent_option_aliases.py

for 1059_normalize_coding_agent_option_aliases in sentry

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 1773dc9 in this run:

tests/sentry/integrations/api/endpoints/test_organization_repository_details.py::OrganizationRepositoryGetTest::test_get_repository_expand_settings_no_settings_existlog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/integrations/api/endpoints/test_organization_repository_details.py:91: in test_get_repository_expand_settings_no_settings_exist
    assert response.data["settings"]["codeReviewTriggers"] == [
E   AssertionError: assert ['on_ready_for_review'] == ['on_ready_fo...n_new_commit']
E     
E     Right contains one more item: 'on_new_commit'
E     
E     Full diff:
E       [
E           'on_ready_for_review',
E     -     'on_new_commit',
E       ]

Comment on lines +37 to +38
row.value = canonical
row.save(update_fields=["value"])
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.

Bug: The migration updates OrganizationOption values but fails to invalidate the cache because it uses a historical model, which bypasses the post_save signal that triggers cache reloading.
Severity: LOW

Suggested Fix

After saving the updated row inside the loop, add an explicit call to OrganizationOption.objects.reload_cache(row.organization_id, "migrate_coding_agent_alias") to manually invalidate the cache, since the post_save signal will not fire for the historical model.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/migrations/1059_normalize_coding_agent_option_aliases.py#L37-L38

Potential issue: The database migration updates `OrganizationOption` rows directly using
`row.save(update_fields=["value"])` on a historical model instance. In Django
migrations, historical models do not trigger signals like `post_save`. The
`OrganizationOptionManager` relies on this signal to call `reload_cache()` for cache
invalidation. Because the signal is bypassed, the Redis and in-memory caches are not
updated, causing them to serve stale option values. The stale data will persist until
the cache's time-to-live (TTL) expires or the process is restarted.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on bccc78d in this run:

tests/sentry/integrations/api/endpoints/test_organization_repository_details.py::OrganizationRepositoryGetTest::test_get_repository_expand_settings_no_settings_existlog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/integrations/api/endpoints/test_organization_repository_details.py:91: in test_get_repository_expand_settings_no_settings_exist
    assert response.data["settings"]["codeReviewTriggers"] == [
E   AssertionError: assert ['on_ready_for_review'] == ['on_ready_fo...n_new_commit']
E     
E     Right contains one more item: 'on_new_commit'
E     
E     Full diff:
E       [
E           'on_ready_for_review',
E     -     'on_new_commit',
E       ]

@srest2021 srest2021 closed this Mar 31, 2026
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.

1 participant