Skip to content

Commit 143af9f

Browse files
fix(server): keep serving a project's last repository identity while it refreshes
Once a project's repository identity passed its one-minute cache TTL, peek and getAvailable returned null until the refresh finished, and returned null again if the refresh failed. Clients with no identity on record then split the project out of its repository group. ProjectEnrichmentService now records the last successfully resolved identity per root in a map capped at cacheCapacity. peek falls back to it when the cache has no fresh success. A new resolution replaces it, a resolved null clears it, and invalidate drops it. repositoryIdentityResolved still means freshly resolved, so the fallback is never sent as a resolved root. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 76d3aa8 commit 143af9f

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

‎apps/server/src/project/ProjectEnrichmentService.ts‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,30 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
9191
const maxPending = Math.max(1, options.maxPending ?? DEFAULT_MAX_PENDING);
9292
const concurrency = Math.max(1, options.concurrency ?? DEFAULT_CONCURRENCY);
9393

94+
// Outlives the cache entry so an expired or refreshing identity still reads as its last value.
95+
const lastRepositoryIdentities = new Map<string, RepositoryIdentity>();
96+
const rememberRepositoryIdentity = (
97+
workspaceRoot: string,
98+
repositoryIdentity: RepositoryIdentity | null,
99+
) => {
100+
lastRepositoryIdentities.delete(workspaceRoot);
101+
if (repositoryIdentity === null) return;
102+
if (lastRepositoryIdentities.size >= cacheCapacity) {
103+
const oldestRoot = lastRepositoryIdentities.keys().next().value;
104+
if (oldestRoot !== undefined) lastRepositoryIdentities.delete(oldestRoot);
105+
}
106+
lastRepositoryIdentities.set(workspaceRoot, repositoryIdentity);
107+
};
108+
94109
const repositoryIdentityCache = yield* Cache.makeWith(
95-
(workspaceRoot: string) => Effect.exit(repositoryIdentityResolver.resolve(workspaceRoot)),
110+
(workspaceRoot: string) =>
111+
Effect.exit(repositoryIdentityResolver.resolve(workspaceRoot)).pipe(
112+
Effect.tap((result) =>
113+
Exit.isSuccess(result)
114+
? Effect.sync(() => rememberRepositoryIdentity(workspaceRoot, result.value))
115+
: Effect.void,
116+
),
117+
),
96118
{
97119
capacity: cacheCapacity,
98120
timeToLive: Exit.match({
@@ -238,10 +260,13 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
238260
] as const,
239261
{ concurrency: "unbounded" },
240262
);
263+
const repositoryIdentityResolved = isSuccessfullyResolved(repositoryIdentity);
241264
return {
242-
repositoryIdentity: availableValue(repositoryIdentity),
265+
repositoryIdentity: repositoryIdentityResolved
266+
? availableValue(repositoryIdentity)
267+
: (lastRepositoryIdentities.get(workspaceRoot) ?? null),
243268
faviconPath: availableValue(faviconPath),
244-
repositoryIdentityResolved: isSuccessfullyResolved(repositoryIdentity),
269+
repositoryIdentityResolved,
245270
};
246271
},
247272
);
@@ -287,6 +312,7 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
287312
Effect.all(
288313
[
289314
Cache.invalidate(repositoryIdentityCache, workspaceRoot),
315+
Effect.sync(() => lastRepositoryIdentities.delete(workspaceRoot)),
290316
Cache.invalidate(faviconCache, workspaceRoot),
291317
// The resolver keeps its own misses, which would outlive a clone filling the folder.
292318
faviconResolver.invalidate(workspaceRoot),

0 commit comments

Comments
 (0)