Skip to content

fix(gitlab): expire project-ref negatives instead of caching them forever - #12390

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-gitlab-ttl-deflake
Aug 4, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-gitlab-ttl-deflake

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

src/main/gitlab/gitlab-project-ref-resolution.ts stored null with no expiry and returned any cached value straight from the map. 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 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 async glab auth status --hostname fallback and per-call knownHosts):

  • Negatives expire on the shared NEGATIVE_ENTRY_TTL_MS, imported from remote-ref-probe-cache so the interval stays single-sourced. Positives still never expire.
  • The SSH provider generation joins the cache signature, so a reconnect that swaps the execution host under the same connection id re-asks instead of serving the retired host's answer. (knownHosts already carried the glab auth state into the key.)
  • A probe abandoned as stale can no longer publish over its successor's answer (ownsKey guard, matching the generic cache). runProjectRefProbeOnce was dropping the ownsKey argument runCoalescedProbe already provides.
  • Transient git/SSH failures stay uncached, as before. SSH failures deliberately stay uncached outright rather than adopting the generic cache's stable-missing-remote exception — keeping a connected host's detection fresh is worth the extra probe. That divergence is commented in the source.

Cost regression this fix would otherwise have introduced, closed here: parseRemoteProjectRefCandidate accepts any host, so a plain GitHub repo reaches glab auth status --hostname github.com. With negatives previously cached forever, that spawned glab once per repo per process; with negatives expiring it would have become one glab spawn per repo per interval on the hosted-review poll (getProjectSlug). gitlab-known-host-probe.ts now memoizes the "not authenticated" answer per host (not per repo) on the same TTL clock, bounded at 128 entries, and a successful rememberGlabKnownHost clears it. Three repos on the same unauthenticated host now cost one glab spawn per interval instead of three.

Provider-generic: no Azure DevOps / Bitbucket / Gitea path was touched — remote-ref-probe-cache.ts is imported from, not modified.

Scope note: this PR originally also carried a deflake for tests/e2e/workspace-board-lane-virtualization.spec.ts. That rework did not survive CI-runner load (it still failed the changed-e2e-specs job), so it has been removed from this branch and moved to its own PR rather than holding this clean fix hostage. This PR is now GitLab-only.

Screenshots

No visual change — main-process cache behavior only; no renderer or user-facing copy touched.

Testing

  • pnpm lint — passed (full run, exit 0), plus audit:code-quality:native and audit:code-quality:type-aware.
  • pnpm typecheck — passed (via pnpm tc), re-run after rebasing onto current main (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 unmodified origin/main scratch worktree (agent-exec-handler, check-root-directory-entries, updater reproduced 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.
  • Added or updated high-quality tests that would catch regressions

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:

test red without fix?
re-probes a repo whose GitLab remote could have been added since the miss ✅ fails without TTL
does not serve a project ref resolved on a retired SSH connection ✅ fails without generation keying
asks glab about an unauthenticated host once per interval, not once per repo ✅ fails without the per-host memo
keeps a resolved project ref past the negative interval guard (green before and after — pins that positives don't expire)
does not cache a local probe killed on its deadline as a definitive miss guard (green before and after — pins transient-not-cached)
re-resolves a self-hosted remote once glab auth knows its host guard (auth signature was already keyed via 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:

  • Spawn-cost regression introduced by my own TTL — expiring negatives turned glab auth status --hostname from once-per-repo-per-process into once-per-repo-per-interval on the hosted-review poll. Found by tracing getProjectSlug callers and confirming parseRemoteProjectRefCandidate accepts non-GitLab hosts. Fixed with the per-host memo described above, with a test pinning the spawn budget.
  • Stale-probe publish — resolveProjectRefForRemote wrote the cache unconditionally. Now threaded through ownsKey and gated.
  • Verified no import cycle from gitlab/ → git/remote-ref-probe-cache (that module imports only ssh-git-dispatch, coalesced-probe, remote-url-probe, stable-missing-git-remote-error).
  • Confirmed _resetProjectRefCache also 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 same knownHostsExecutionKey (native / wsl:<distro> / connection:<id>:<gen>). No new path handling, no shell invocation, no new binary arguments; glab args 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.

  • Command execution: no new commands. 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).
  • Input handling: the host fed to the new memo comes from parseRemoteProjectRefCandidate and is normalized through the existing normalizeGitLabHost. Cache keys use \0 separators consistent with surrounding code, so a host or repo path cannot forge a different context's key.
  • Auth/secrets: the memo stores only a hostname and an expiry timestamp — no tokens, no glab output, 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.
  • Path handling / IPC / dependencies: unchanged. No new dependencies. Both caches are bounded (512 project refs, 128 hosts) with FIFO eviction.

Notes

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

GitLab 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)
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 describes the primary GitLab cache change: negative project-reference results now expire.
Description check ✅ Passed The description covers the summary, testing, visual impact, AI review, security audit, and platform notes, and explains why the build was not run.
✨ Finishing Touches
📝 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.

…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.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/fix-gitlab-ttl-deflake branch from 91ac672 to 34e9e42 Compare August 4, 2026 02:25
@brennanb2025 brennanb2025 changed the title fix(gitlab): expire project-ref negatives, deflake board marquee e2e fix(gitlab): expire project-ref negatives instead of caching them forever Aug 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a69ca6d and 34e9e42.

📒 Files selected for processing (4)
  • src/main/gitlab/gitlab-known-host-probe.ts
  • src/main/gitlab/gitlab-project-ref-resolution.ts
  • src/main/gitlab/gl-utils.test.ts
  • src/main/gitlab/project-ref-inflight.ts

Comment on lines +271 to +298
// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 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.

@brennanb2025
brennanb2025 merged commit c052ca1 into main Aug 4, 2026
42 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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