fix(integrations): record 409 empty repo responses as halts instead of failures#109134
Merged
fix(integrations): record 409 empty repo responses as halts instead of failures#109134
Conversation
# Conflicts: # src/sentry/integrations/github/client.py
rbro112
approved these changes
Feb 23, 2026
trevor-e
added a commit
that referenced
this pull request
Feb 24, 2026
…I calls (#109153) Cache the result when GitHub's Git Trees API returns a 409 ("Git Repository is empty") instead of re-fetching on every task run. Previously, when `get_tree` hit a 409 for an empty repo, the exception propagated without writing to cache. This meant every subsequent `auto_source_code_config` task run would re-fetch the same empty repos, wasting API calls and contributing to GitHub rate limiting. For large orgs with many empty repos, this adds up to thousands of unnecessary API calls per day. Now we catch `ApiConflictError` in `get_cached_repo_files`, cache an empty list with the same TTL as successful results (24h + staggered offset), and return early. The existing error handling in `_populate_trees` is unaffected since the exception no longer propagates. Pairs with #109134 which records these 409s as halts instead of failures in the interaction event lifecycle. Refs SENTRY-5K7F
mchen-sentry
pushed a commit
that referenced
this pull request
Feb 24, 2026
…f failures (#109134) Wraps `get_tree` and `get_repositories_from_github` in `SCMIntegrationInteractionEvent` context managers to track these GitHub API interactions. Additionally, handles 409 responses from GitHub's tree API (returned for empty repositories) as halts rather than failures. These are expected responses that don't indicate a bug, but the `SCMIntegrationInteractionEvent` wrapper was surfacing them as Sentry issues via `capture_exception`, which caused high-occurrence alerts that blocked deployments. The fix catches `ApiConflictError` (409) and calls `record_halt()` on the lifecycle, which logs the event without creating a Sentry issue. The exception is still re-raised so the existing circuit breaker logic in `_populate_trees` continues to work as before. Refs SENTRY-5K7F
mchen-sentry
pushed a commit
that referenced
this pull request
Feb 24, 2026
…I calls (#109153) Cache the result when GitHub's Git Trees API returns a 409 ("Git Repository is empty") instead of re-fetching on every task run. Previously, when `get_tree` hit a 409 for an empty repo, the exception propagated without writing to cache. This meant every subsequent `auto_source_code_config` task run would re-fetch the same empty repos, wasting API calls and contributing to GitHub rate limiting. For large orgs with many empty repos, this adds up to thousands of unnecessary API calls per day. Now we catch `ApiConflictError` in `get_cached_repo_files`, cache an empty list with the same TTL as successful results (24h + staggered offset), and return early. The existing error handling in `_populate_trees` is unaffected since the exception no longer propagates. Pairs with #109134 which records these 409s as halts instead of failures in the interaction event lifecycle. Refs SENTRY-5K7F
wedamija
pushed a commit
that referenced
this pull request
Feb 24, 2026
…f failures (#109134) Wraps `get_tree` and `get_repositories_from_github` in `SCMIntegrationInteractionEvent` context managers to track these GitHub API interactions. Additionally, handles 409 responses from GitHub's tree API (returned for empty repositories) as halts rather than failures. These are expected responses that don't indicate a bug, but the `SCMIntegrationInteractionEvent` wrapper was surfacing them as Sentry issues via `capture_exception`, which caused high-occurrence alerts that blocked deployments. The fix catches `ApiConflictError` (409) and calls `record_halt()` on the lifecycle, which logs the event without creating a Sentry issue. The exception is still re-raised so the existing circuit breaker logic in `_populate_trees` continues to work as before. Refs SENTRY-5K7F
wedamija
pushed a commit
that referenced
this pull request
Feb 24, 2026
…I calls (#109153) Cache the result when GitHub's Git Trees API returns a 409 ("Git Repository is empty") instead of re-fetching on every task run. Previously, when `get_tree` hit a 409 for an empty repo, the exception propagated without writing to cache. This meant every subsequent `auto_source_code_config` task run would re-fetch the same empty repos, wasting API calls and contributing to GitHub rate limiting. For large orgs with many empty repos, this adds up to thousands of unnecessary API calls per day. Now we catch `ApiConflictError` in `get_cached_repo_files`, cache an empty list with the same TTL as successful results (24h + staggered offset), and return early. The existing error handling in `_populate_trees` is unaffected since the exception no longer propagates. Pairs with #109134 which records these 409s as halts instead of failures in the interaction event lifecycle. Refs SENTRY-5K7F
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Wraps
get_treeandget_repositories_from_githubinSCMIntegrationInteractionEventcontext managers to track these GitHub API interactions.
Additionally, handles 409 responses from GitHub's tree API (returned for
empty repositories) as halts rather than failures. These are expected
responses that don't indicate a bug, but the
SCMIntegrationInteractionEventwrapper was surfacing them as Sentry issues via
capture_exception, whichcaused high-occurrence alerts that blocked deployments.
The fix catches
ApiConflictError(409) and callsrecord_halt()on thelifecycle, which logs the event without creating a Sentry issue. The
exception is still re-raised so the existing circuit breaker logic in
_populate_treescontinues to work as before.Refs SENTRY-5K7F