fix(vcs): resolve SSH aliases before classifying GitHub hosts #7186
main fromrefs/pull/7186/head·opened View on GitHubFixes #6198. git@github-personal:owner/repo no longer becomes GitHub Self-Hosted. SSH aliases are resolved via ssh -G to HostName for API/browser host; git auth still uses the alias.
Note
Medium Risk
Touches provider detection, repository identity, and PR host routing with subprocess ssh -G calls; failures are designed to fall back safely, but wrong resolution could mis-route API calls for affected remotes.
Overview
Fixes misclassification of undotted SSH host aliases (e.g. git@github-personal:…) as self-hosted GitHub/GitLab/Bitbucket. Provider detection now uses a resolved detectionUrl while the stored git remote URL stays unchanged for clone/auth.
SSH resolution: New resolveGitRemoteForSourceControl runs ssh -G only for undotted, non-public aliases, rewrites the remote host via rewriteGitRemoteUrlHost, and falls back to the original URL on failure or timeout. Wired through RepositoryIdentityResolver, SourceControlProviderRegistry, and PullRequestService (with async refinement and cached detection per remote).
Classification: detectSourceControlProviderFromRemoteUrl treats label matches like github in github-personal as unknown unless the host is the public domain or contains a dot (real enterprise hostname).
PR listing: hostnameFromProviderBaseUrl uses URL.host so self-hosted bases keep nonstandard ports (e.g. :8443).
Docs note SSH-alias behavior; @t3tools/ssh gains optional timeout and fallbackOnError on resolveSshTarget.
Note
Resolve SSH host aliases before classifying GitHub/GitLab/Bitbucket remotes#
- SSH remotes with undotted host aliases (e.g.
github-personal) were previously misclassified as self-hosted instances or unknown providers. The fix resolves the real hostname viassh -Gbefore provider detection and canonicalization. - Adds
resolveGitRemoteForSourceControlwhich rewrites the SSH alias host usingrewriteGitRemoteUrlHostfrom shared; the original remote URL is kept for Git authentication. SourceControlProviderRegistry,RepositoryIdentityResolver, andPullRequestServiceall now resolve adetectionUrlbefore classifying or grouping remotes.- Adds
hostnameFromProviderBaseUrlto preserve nonstandard ports in host values used for provider API selection and grouping. - Behavioral Change: undotted SSH aliases (e.g.
github-personal) are no longer treated as enterprise/self-hosted domains byisGitHubHost/isGitLabHost/isBitbucketHost.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
🟠 High
Self-hosted installations on nonstandard ports are assigned a host without that port, so subsequent provider calls target the default HTTPS port and listing/detail requests fail.
hostnameFromProviderBaseUrlusesURL.hostname, which strips:8443from detected base URLs such ashttps://github.company:8443/...; preserve the URL's port when derivingproject.host.No longer relevant as of 9c2eaa931129284a798f3fdb170b9eb88604531a
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 11cbd8cfeef79749090dbee4ba61f0f76e9e07f1. Configure [here](https://www.cursor.com/dashboard/bugbot).
apps/server/src/sourceControl/resolveGitRemoteForSourceControl.ts line 74Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +48,21 @@48+49+/**50+ * SSH aliases such as `github-personal` have no dot and are not public hosts.51+ * Those are the only remotes worth asking `ssh -G` about.52+ */53+export function gitRemoteSshAliasToResolve(remoteUrl: string): string | null {54+ const hostname = parseSshRemoteHostname(remoteUrl);55+ if (hostname === null || hostname.includes(".") || KNOWN_PUBLIC_SSH_HOSTS.has(hostname)) {56+ return null;57+ }58+ return hostname;59+}60+61+export const resolveSshHostnameFromConfig: ResolveSshHostname<ResolveGitRemoteServices> = (alias) =>62+ resolveSshTarget(alias).pipe(63+ Effect.map((target) => {64+ const hostname = target.hostname.trim();65+ return hostname.length > 0 ? hostname : null;66+ }),67+ Effect.orElseSucceed(() => null),68+ );SSH resolve blocks for sixty seconds#
Medium Severity
resolveSshHostnameFromConfigcallsresolveSshTargetwith no short timeout, so it inherits the default 60s SSH command budget. Pull request listing and provider detection now run this on the request path for every undotted SSH alias.RepositoryIdentityResolveralready caps the samessh -Gprobe at 5 seconds, so a slow or hung SSH config (Match exec, missingssh, etc.) can stall the PR pane far longer than identity resolution.Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 11cbd8cfeef79749090dbee4ba61f0f76e9e07f1. Configure [here](https://www.cursor.com/dashboard/bugbot).Additional Locations (1)
Fixed in 9c2eaa931129284a798f3fdb170b9eb88604531a. The listing-path
ssh -Gprobe now uses a 5s budget (SSH_CONFIG_RESOLVE_TIMEOUT_MS) instead of the 60s SSH command default. Timeout or failure leaves the original remote URL and does not invent github.com.Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This change adds automatic SSH-config subprocess resolution and threads the result through repository identity, provider discovery, and pull-request host routing. Although failures fall back safely and tests are included, the cross-cutting runtime and API-routing impact is substantial enough for human review.
Notes:
- Diff unchanged. Approvability was decided on eligibility alone.
Fixed in 9c2eaa931129284a798f3fdb170b9eb88604531a.
hostnameFromProviderBaseUrlnow usesURL.hostso a nonstandard port is kept (https://github.company:8443→github.company:8443) forproject.hostand later API calls.Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Note
🤖 GPT-6 Astra (preview) responding on behalf of Theo
This note is part of an automated cleanup pass.
Preserving these details from items reviewed in the cleanup pass.
Carryover from #9497 at 1f21017: preserve
packages/shared/src/git.test.tsandsourceControl.test.tscases for SCP and SSH-URLgithub.com-work, GitLab aliases, unchanged HTTPS hosts, canonical repository identity, and owner/repo parsing. The resolver currently skips dotted aliases. Extend it to consult SSH configuration for these names, and verify the resolved identity reaches GitManager's PR consumers while Git authentication keeps the original alias. Keep SSH ports out of HTTPS API origins. Add a realgithub.com-work.examplenegative case so host spelling alone never selects GitHub. These are follow-up requirements, not claims that tests or code have been ported.Additional alias fixtures from #9487 at de7462b:
sourceControl.test.tscoversssh.dev.azure.com-work,bitbucket.org-personal, GitHub SCP/SSH forms, and HTTPS hosts that resemble aliases. Preserve those inputs when testing actual SSHHostNameresolution. Do not preserve its expectedhttps://gitlab.com:2222result forssh://git@gitlab.com-personal:2222/...: the SSH port is not the HTTPS API port. These cases are recorded for follow-up, not implemented by this note.Carryover from #6196 at 0fed43997d: cover GitManager's direct reads of the branch-selected remote, its
originfallback, and pull request repository identity. These readers need the resolved detection URL without changing the raw remote used for SSH authentication. Keep tests forssh://ports, IPv6 HostName values, retry after a failed SSH probe, and unchanged local/non-SSH paths. Dotted and user-less aliases also need review. This records missing coverage, not a completed port.Verified on the branch: the five touched test files pass, and swapping in main's
sourceControl.tsmakes the classifier and rewrite tests fail, so they pin the change.ssh -Gon an alias that isn't in ssh config just echoes the name back, so the fallback never invents github.com.One gap worth closing here, since #9497 was closed in favor of this PR:
gitRemoteSshAliasToResolveskips any host containing a dot, so the documented multi-account formgit@github.com-work:owner/repo.git(the case in #9458) never reachesssh -G, and the new classifier still reports it as GitHub Self-Hosted withhttps://github.com-workas the base URL. On this branch detect returns{kind: github, name: GitHub Self-Hosted, baseUrl: https://github.com-work}, the canonical key staysgithub.com-work/owner/repo, and owner/repo parsing returns null. Dropping the dot gate and keeping only the public-host skip should be safe, since a dotted name that isn't an alias echoes back unchanged. Happy to send the carried-over test cases from #9497 as a follow-up if you'd rather keep this one focused.Note: GPT-6 on behalf of shivam (@shivamhwp).
resolveGitRemoteForSourceControlpasses only the bare alias tossh -G, discarding the remote username. WithMatch originalhost reviewalias user gitselectinggithub.comand a fallbackHost reviewaliasselectinggitlab.com,git@reviewalias:owner/repo.gitresolves to GitLab when the local OS user is notgit. Preserve the SSH destination username, and the explicit port for URI remotes, when resolving configuration. Keep the original Git locator for authentication.The SSH-port issue recorded above also remains at
9c2eaa9: after rewritingssh://git@reviewalias:2222/owner/repo.git, provider detection buildshttps://github.com:2222. Use the hostname without the SSH transport port for the API origin, while preserving custom HTTPS ports. Dotted-alias support from the earlier carryover remains outstanding.juliusmarminge added labelsmacroscope-review
Thanks for carrying this. I hit the same bug: my laptop's remote is
gh:owner/repothroughHost gh/HostName github.com, so the project showed up twice in the sidebar. I worked out a fix for repository identity before finding this PR. Reading9c2eaa9, these cases still don't resolve. I checked each one against realssh -G(OpenSSH 10.0 on Windows, 10.2 on Ubuntu):- SCP remotes without a user.
gh:owner/repois valid git syntax, butSCP_SSH_HOST_PATTERNrequiresuser@, so it never reachesssh -G. - Dotted aliases (
github.com-work), as noted above. - Absolute paths.
user@alias:/srv/git/app.gitis rewritten touser@10.0.0.5:/srv/git/app.git.normalizeGitRemoteUrldoesn't parse a path that starts with/, so the key is the raw string and never matchesssh://user@10.0.0.5/srv/git/app.git. - Two logins on one server (false merge).
darky@box:app.gitandcodex@box:app.gitare~darky/app.gitand~codex/app.git, two different repositories. AfterHostNameresolution both are keyed10.0.0.5/app, so they merge into one project. My fix: on hosts the classifier reports asunknown, when the login isn'tgit, key a relative path as~login/path(git's own spelling). Forges are untouched, and any miss leaves an unmerged duplicate rather than a wrong merge. - Port-443 endpoints.
HostName ssh.github.comis classified as GitHub Self-Hosted, withhttps://ssh.github.comas the API base. Mappingssh.github.com,altssh.gitlab.comandaltssh.bitbucket.orgto their main hosts fixes it. git+ssh://andssh+git://remotes skip resolution, because onlyssh://is checked.- User and port. I agree with the note above. Passing
-l <user>(injection-safe, since it's an option value) and-p <port>makesMatch originalhost X user gitwork:ssh -G reviewresolves to gitlab.com, whilessh -G -l git reviewresolves to github.com.
My branch covers these for
RepositoryIdentityResolveronly, not the PR-pane wiring in this PR:darkyeg:fix/ssh-host-alias-remotes(fb5d8da). It has a table-driven test matrix: Bitbucket, SourceHut~userpaths, a self-hosted forge on a plain host name, CodeCommit, Gerrit on:29418, an alias withoutUser, andMatch user. Swapping in main's resolver makes the alias tests fail. I'm happy to port the cases onto this PR or send them as a follow-up once it lands, whichever you prefer.Written with Claude Opus 5.5 in Claude Code.
- SCP remotes without a user.
Thanks for working on this. We merged the orchestrator V2 rewrite in #2829, and we are closing this PR as part of that transition.
The patch conflicts with the rewrite in apps/server/src/sourceControl/SourceControlProviderRegistry.ts. Even where the conflict is small enough to rebase, we are asking for fresh PRs against the new base so we can review and verify the behavior in V2.
Sorry for the extra work this creates. If the change is still needed on V2, please rebuild it on current main, verify it there, and open a new PR linking back here. We're closing the current implementation without assuming the underlying request is resolved.
juliusmarminge closed this
Sign in to join this conversation.

Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
9105ea65-fc38-4d93-b655-a2e33ee3355eYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share