diff --git a/src/main/git/source-control/effective-upstream-status-cache.ts b/src/main/git/source-control/effective-upstream-status-cache.ts index 0a6d8243bae..cf153b71b70 100644 --- a/src/main/git/source-control/effective-upstream-status-cache.ts +++ b/src/main/git/source-control/effective-upstream-status-cache.ts @@ -38,6 +38,10 @@ export function getEffectiveUpstreamStatusGenerationCountForTests(): number { return effectiveUpstreamStatusWriteGeneration.size } +export function getEffectiveUpstreamStatusWriteGeneration(cacheKey: string): number { + return effectiveUpstreamStatusWriteGeneration.get(cacheKey) ?? evictedWriteGeneration +} + export function getEffectiveUpstreamStatusCacheKey( worktreePath: string, branchName: string, diff --git a/src/main/git/source-control/effective-upstream-status-probe.ts b/src/main/git/source-control/effective-upstream-status-probe.ts index 1fd15cda486..c9483dcf681 100644 --- a/src/main/git/source-control/effective-upstream-status-probe.ts +++ b/src/main/git/source-control/effective-upstream-status-probe.ts @@ -11,7 +11,7 @@ import { gitExecFileAsync } from '../runner' import { MAX_EFFECTIVE_UPSTREAM_NEGATIVE_CACHE_ENTRIES, effectiveUpstreamStatusInFlight, - effectiveUpstreamStatusWriteGeneration, + getEffectiveUpstreamStatusWriteGeneration, readCachedEffectiveUpstreamStatus, rememberEffectiveUpstreamStatus, trimEffectiveUpstreamStatusGeneration @@ -46,7 +46,7 @@ export async function readOrProbeEffectiveUpstreamStatus( } // Why: overlapping refreshes at startup — coalesce the upstream probe so a stable missing ref fails once. - const writeGeneration = effectiveUpstreamStatusWriteGeneration.get(cacheKey) ?? 0 + const writeGeneration = getEffectiveUpstreamStatusWriteGeneration(cacheKey) const probe = probeOrRevalidateEffectiveUpstreamStatus( cacheKey, worktreePath, diff --git a/src/main/git/status-upstream-negative-cache.test.ts b/src/main/git/status-upstream-negative-cache.test.ts index f237bf9e519..5618ff1910f 100644 --- a/src/main/git/status-upstream-negative-cache.test.ts +++ b/src/main/git/status-upstream-negative-cache.test.ts @@ -45,6 +45,11 @@ import { getEffectiveUpstreamStatusGenerationCountForTests, getStatus } from './status' +import { + getEffectiveUpstreamStatusWriteGeneration, + readCachedEffectiveUpstreamStatus, + rememberEffectiveUpstreamStatus +} from './source-control/effective-upstream-status-cache' describe('local upstream negative cache', () => { beforeEach(() => { @@ -405,4 +410,23 @@ describe('local upstream negative cache', () => { expect(getEffectiveUpstreamStatusCacheCountForTests()).toBe(0) expect(getEffectiveUpstreamStatusGenerationCountForTests()).toBe(512) }) + + it('continues caching new negatives after generation eviction', () => { + const now = Date.now() + for (let index = 0; index < 513; index += 1) { + rememberEffectiveUpstreamStatus( + `positive-${index}`, + { hasUpstream: true, ahead: 0, behind: 1 }, + now, + true, + 0 + ) + } + const cacheKey = 'new-negative' + const writeGeneration = getEffectiveUpstreamStatusWriteGeneration(cacheKey) + const status = { hasUpstream: false, ahead: 0, behind: 0 } + rememberEffectiveUpstreamStatus(cacheKey, status, now, true, writeGeneration) + + expect(readCachedEffectiveUpstreamStatus(cacheKey, now)).toEqual(status) + }) })