Skip to content

fix(cmd-j): decline a GitLab iid match when the repo remote names a different project (STA-4450) - #15193

Merged
nwparker merged 3 commits into
mainfrom
nwparker/sta-4450-decline-gitlab-iid-match-on-known-project-mismatch
Aug 18, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/sta-4450-decline-gitlab-iid-match-on-known-project-mismatch

Conversation

@nwparker

@nwparker nwparker commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1

ELI5

GitLab merge-request numbers (iids) restart at 1 in every project, so !17 in one project has nothing to do with !17 in another. Cmd+J was allowed to ignore that check for any repo whose detected remote happened to be named upstream, 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

repoMatchesGitLabSlug in src/renderer/src/lib/worktree-palette-gitlab-url-match.ts now returns the matchGitRemoteKeyParts verdict directly instead of laundering a definite false into 'unknown' when identity.remoteName === 'upstream'.

matchGitRemoteKeyParts (src/shared/git-remote-identity.ts) only returns a hard false when identity.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 of worktreeMatchesGitLabUrl (see Notes).

Why

deriveGitRemoteIdentity ranks upstream above origin and keeps only entries[0], so the escape hatch was far broader than the fork case it was written for: any repo whose top-ranked remote is named upstream lost GitLab project gating entirely.

Concretely: repo with upstream = gitlab.com/acme/orca; workspace W has linkedGitLabMR: 3, no linkedWorkItem.url, no cached review. Pasting https://gitlab.com/totally/unrelated/-/merge_requests/3 gave tail mismatch → false → laundered to 'unknown' → the permissive tail returned true → 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.ts re-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.

npx oxlint src/renderer/src/lib/worktree-palette-gitlab-url-match.ts src/renderer/src/lib/worktree-palette-task-url-match.test.ts   # clean
npx vitest run --config config/vitest.config.ts src/renderer/src/lib/worktree-palette-task-url-match.test.ts   # 36 passed
npx tsc --noEmit -p config/tsconfig.tc.web.json   # 0 errors in touched files

pnpm typecheck reports 3 errors in open-tab-search-retention.test.ts / useSessionRestoredBannerDismiss.test.tsx; verified pre-existing on origin/main by 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:

Test Without fix With fix
declines a different GitLab project even when the identity came from upstream (inverted from stays permissive for a fork whose identity resolved to the upstream remote) FAIL PASS
does not surface an upstream-identified repo for an unrelated project iid (new) FAIL PASS
other 34 in the file PASS PASS

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 (covers altssh. / 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) returns null — that documents the accepted false negative rather than hiding it — while the upstream URL (gitlab.com/acme/orca) still matches.

  • I manually tested these changes locally (unit level; the code path is pure and fully covered by the file above)
  • Automated tests added/updated

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 stored linkedWorkItem.url or a cached review URL, both of which are checked before the iid gate.

Agent skill upstream boundary

  • Not applicable.

Notes

Scoped out (1): the unresolved/'unknown' case is intentionally left permissive. The obvious "finish the job" follow-on — changing worktreeMatchesGitLabUrl's tail to require repoMatchesGitLabSlug(repo, link.slug) === true — is wrong and is deliberately not done here:

  1. It breaks the SSH-alias case: isUnresolvedSshHostAlias makes gitlab-work/acme/orca resolve to 'unknown', so === true is false and a legitimate match is lost.
  2. It permanently disables GitLab number matching for folder workspaces: selectEnrichmentCandidates filters repo.kind !== 'folder', so a folder repo never gets a gitRemoteIdentity. That violates the folder-workspace requirement in AGENTS.md.
  3. Remote-wire regression: enrichment is invoked as 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.
  4. It breaks the window between adding a repo and its first successful probe, and any host that is unreachable.

Scoped out (2): the identical escape hatch on the GitHub side. remoteIdentityMatchesGitHubSlug in src/renderer/src/lib/worktree-palette-task-url-match.ts (consumed via repoMatchesGitHubSlug(...) !== false) has the same remoteName === 'upstream' laundering. It is deliberately left for a twin ticket, because GitHub has an independent displayName / repo.upstream identity 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 single canonicalKey, so a fork's own origin becomes 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

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • N/A with reason for visual proof
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Targeted lint / typecheck / tests pass locally; CI covers the rest

…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.
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dcab6d42-a263-4f73-9c1e-4d904ce6e1b3

📥 Commits

Reviewing files that changed from the base of the PR and between 39e57be and 61bc548.

📒 Files selected for processing (3)
  • src/renderer/src/lib/worktree-palette-gitlab-url-match.ts
  • src/renderer/src/lib/worktree-palette-task-url-match.test.ts
  • src/renderer/src/lib/worktree-palette-task-url-match.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/lib/worktree-palette-gitlab-url-match.ts
  • src/renderer/src/lib/worktree-palette-task-url-match.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

repoMatchesGitLabSlug now returns the direct result from matchGitRemoteKeyParts. Project mismatches return false, including mismatches for upstream identities. Missing or unresolved identities remain 'unknown'. Tests verify that GitLab merge request URLs match the identified upstream project and reject unrelated projects.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the Cmd+J GitLab IID matching fix and the affected upstream-remote case.
Description check ✅ Passed The description clearly covers the change, rationale, testing, scope, risks, and checklist; the linked issue field is not populated as a formal link.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

…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.
@nwparker
nwparker merged commit 3697d68 into main Aug 18, 2026
87 of 89 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…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.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant