Repository navigation
fix(gitlab): expire project-ref negatives instead of caching them forever - #12390
Conversation
📝 WalkthroughWalkthroughGitLab unauthenticated-host caching now has execution-context-aware keys, TTL expiry, a 128-entry limit, eviction, and test reset support. Project-reference caching now distinguishes positive and negative expiration, includes SSH or WSL context, and prevents stale probes from publishing results. Authentication checks reuse and update the unauthenticated-host cache. Tests cover timeout recovery, cache expiry, authentication changes, host probe deduplication, and SSH connection replacement. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
…ever GitLab's project-ref cache stored `null` forever and returned any cached value straight from the map, so a repo probed before `origin` was configured — or before `glab auth login` ran for its self-hosted host — kept hosted-review provider detection stale until app restart. The negative-TTL work that shipped for Azure DevOps / Bitbucket / Gitea skipped it. Mirror `createRemoteRefProbeCache`'s semantics: negatives expire on the shared interval, positives stay, the SSH provider generation joins the cache signature so a reconnect re-asks, and a probe abandoned as stale can no longer publish over its successor. Transient git/SSH failures stay uncached. Expiring negatives would otherwise turn `glab auth status --hostname` into one spawn per repo per interval on the hosted-review poll, since a non-GitLab remote reaches it too, so remember the unauthenticated answer per host — not per repo — on the same clock.
91ac672 to
34e9e42
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7b096d8c-d2b9-416c-a715-1bfc88fcf04d
📒 Files selected for processing (4)
src/main/gitlab/gitlab-known-host-probe.tssrc/main/gitlab/gitlab-project-ref-resolution.tssrc/main/gitlab/gl-utils.test.tssrc/main/gitlab/project-ref-inflight.ts
| // Why: this probe is per host, but the project-ref miss that reaches it is per | ||
| // repo — without the memo, every non-GitLab repo re-spawns `glab` each time | ||
| // its negative expires. | ||
| if (isGlabHostKnownUnauthenticated(projectRef.host, connectionId, localGitOptions)) { | ||
| return false | ||
| } | ||
| try { | ||
| const result = await glabExecFileAsync( | ||
| ['auth', 'status', '--hostname', projectRef.host], | ||
| glabRepoExecOptions(repoPath, connectionId, localGitOptions) | ||
| ) | ||
| return result !== undefined | ||
| if (result === undefined) { | ||
| rememberGlabHostUnauthenticated(projectRef.host, connectionId, localGitOptions) | ||
| return false | ||
| } | ||
| return true | ||
| } catch (error) { | ||
| const execLike = error as { stdout?: unknown; stderr?: unknown; message?: unknown } | ||
| const output = | ||
| [execLike.stdout, execLike.stderr, execLike.message] | ||
| .filter((value): value is string => typeof value === 'string' && value.trim().length > 0) | ||
| .join('\n') || String(error) | ||
| const hosts = parseGlabAuthStatusHosts(output).map(normalizeGitLabHost) | ||
| return hosts.includes(normalizeGitLabHost(projectRef.host)) | ||
| if (hosts.includes(normalizeGitLabHost(projectRef.host))) { | ||
| return true | ||
| } | ||
| rememberGlabHostUnauthenticated(projectRef.host, connectionId, localGitOptions) | ||
| return false |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift
Coalesce concurrent unauthenticated-host probes.
Several repositories can pass the cache check at Line 274 before any probe writes the negative entry at Lines 283 or 297. Each repository then starts its own glab auth status process. The once-per-host behavior only works for serial calls.
Store an in-flight promise per execution-context and host key. Make later callers join that promise. Clear it when the probe settles. Add a Promise.all test for multiple repositories on the same unauthenticated host.
…ever (stablyai#12390) GitLab's project-ref cache stored `null` forever and returned any cached value straight from the map, so a repo probed before `origin` was configured — or before `glab auth login` ran for its self-hosted host — kept hosted-review provider detection stale until app restart. The negative-TTL work that shipped for Azure DevOps / Bitbucket / Gitea skipped it. Mirror `createRemoteRefProbeCache`'s semantics: negatives expire on the shared interval, positives stay, the SSH provider generation joins the cache signature so a reconnect re-asks, and a probe abandoned as stale can no longer publish over its successor. Transient git/SSH failures stay uncached. Expiring negatives would otherwise turn `glab auth status --hostname` into one spawn per repo per interval on the hosted-review poll, since a non-GitLab remote reaches it too, so remember the unauthenticated answer per host — not per repo — on the same clock.
Summary
src/main/gitlab/gitlab-project-ref-resolution.tsstorednullwith no expiry and returned any cached value straight from the map. A repo probed beforeoriginwas configured — or beforeglab auth loginran for its self-hosted host — kept hosted-review provider detection stale until app restart. The negative-TTL work that shipped for the other forges (createRemoteRefProbeCache: negative TTL, signature keying, 512-entry bound, no caching of transient failures) skipped GitLab.This mirrors those semantics in the GitLab cache (rather than reusing
createRemoteRefProbeCache, which takes a synchronous URL parser — GitLab's resolution needs an asyncglab auth status --hostnamefallback and per-callknownHosts):NEGATIVE_ENTRY_TTL_MS, imported fromremote-ref-probe-cacheso the interval stays single-sourced. Positives still never expire.knownHostsalready carried the glab auth state into the key.)ownsKeyguard, matching the generic cache).runProjectRefProbeOncewas dropping theownsKeyargumentrunCoalescedProbealready provides.Cost regression this fix would otherwise have introduced, closed here:
parseRemoteProjectRefCandidateaccepts any host, so a plain GitHub repo reachesglab auth status --hostname github.com. With negatives previously cached forever, that spawnedglabonce per repo per process; with negatives expiring it would have become oneglabspawn per repo per interval on the hosted-review poll (getProjectSlug).gitlab-known-host-probe.tsnow memoizes the "not authenticated" answer per host (not per repo) on the same TTL clock, bounded at 128 entries, and a successfulrememberGlabKnownHostclears it. Three repos on the same unauthenticated host now cost oneglabspawn per interval instead of three.Provider-generic: no Azure DevOps / Bitbucket / Gitea path was touched —
remote-ref-probe-cache.tsis imported from, not modified.Screenshots
No visual change— main-process cache behavior only; no renderer or user-facing copy touched.Testing
pnpm lint— passed (full run, exit 0), plusaudit:code-quality:nativeandaudit:code-quality:type-aware.pnpm typecheck— passed (viapnpm tc), re-run after rebasing onto currentmain(194e1a8d4d).pnpm test— the targeted suites are green on the current base:src/main/gitlab/+remote-ref-probe-cache= 237/237. The full-suite run showed 24 unrelated failures which I verified base-identical by re-running them on an unmodifiedorigin/mainscratch worktree (agent-exec-handler,check-root-directory-entries,updaterreproduced there directly; the rest are PTY/daemon/fs-watcher timing on node 26). None of the failing files import anything this PR touches.pnpm build— not run. No build-surface change in this diff.Tests added to
src/main/gitlab/gl-utils.test.ts(5 new), each verified non-vacuous by reverting the fix and confirming it goes red:knownHosts)AI Review Report
Self-review focused on: cache-poisoning and staleness semantics, probe coalescing races, process-spawn cost, and test vacuity.
Flagged and fixed during review:
glab auth status --hostnamefrom once-per-repo-per-process into once-per-repo-per-interval on the hosted-review poll. Found by tracinggetProjectSlugcallers and confirmingparseRemoteProjectRefCandidateaccepts non-GitLab hosts. Fixed with the per-host memo described above, with a test pinning the spawn budget.resolveProjectRefForRemotewrote the cache unconditionally. Now threaded throughownsKeyand gated.gitlab/→git/remote-ref-probe-cache(that module imports onlyssh-git-dispatch,coalesced-probe,remote-url-probe,stable-missing-git-remote-error)._resetProjectRefCachealso clears the new memo so state cannot leak between tests.Cross-platform compatibility explicitly reviewed for macOS, Linux, and Windows. The change keeps the existing execution-context separation intact and extends it: cache keys distinguish native host, WSL distro (
wslDistro), and SSH connection including generation, so a Windows/WSL host and its native host cannot share a project-ref answer — the existing "keeps local host and local WSL project-ref cache entries separate" test still passes, and the new memo is keyed through the sameknownHostsExecutionKey(native /wsl:<distro>/connection:<id>:<gen>). No new path handling, no shell invocation, no new binary arguments;glabargs are unchanged. Git binary compatibility is unaffected —git remote get-url(well below the 2.25 baseline) is the only git command involved and it was not modified. SSH and folder-workspace cases were considered: SSH negatives remain uncached (deliberate, commented), and nothing here assumes a git worktree.Declining CodeRabbit's Docstring Coverage (80%) check per
AGENTS.md("Concise/Brief Non-obvious comments ONLY … 1 LINE if possible").Security Audit
Low risk; no new attack surface.
glab auth status --hostname <host>was already invoked on this path; this PR only reduces how often it runs. Argument construction is unchanged and still array-form (no shell interpolation).parseRemoteProjectRefCandidateand is normalized through the existingnormalizeGitLabHost. Cache keys use\0separators consistent with surrounding code, so a host or repo path cannot forge a different context's key.glaboutput, no credentials. Auth state is keyed per execution context, so a WSL distro or SSH connection cannot read another's authentication answer. Expiring negatives is a strict improvement for auth correctness: a repo is no longer permanently misclassified based on a pre-login probe.Notes
git remote get-urlonce per 5-minute interval instead of once per process. This is the same cost Azure DevOps / Bitbucket / Gitea already pay, and theglabhalf is amortized per host by the new memo.main(194e1a8d4d) after fix(persistence): make the renderer unload checkpoint durably flush before reporting success #12387/fix(worktrees): fence SSH worktree deletion PTY teardown to the owning host #12388 landed; no file overlap with either.pnpm buildwas not run; see Testing.