Skip to content

ref(cursor-origin): Resolve the installation once per delivery - #124996

Open
wedamija wants to merge 1 commit into
danf/origin-webhook-routingfrom
danf/origin-handler-context
Open

wedamija wants to merge 1 commit into
danf/origin-webhook-routingfrom
danf/origin-handler-context

Conversation

@wedamija

Copy link
Copy Markdown
Member

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.

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.
@wedamija
wedamija requested a review from a team as a code owner September 19, 2026 00:25
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 19, 2026
@wedamija
wedamija requested a review from gi0baro September 19, 2026 00:27
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)

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: 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.

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