Repository navigation
Conversation
Split file paths into directory prefixes and rank them by how many unique files they cover, for the upcoming prefix autocomplete endpoints. Refs VDY-245 Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 523bbf5. Configure here.
…efixes Splitting on '/' dropped the empty segments between the triple slashes, collapsing app:///src/index.tsx into prefixes starting with app:/ instead of app:///. Peel the scheme before splitting and re-attach it to each prefix. Refs VDY-245 Co-authored-by: Cursor <cursoragent@cursor.com>
…e raw path Stack roots are matched with startswith before any slash rewrite. Rebuilding a path by dropping empty segments turned UNC, scheme:///, and backslash frames into prefixes the frame does not start with. Emit each prefix as a slice of the original path and keep that path's separator. Refs VDY-245 Co-authored-by: Cursor <cursoragent@cursor.com>
…126616) For project: https://linear.app/getsentry/project/code-mappings-refactor-d3987c38f5f1/overview Adds `GET /api/0/organizations/{org}/code-mapping-prefixes/repo/?repositoryId=` (M11-2, [VDY-246](https://linear.app/getsentry/issue/VDY-246)). Given a single `repositoryId`, the endpoint resolves the active `Repository`, fetches its already-cached source-code file list via `get_cached_repo_files`, and passes those paths through the `rank_directory_prefixes` helper from [#126209](#126209) to return a ranked `prefixes` list (`path`, `fileCount`). It intentionally avoids `get_trees_for_org()` and only touches the one repo the user picked, keeping the response fast on cache hits. The empty-string catch-all is omitted from the JSON — the frontend combobox (M11-4) adds it. Errors that `get_cached_repo_files` already handles internally (empty repo 409, missing ref 404) fall through as `{prefixes: []}` so the field stays typeable; any other `ApiError` returns 502 rather than blocking Save. Refs VDY-246 --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
…126623) For project: https://linear.app/getsentry/project/code-mappings-refactor-d3987c38f5f1/overview Adds `GET /api/0/projects/{org}/{project}/code-mapping-prefixes/stack/` ([VDY-247](https://linear.app/getsentry/issue/VDY-247)). It samples the 50 newest events from the last 7 days, keeps in-app stack filenames, unions in this project's saved stack roots, and ranks directory prefixes with the helper from #126209. An empty sample or a Snuba error returns `{prefixes: []}` so the field stays typeable. Stacked on the directory-prefix helper, in parallel with the repo-prefix endpoint. Refs VDY-247 Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
…es endpoint Capture the RepositoryIntegration check before narrowing to RepoTreesIntegration so mypy can prove each isinstance independently. The prior ordering asked mypy to intersect IntegrationInstallation, RepoTreesIntegration, and RepositoryIntegration[Any] in the true branch, which produces an impossible MRO and triggers warn_unreachable=true as a hard error. Co-authored-by: Cursor <cursoragent@cursor.com>
| integration = integration_service.get_integration(integration_id=repo.integration_id) | ||
| if integration is None: | ||
| return None, Response({"detail": "Integration not found."}, status=404) | ||
|
|
||
| installation = integration.get_installation(organization_id=organization.id) | ||
| repository_installation = ( | ||
| installation if isinstance(installation, RepositoryIntegration) else None | ||
| ) | ||
| if not isinstance(installation, RepoTreesIntegration): | ||
| return None, Response( | ||
| {"detail": "Integration does not support repository trees."}, status=404 | ||
| ) | ||
|
|
||
| cached = installation.get_repo_files_from_cache(repo.name) | ||
| if cached is not None: | ||
| # Warm cache hit — skip the provider branch lookup entirely. | ||
| files = cached | ||
| else: | ||
| if repository_installation is not None: | ||
| try: | ||
| branch = repository_installation.get_repository_default_branch(repo) | ||
| except ApiError as e: | ||
| logger.warning( | ||
| "code_mapping_repo_prefixes.branch_lookup_error", | ||
| extra={"repo": repo.name, "error_code": e.code}, | ||
| ) | ||
| branch = None | ||
| if not branch: | ||
| return None, Response( | ||
| {"detail": "Could not determine default branch for this repository."}, | ||
| status=400, | ||
| ) | ||
| else: | ||
| branch = "HEAD" | ||
|
|
||
| try: | ||
| files = installation.get_cached_repo_files(repo.name, branch, shifted_seconds=0) | ||
| except ApiError as e: | ||
| logger.warning( | ||
| "code_mapping_repo_prefixes.api_error", | ||
| extra={"repo": repo.name, "error_code": e.code}, | ||
| ) | ||
| return None, Response( | ||
| {"detail": "Failed to retrieve repository file list."}, status=502 | ||
| ) |
There was a problem hiding this comment.
Uncaught missing organization integration during repository uninstall race
If this endpoint reads the active repository before the uninstall deletion task disassociates it, but the organization integration is removed before provider access, a cold-cache request can raise OrganizationIntegrationNotFound and return a 500. On the cache-miss path, get_repository_default_branch() and get_cached_repo_files() can call get_client(), which accesses org_integration; the surrounding handlers catch only ApiError. Pre-fetch and seed the organization integration, and handle OrganizationIntegrationNotFound around provider access (for example, return a 404 when the installation is no longer configured).
Evidence
- The repository deletion task disassociates repositories before deleting the organization integration; a request that already read the repository can retain its integration ID during that race.
- On a cache miss,
get_repository_default_branch()callsget_repositories(), which reachesget_client(); GitHub and Cursor Origin clients accessorg_integration. IntegrationInstallation.org_integrationraisesOrganizationIntegrationNotFoundwhen the organization integration row is gone, and the endpoint catches onlyApiErroraround both provider calls.OrganizationRepositoryPlatformsEndpointpre-fetches and seeds the organization integration and catches missing-installation errors, confirming this failure mode is not handled here.
Identified by Warden · sentry-backend-bugs · XZU-V8G

For project: https://linear.app/getsentry/project/code-mappings-refactor-d3987c38f5f1/overview
directory_prefixesturns one file path into its directory prefixes, each with a trailing slash and never including the filename.rank_directory_prefixesunions those prefixes across many files, counts how many unique files sit under each, and keeps the top 200.The repo-prefix and stack-prefix autocomplete endpoints will call this. This change has no HTTP surface.
Refs VDY-245