Skip to content

Commit c9b72ad

Browse files
committed
fix(server): cache favicon lookups for missing project folders
A deleted project folder reached the favicon cache as a failed lookup, and failures get a zero TTL, so every enrichment pass stat'd the missing folder again. The resolver now answers a missing workspace root as "no favicon", which gets the same negative cache window. Other failures keep their zero TTL. That makes the missing-root branch in ProjectEnrichmentService unreachable with the real resolver, so it is removed along with the predicate's export. Fixes #23658
1 parent 60b35a1 commit c9b72ad

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,6 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
183183
workspaceRoot: string,
184184
) {
185185
const faviconPath = yield* Cache.get(faviconCache, workspaceRoot);
186-
const isMissingWorkspaceRoot = Option.exists(
187-
Exit.findErrorOption(faviconPath),
188-
ProjectFaviconResolver.isMissingWorkspaceRoot,
189-
);
190-
if (isMissingWorkspaceRoot) {
191-
return;
192-
}
193186
yield* logFailure(workspaceRoot, "faviconPath", faviconPath);
194187
});
195188

‎apps/server/src/project/ProjectFaviconResolver.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const writeTextFile = Effect.fn("writeTextFile")(function* (
4343

4444
const makeResolverWithFileSystem = (fileSystem: FileSystem.FileSystem) =>
4545
ProjectFaviconResolver.make.pipe(
46-
Effect.provide([WorkspacePaths.layer, T3ProjectFileLoader.layer]),
46+
Effect.provide([Layer.fresh(WorkspacePaths.layer), T3ProjectFileLoader.layer]),
4747
Effect.provideService(FileSystem.FileSystem, fileSystem),
4848
);
4949

@@ -81,6 +81,28 @@ it.layer(layerTest)("ProjectFaviconResolverLive", (it) => {
8181
}).pipe(Effect.provide(TestClock.layer())),
8282
);
8383

84+
it.effect("looks up a missing workspace root once within the negative cache window", () =>
85+
Effect.gen(function* () {
86+
const fileSystem = yield* FileSystem.FileSystem;
87+
const path = yield* Path.Path;
88+
const cwd = path.join(yield* makeTempDir, "deleted-project");
89+
let rootStats = 0;
90+
const resolver = yield* makeResolverWithFileSystem(
91+
FileSystem.FileSystem.of({
92+
...fileSystem,
93+
stat: (filePath) => {
94+
if (filePath === cwd) rootStats += 1;
95+
return fileSystem.stat(filePath);
96+
},
97+
}),
98+
);
99+
100+
expect(yield* resolver.resolvePath(cwd)).toBeNull();
101+
expect(yield* resolver.resolvePath(cwd)).toBeNull();
102+
expect(rootStats).toBe(1);
103+
}),
104+
);
105+
84106
it.effect("prefers a t3.json iconPath over well-known files", () =>
85107
Effect.gen(function* () {
86108
const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class ProjectFaviconResolutionError extends Schema.TaggedError<ProjectFav
101101

102102
const isWorkspaceRootNotExistsError = Schema.is(WorkspacePaths.WorkspaceRootNotExistsError);
103103

104-
export const isMissingWorkspaceRoot = (error: ProjectFaviconResolutionError): boolean =>
104+
const isMissingWorkspaceRoot = (error: ProjectFaviconResolutionError): boolean =>
105105
error.operation === "normalize-workspace" && isWorkspaceRootNotExistsError(error.cause);
106106

107107
export class ProjectFaviconResolver extends Context.Service<
@@ -302,7 +302,10 @@ export const make = Effect.gen(function* () {
302302
const faviconCache = yield* Cache.makeWith<string, string | null, ProjectFaviconResolutionError>(
303303
(key) => {
304304
const { cwd, faviconPath } = parseFaviconCacheKey(key);
305-
return resolvePathUncached(cwd, faviconPath);
305+
// Failures get a zero TTL, so a deleted folder is answered as "no favicon" to be cached.
306+
return resolvePathUncached(cwd, faviconPath).pipe(
307+
Effect.catchIf(isMissingWorkspaceRoot, () => Effect.succeed(null)),
308+
);
306309
},
307310
{
308311
capacity: FAVICON_CACHE_CAPACITY,

0 commit comments

Comments
 (0)