Conversation
Resolve the installation once at the webhook endpoint and pass the integration and organization integrations to each handler. Unknown or missing installations are handled by the endpoint, so handlers no longer need to extract or look up the installation themselves. This also lets repository lookups be scoped by organization, matching the other SCM integrations.
Comment on lines
100
to
104
| ) | ||
| integration_service.update_integration( | ||
| integration_id=integration_id, status=ObjectStatus.ACTIVE | ||
| integration_id=integration.id, status=ObjectStatus.ACTIVE | ||
| ) | ||
| _sync_repositories(org_integrations, delivery_id) |
Contributor
There was a problem hiding this comment.
Bug: A race condition can cause a valid, refreshed access token to be overwritten with a stale one during an integration update, breaking subsequent API calls.
Severity: MEDIUM
Suggested Fix
To prevent overwriting fresh data with stale data, re-fetch the integration object from the database within the InstallationUpdatedHandler just before the metadata is updated and saved. Alternatively, use a database-level merge operation or implement locking.
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/integrations/cursor_origin/handlers.py#L100-L104
Potential issue: A race condition can occur in the `InstallationUpdatedHandler`. The
integration's data is fetched at the webhook level and passed to the handler. If a
concurrent process refreshes the access token (e.g., via `_refresh_access_token()`), the
database is updated with a new token. However, the handler, holding a stale version of
the integration object, will then perform a metadata merge (`{**integration.metadata,
**changed}`) and save it. This action overwrites the new, valid token in the database
with the old, stale one, which can cause subsequent API calls for that integration to
fail.
Also affects:
src/sentry/integrations/cursor_origin/webhook.py:214~220
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve the installation once at the webhook endpoint and pass the integration and
organization integrations to each handler. Unknown or missing installations are handled
by the endpoint, so handlers no longer need to extract or look up the installation
themselves.
This also lets repository lookups be scoped by organization, matching the other SCM
integrations.