fix(memory): align evicted upstream generations

This commit is contained in:
m4air
2026-09-19 23:07:01 -07:00
parent b2b3ae9748
commit 9bf533fb38
3 changed files with 30 additions and 2 deletions
@@ -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,
@@ -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,
@@ -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)
})
})