fix(integrations): Cache missing GitHub repo tree lookups#113113
fix(integrations): Cache missing GitHub repo tree lookups#113113
Conversation
Cache GitHub repo tree 404 responses as empty results to avoid repeated failing requests from auto source code config. Keep non-404 API errors raising normally and cover both behaviors with tests. Fixes SENTRY-5K7G Co-Authored-By: Codex <noreply@openai.com> Made-with: Cursor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: 404 cache missing staggered expiration unlike other cases
- Added shifted_seconds to the NOT_FOUND_CACHE_SECONDS duration at line 221 to stagger cache expirations across repos, consistent with the ApiConflictError and success path handling.
Or push these changes by commenting:
@cursor push 521812cc91
Preview (521812cc91)
diff --git a/src/sentry/integrations/source_code_management/repo_trees.py b/src/sentry/integrations/source_code_management/repo_trees.py
--- a/src/sentry/integrations/source_code_management/repo_trees.py
+++ b/src/sentry/integrations/source_code_management/repo_trees.py
@@ -218,7 +218,7 @@
"Caching empty files result for missing repo or ref",
extra={"repo": repo_full_name},
)
- cache.set(key, [], NOT_FOUND_CACHE_SECONDS)
+ cache.set(key, [], NOT_FOUND_CACHE_SECONDS + shifted_seconds)
tree = None
else:
raiseYou can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit c29b65f. Configure here.
| "Caching empty files result for missing repo or ref", | ||
| extra={"repo": repo_full_name}, | ||
| ) | ||
| cache.set(key, [], NOT_FOUND_CACHE_SECONDS) |
There was a problem hiding this comment.
404 cache missing staggered expiration unlike other cases
Low Severity
The 404 cache uses a fixed NOT_FOUND_CACHE_SECONDS duration without adding shifted_seconds, while the ApiConflictError (409) and success paths both use self.CACHE_SECONDS + shifted_seconds to stagger cache expirations across repos. When _populate_trees processes many missing repos, all their negative-cache entries expire at the exact same time, causing a burst of repeated 404 API calls on the next run instead of spreading them out.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c29b65f. Configure here.
Backend Test FailuresFailures on
|



Cache GitHub repo tree 404 responses as empty results in repo tree fetching.
Auto source code config was repeatedly requesting the same missing repos/refs and
producing high-volume errors. Negative-caching these not-found responses for one day
reduces repeated API calls and issue noise while preserving current handling for other
API failures.
I considered applying this to all API errors, but that would hide actionable failures.
The change is intentionally scoped to not-found responses and keeps other errors raising
as before.
Tests cover the new 404 cache behavior and confirm non-404 ApiError responses still raise.
Fixes SENTRY-5K7G
Made with Cursor