Repository navigation
fix(cmd-j): decline a GitLab iid match when the repo remote names a different project (STA-4450) - #15193
Conversation
…ifferent project (STA-4450) `repoMatchesGitLabSlug` laundered a definite project-path mismatch into `'unknown'` whenever the resolved identity came from a remote named `upstream`, and `worktreeMatchesGitLabUrl` treats `'unknown'` as permission to accept a bare iid. Since `deriveGitRemoteIdentity` ranks `upstream` above `origin`, any repo whose top-ranked remote is `upstream` lost GitLab project gating entirely, so an exact URL for an unrelated project could surface that workspace. Return the `matchGitRemoteKeyParts` verdict directly. Resolved identities are re-probed on a 6h TTL, so a remote naming a different project is current evidence. `'unknown'` now means only "no identity" or "unexpanded SSH host alias", both of which stay permissive as before.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 3 remain after this review. 📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
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. Comment |
…cate test The GitLab why-comment implied resolved identities refresh unconditionally. They only refresh when a repo/project list sweep finds one past its ~6h TTL (`selectEnrichmentCandidates` runs from `repos:list`/`projects:list`/ `projectHostSetups:list`, four refreshes per sweep, after a 5m startup delay); there is no background timer. State the accepted cost instead of implying the gate is loss-free. The GitHub-side comment still claimed the identity is "chosen when the repo was added and never re-probed" — the exact claim this PR disproves. Rewrite it to the reason that still holds (one stored remote hides a fork's `origin`). Behavior on the GitHub path is unchanged; it stays with the twin ticket. Delete `does not surface an upstream-identified repo for an unrelated project iid`: the inverted test above it already asserts both halves (mismatched project declines, the named project still matches) against the same upstream-derived identity.
…n-known-project-mismatch
…ifferent project (STA-4450) (stablyai#15193) * fix(cmd-j): decline a GitLab iid match when the repo remote names a different project (STA-4450) `repoMatchesGitLabSlug` laundered a definite project-path mismatch into `'unknown'` whenever the resolved identity came from a remote named `upstream`, and `worktreeMatchesGitLabUrl` treats `'unknown'` as permission to accept a bare iid. Since `deriveGitRemoteIdentity` ranks `upstream` above `origin`, any repo whose top-ranked remote is `upstream` lost GitLab project gating entirely, so an exact URL for an unrelated project could surface that workspace. Return the `matchGitRemoteKeyParts` verdict directly. Resolved identities are re-probed on a 6h TTL, so a remote naming a different project is current evidence. `'unknown'` now means only "no identity" or "unexpanded SSH host alias", both of which stay permissive as before. * docs(cmd-j): correct the identity-freshness comments and drop a duplicate test The GitLab why-comment implied resolved identities refresh unconditionally. They only refresh when a repo/project list sweep finds one past its ~6h TTL (`selectEnrichmentCandidates` runs from `repos:list`/`projects:list`/ `projectHostSetups:list`, four refreshes per sweep, after a 5m startup delay); there is no background timer. State the accepted cost instead of implying the gate is loss-free. The GitHub-side comment still claimed the identity is "chosen when the repo was added and never re-probed" — the exact claim this PR disproves. Rewrite it to the reason that still holds (one stored remote hides a fork's `origin`). Behavior on the GitHub path is unchanged; it stays with the twin ticket. Delete `does not surface an upstream-identified repo for an unrelated project iid`: the inverted test above it already asserts both halves (mismatched project declines, the named project still matches) against the same upstream-derived identity.
…ifferent project (STA-4450) (stablyai#15193) * fix(cmd-j): decline a GitLab iid match when the repo remote names a different project (STA-4450) `repoMatchesGitLabSlug` laundered a definite project-path mismatch into `'unknown'` whenever the resolved identity came from a remote named `upstream`, and `worktreeMatchesGitLabUrl` treats `'unknown'` as permission to accept a bare iid. Since `deriveGitRemoteIdentity` ranks `upstream` above `origin`, any repo whose top-ranked remote is `upstream` lost GitLab project gating entirely, so an exact URL for an unrelated project could surface that workspace. Return the `matchGitRemoteKeyParts` verdict directly. Resolved identities are re-probed on a 6h TTL, so a remote naming a different project is current evidence. `'unknown'` now means only "no identity" or "unexpanded SSH host alias", both of which stay permissive as before. * docs(cmd-j): correct the identity-freshness comments and drop a duplicate test The GitLab why-comment implied resolved identities refresh unconditionally. They only refresh when a repo/project list sweep finds one past its ~6h TTL (`selectEnrichmentCandidates` runs from `repos:list`/`projects:list`/ `projectHostSetups:list`, four refreshes per sweep, after a 5m startup delay); there is no background timer. State the accepted cost instead of implying the gate is loss-free. The GitHub-side comment still claimed the identity is "chosen when the repo was added and never re-probed" — the exact claim this PR disproves. Rewrite it to the reason that still holds (one stored remote hides a fork's `origin`). Behavior on the GitHub path is unchanged; it stays with the twin ticket. Delete `does not surface an upstream-identified repo for an unrelated project iid`: the inverted test above it already asserts both halves (mismatched project declines, the named project still matches) against the same upstream-derived identity.
…ifferent project (STA-4450) (stablyai#15193) * fix(cmd-j): decline a GitLab iid match when the repo remote names a different project (STA-4450) `repoMatchesGitLabSlug` laundered a definite project-path mismatch into `'unknown'` whenever the resolved identity came from a remote named `upstream`, and `worktreeMatchesGitLabUrl` treats `'unknown'` as permission to accept a bare iid. Since `deriveGitRemoteIdentity` ranks `upstream` above `origin`, any repo whose top-ranked remote is `upstream` lost GitLab project gating entirely, so an exact URL for an unrelated project could surface that workspace. Return the `matchGitRemoteKeyParts` verdict directly. Resolved identities are re-probed on a 6h TTL, so a remote naming a different project is current evidence. `'unknown'` now means only "no identity" or "unexpanded SSH host alias", both of which stay permissive as before. * docs(cmd-j): correct the identity-freshness comments and drop a duplicate test The GitLab why-comment implied resolved identities refresh unconditionally. They only refresh when a repo/project list sweep finds one past its ~6h TTL (`selectEnrichmentCandidates` runs from `repos:list`/`projects:list`/ `projectHostSetups:list`, four refreshes per sweep, after a 5m startup delay); there is no background timer. State the accepted cost instead of implying the gate is loss-free. The GitHub-side comment still claimed the identity is "chosen when the repo was added and never re-probed" — the exact claim this PR disproves. Rewrite it to the reason that still holds (one stored remote hides a fork's `origin`). Behavior on the GitHub path is unchanged; it stays with the twin ticket. Delete `does not surface an upstream-identified repo for an unrelated project iid`: the inverted test above it already asserts both halves (mismatched project declines, the named project still matches) against the same upstream-derived identity.
ELI5
GitLab merge-request numbers (iids) restart at 1 in every project, so
!17in one project has nothing to do with!17in another. Cmd+J was allowed to ignore that check for any repo whose detected remote happened to be namedupstream, so pasting an exact URL for a totally different project could still surface your workspace. Now a remote that names a different project is a real "no".What Changed
repoMatchesGitLabSluginsrc/renderer/src/lib/worktree-palette-gitlab-url-match.tsnow returns thematchGitRemoteKeyPartsverdict directly instead of laundering a definitefalseinto'unknown'whenidentity.remoteName === 'upstream'.matchGitRemoteKeyParts(src/shared/git-remote-identity.ts) only returns a hardfalsewhenidentity.tail !== target.tail— a genuinely different project path. Host-only ambiguity (an unexpanded SSH host alias) already returns'unknown'on its own. So after this change'unknown'means exactly two things: no identity at all, or an unexpanded SSH host alias.Deliberately not changed: the
'unknown'-stays-permissive tail ofworktreeMatchesGitLabUrl(see Notes).Why
deriveGitRemoteIdentityranksupstreamaboveoriginand keeps onlyentries[0], so the escape hatch was far broader than the fork case it was written for: any repo whose top-ranked remote is namedupstreamlost GitLab project gating entirely.Concretely: repo with
upstream = gitlab.com/acme/orca; workspace W haslinkedGitLabMR: 3, nolinkedWorkItem.url, no cached review. Pastinghttps://gitlab.com/totally/unrelated/-/merge_requests/3gave tail mismatch →false→ laundered to'unknown'→ the permissive tail returnedtrue→ W was surfaced for a different project's MR.The comment justifying the hatch ("chosen when the repo was added and never re-probed") is stale:
src/main/repo-git-remote-identity-enrichment.tsre-probes resolved identities on a 6h TTL (RESOLVED_IDENTITY_REFRESH_TTL_MS). A remote naming a different project is therefore current evidence, not a stale guess.Linked Issue
STA-4450 — "Exact GitLab URL can still select a fork workspace" (P1). Original PR #14190; #14381 (0a0ae97) landed but did not close it. No GitHub issue number.
Fixes #
Visual Proof
N/A— this is pure Cmd+J palette matching logic. Nothing about rendering, layout, or the result-row markup changes; the only observable difference is that a workspace that previously appeared for another project's MR/issue URL no longer appears in the result list. There is no before/after frame that shows anything beyond "one bogus row is gone".Testing
All in
src/renderer/src/lib/worktree-palette-task-url-match.test.ts.pnpm typecheckreports 3 errors inopen-tab-search-retention.test.ts/useSessionRestoredBannerDismiss.test.tsx; verified pre-existing onorigin/mainby stashing this branch's diff and re-running. Untouched by this PR.Vacuity check
Stashed only
worktree-palette-gitlab-url-match.ts(kept the tests) and re-ran:declines a different GitLab project even when the identity came from upstream(inverted fromstays permissive for a fork whose identity resolved to the upstream remote)does not surface an upstream-identified repo for an unrelated project iid(new)Result without the fix:
Tests 2 failed | 34 passed (36). With the fix:36 passed.Explicitly still green, unchanged:
gates a stored GitLab number with no work item on the repo remote identity,matches GitLab remotes whose host is an SSH alias or www form of gitlab.com(coversaltssh./gitlab-work/www.),stays permissive for GitLab numbers when the repo remote identity is unknown, the stored-work-item-URL and cached-review cases, and the entire GitHub block.The new test also asserts that the fork's own origin URL (
gitlab.com/me/orca) returnsnull— that documents the accepted false negative rather than hiding it — while the upstream URL (gitlab.com/acme/orca) still matches.AI Disclosure
Claude Opus.
Review
The one judgement call worth a reviewer's attention: this trades a false positive (someone else's project surfacing your workspace, P1) for a false negative (an MR URL from a fork's own origin no longer matching by bare iid, when the single stored identity came from
upstream). That trade is the point of the ticket — a wrong match is worse than a missed one, and the fork origin case is still matchable via the storedlinkedWorkItem.urlor a cached review URL, both of which are checked before the iid gate.Agent skill upstream boundary
Notes
Scoped out (1): the unresolved/
'unknown'case is intentionally left permissive. The obvious "finish the job" follow-on — changingworktreeMatchesGitLabUrl's tail to requirerepoMatchesGitLabSlug(repo, link.slug) === true— is wrong and is deliberately not done here:isUnresolvedSshHostAliasmakesgitlab-work/acme/orcaresolve to'unknown', so=== trueis false and a legitimate match is lost.selectEnrichmentCandidatesfiltersrepo.kind !== 'folder', so a folder repo never gets agitRemoteIdentity. That violates the folder-workspace requirement in AGENTS.md.runtime.enrichMissingRepoGitRemoteIdentities?.()— optional precisely because an older remote host may not implement it. The client would start depending on content the host may not publish.Scoped out (2): the identical escape hatch on the GitHub side.
remoteIdentityMatchesGitHubSluginsrc/renderer/src/lib/worktree-palette-task-url-match.ts(consumed viarepoMatchesGitHubSlug(...) !== false) has the sameremoteName === 'upstream'laundering. It is deliberately left for a twin ticket, because GitHub has an independentdisplayName/repo.upstreamidentity path that GitLab lacks, so the fix there needs its own analysis and its own test matrix. Fixing both in one PR would make the blast radius harder to review.Follow-up (separate PR): additive
canonicalKeys?: string[]. The right way to restore fork-origin matching is to have identity enrichment emit every remote's canonical key alongside the existing singlecanonicalKey, so a fork's ownoriginbecomes matchable without weakening the gate. That field is additive and therefore wire-safe for mixed client/host versions, but it touches the main-process probe and the repo type, so it belongs in its own PR.Cross-platform / SSH / performance: no platform-conditional code, no paths, no shortcuts, no new IPC, no new wire field, no added work per keystroke — this only removes a branch from an existing pure comparison. SSH and relay workspaces are unaffected beyond getting the same corrected gate.
Checklist
N/Awith reason for visual proof