History

fix(server): preserve active VCS cache entries

Ben Davis committed 4 months ago

Commit 4a4df051 parent f891d522 files · +11 −2Browse files

Unified · Split

2 files
  1. apps/server/src/provider/Layers/EventNdjsonLogger.ts +1 −1
  2. apps/server/src/vcs/VcsStatusBroadcaster.ts +10 −1
apps/server/src/provider/Layers/EventNdjsonLogger.ts+1−1
@@ -296,7 +296,7 @@ function enforceRetention(input: { · 295 unmodified lines
296296 (left, right) => left.mtimeMs - right.mtimeMs || left.filePath.localeCompare(right.filePath),
297297 )) {
298298 if (totalBytes <= input.maxTotalBytes) break;
299− remove(file);
299+ if (!remove(file)) break;
300300 }
301301
302302 return { failures, removedCount, totalBytes };
apps/server/src/vcs/VcsStatusBroadcaster.ts+10−1
@@ -190,6 +190,7 @@ export const make = Effect.gen(function* () { · 189 unmodified lines
190190 Scope.close(scope, Exit.void),
191191 );
192192 const statusCache = new Map<string, CachedVcsStatus>();
193+ const activeRemotePollerCwds = new Set<string>();
193194 const pollersRef = yield* SynchronizedRef.make(new Map<string, ActiveRemotePoller>());
194195
195196 const setCachedStatus = (cwd: string, status: CachedVcsStatus) => {
@@ -197,7 +198,13 @@ export const make = Effect.gen(function* () { · 1 unmodified line
197198 statusCache.set(cwd, status);
198199
199200 while (statusCache.size > VCS_STATUS_CACHE_CAPACITY) {
200− const oldestCwd = statusCache.keys().next().value;
201+ let oldestCwd: string | undefined;
202+ for (const cachedCwd of statusCache.keys()) {
203+ if (!activeRemotePollerCwds.has(cachedCwd)) {
204+ oldestCwd = cachedCwd;
205+ break;
206+ }
207+ }
201208 if (oldestCwd === undefined) {
202209 break;
203210 }
@@ -489,6 +496,7 @@ export const make = Effect.gen(function* () { · 285 unmodified lines
489496 return makeRemoteRefreshLoop(cwd, automaticRemoteRefreshInterval, refreshImmediately).pipe(
490497 Effect.forkIn(broadcasterScope),
491498 Effect.map((fiber) => {
499+ activeRemotePollerCwds.add(cwd);
492500 const nextPollers = new Map(activePollers);
493501 nextPollers.set(cwd, {
494502 fiber,
@@ -531,6 +539,7 @@ export const make = Effect.gen(function* () { · 36 unmodified lines
531539 }
532540
533541 return Effect.sync(() => {
542+ activeRemotePollerCwds.delete(cwd);
534543 statusCache.delete(cwd);
535544 return [undefined, activePollers] as const;
536545 });