From 4504115781f56222ffa5f8d875a85fc5239d24fd Mon Sep 17 00:00:00 2001 From: "lvning.liu" Date: Sun, 22 Nov 2026 19:56:06 +0800 Subject: [PATCH 1/4] fix(server): filesystem browse lists symlinks pointing to directories --- .../src/workspace/WorkspaceEntries.test.ts | 47 +++++++++++++++++++ apps/server/src/workspace/WorkspaceEntries.ts | 33 ++++++++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceEntries.test.ts b/apps/server/src/workspace/WorkspaceEntries.test.ts index 446f231cff60..a61d4062b0c7 100644 --- a/apps/server/src/workspace/WorkspaceEntries.test.ts +++ b/apps/server/src/workspace/WorkspaceEntries.test.ts @@ -1165,5 +1165,52 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { }); }), ); + + it.effect("includes symlinks pointing to directories and skips file or broken symlinks", () => + Effect.gen(function* () { + const platform = yield* HostProcess.Platform; + if (platform === "win32") return; + const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const cwd = yield* makeTempDir({ prefix: "t3code-workspace-browse-symlink-" }); + const externalTarget = yield* makeTempDir({ + prefix: "t3code-workspace-browse-symlink-target-", + }); + yield* writeTextFile(cwd, "real-dir/readme.md", "hi"); + yield* writeTextFile(cwd, "plain.txt", "hi"); + yield* writeTextFile(externalTarget, "project/index.ts", "export {};"); + + yield* fileSystem.symlink(externalTarget, path.join(cwd, "personal")); + yield* fileSystem.symlink(path.join(cwd, "plain.txt"), path.join(cwd, "file-link")); + yield* fileSystem.symlink(path.join(cwd, "does-not-exist"), path.join(cwd, "broken-link")); + yield* fileSystem.symlink(externalTarget, path.join(cwd, ".hidden-link")); + + const cwdWithSeparator = yield* appendSeparator(cwd); + const directoryResult = yield* workspaceEntries.browse({ + partialPath: cwdWithSeparator, + }); + const prefixResult = yield* workspaceEntries.browse({ + partialPath: `${cwdWithSeparator}per`, + }); + const symlinkChildren = yield* workspaceEntries.browse({ + partialPath: yield* appendSeparator(path.join(cwd, "personal")), + }); + + expect(directoryResult.entries).toEqual([ + { name: ".hidden-link", fullPath: path.join(cwd, ".hidden-link") }, + { name: "personal", fullPath: path.join(cwd, "personal") }, + { name: "real-dir", fullPath: path.join(cwd, "real-dir") }, + ]); + expect(prefixResult).toEqual({ + parentPath: cwd, + entries: [{ name: "personal", fullPath: path.join(cwd, "personal") }], + }); + expect(symlinkChildren).toEqual({ + parentPath: path.join(cwd, "personal"), + entries: [{ name: "project", fullPath: path.join(cwd, "personal", "project") }], + }); + }), + ); }); }); diff --git a/apps/server/src/workspace/WorkspaceEntries.ts b/apps/server/src/workspace/WorkspaceEntries.ts index 0be532107876..360988098461 100644 --- a/apps/server/src/workspace/WorkspaceEntries.ts +++ b/apps/server/src/workspace/WorkspaceEntries.ts @@ -252,16 +252,35 @@ export const make = Effect.gen(function* () { const showHidden = endsWithSeparator || prefix.startsWith("."); const lowerPrefix = prefix.toLowerCase(); const entries: Array<{ readonly name: string; readonly fullPath: string }> = []; + const symlinkCandidates: Array<{ readonly name: string; readonly fullPath: string }> = []; for (const dirent of dirents) { if ( - dirent.isDirectory() && - dirent.name.toLowerCase().startsWith(lowerPrefix) && - (showHidden || !dirent.name.startsWith(".")) + !dirent.name.toLowerCase().startsWith(lowerPrefix) || + (!showHidden && dirent.name.startsWith(".")) ) { - entries.push({ - name: dirent.name, - fullPath: path.join(parentPath, dirent.name), - }); + continue; + } + const fullPath = path.join(parentPath, dirent.name); + if (dirent.isDirectory()) { + entries.push({ name: dirent.name, fullPath }); + } else if (dirent.isSymbolicLink()) { + symlinkCandidates.push({ name: dirent.name, fullPath }); + } + } + if (symlinkCandidates.length > 0) { + const resolvedSymlinks = yield* Effect.forEach( + symlinkCandidates, + (candidate) => + Effect.promise(() => + NodeFSP.stat(candidate.fullPath).then( + (stats) => (stats.isDirectory() ? candidate : null), + () => null, + ), + ), + { concurrency: 16 }, + ); + for (const candidate of resolvedSymlinks) { + if (candidate !== null) entries.push(candidate); } } From a932060a5f008dcf30348593061e39f25c65478c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 12:13:41 +0000 Subject: [PATCH 2/4] test(server): narrow directory-symlink browse test to the regression Co-Authored-By: Claude Opus 5.5 --- .../src/workspace/WorkspaceEntries.test.ts | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceEntries.test.ts b/apps/server/src/workspace/WorkspaceEntries.test.ts index a61d4062b0c7..2453f0c528f5 100644 --- a/apps/server/src/workspace/WorkspaceEntries.test.ts +++ b/apps/server/src/workspace/WorkspaceEntries.test.ts @@ -1166,10 +1166,9 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { }), ); - it.effect("includes symlinks pointing to directories and skips file or broken symlinks", () => + it.effect("lists symlinks to directories under their link path", () => Effect.gen(function* () { - const platform = yield* HostProcess.Platform; - if (platform === "win32") return; + if ((yield* HostProcess.Platform) === "win32") return; const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; @@ -1179,37 +1178,19 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { }); yield* writeTextFile(cwd, "real-dir/readme.md", "hi"); yield* writeTextFile(cwd, "plain.txt", "hi"); - yield* writeTextFile(externalTarget, "project/index.ts", "export {};"); yield* fileSystem.symlink(externalTarget, path.join(cwd, "personal")); yield* fileSystem.symlink(path.join(cwd, "plain.txt"), path.join(cwd, "file-link")); yield* fileSystem.symlink(path.join(cwd, "does-not-exist"), path.join(cwd, "broken-link")); - yield* fileSystem.symlink(externalTarget, path.join(cwd, ".hidden-link")); - const cwdWithSeparator = yield* appendSeparator(cwd); - const directoryResult = yield* workspaceEntries.browse({ - partialPath: cwdWithSeparator, - }); - const prefixResult = yield* workspaceEntries.browse({ - partialPath: `${cwdWithSeparator}per`, - }); - const symlinkChildren = yield* workspaceEntries.browse({ - partialPath: yield* appendSeparator(path.join(cwd, "personal")), + const result = yield* workspaceEntries.browse({ + partialPath: yield* appendSeparator(cwd), }); - expect(directoryResult.entries).toEqual([ - { name: ".hidden-link", fullPath: path.join(cwd, ".hidden-link") }, + expect(result.entries).toEqual([ { name: "personal", fullPath: path.join(cwd, "personal") }, { name: "real-dir", fullPath: path.join(cwd, "real-dir") }, ]); - expect(prefixResult).toEqual({ - parentPath: cwd, - entries: [{ name: "personal", fullPath: path.join(cwd, "personal") }], - }); - expect(symlinkChildren).toEqual({ - parentPath: path.join(cwd, "personal"), - entries: [{ name: "project", fullPath: path.join(cwd, "personal", "project") }], - }); }), ); }); From 5b77bda20f649cf4ac4bc91e04888c646513fba2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 12:22:41 +0000 Subject: [PATCH 3/4] fix(server): skip directory symlinks whose target does not resolve within a second A link to an unresponsive network share held up the whole browse listing. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/workspace/WorkspaceEntries.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/server/src/workspace/WorkspaceEntries.ts b/apps/server/src/workspace/WorkspaceEntries.ts index 360988098461..e9302950d677 100644 --- a/apps/server/src/workspace/WorkspaceEntries.ts +++ b/apps/server/src/workspace/WorkspaceEntries.ts @@ -6,6 +6,7 @@ import * as Context from "effect/Context"; import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as RcMap from "effect/RcMap"; import * as Schema from "effect/Schema"; @@ -154,6 +155,9 @@ const resolveBrowseTarget = Effect.fn("WorkspaceEntries.resolveBrowseTarget")(fu ); }); +// A link to an unresponsive network share must not hold up the local entries beside it. +const SYMLINK_TARGET_STAT_TIMEOUT = Duration.seconds(1); + /** @public */ export const make = Effect.gen(function* () { const path = yield* Path.Path; @@ -276,7 +280,7 @@ export const make = Effect.gen(function* () { (stats) => (stats.isDirectory() ? candidate : null), () => null, ), - ), + ).pipe(Effect.timeoutOption(SYMLINK_TARGET_STAT_TIMEOUT), Effect.map(Option.getOrNull)), { concurrency: 16 }, ); for (const candidate of resolvedSymlinks) { From 45f3c3697766a8586ac194cd89a21203d1d7f5a0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 12:29:50 +0000 Subject: [PATCH 4/4] fix(server): cap symlink target stats in flight so stalled links cannot fill the fs pool A timed-out stat keeps its libuv worker until the OS gives up; with no cap, stalled network links could occupy the whole pool and stall other fs work. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/workspace/WorkspaceEntries.ts | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceEntries.ts b/apps/server/src/workspace/WorkspaceEntries.ts index e9302950d677..738268f95558 100644 --- a/apps/server/src/workspace/WorkspaceEntries.ts +++ b/apps/server/src/workspace/WorkspaceEntries.ts @@ -157,12 +157,30 @@ const resolveBrowseTarget = Effect.fn("WorkspaceEntries.resolveBrowseTarget")(fu // A link to an unresponsive network share must not hold up the local entries beside it. const SYMLINK_TARGET_STAT_TIMEOUT = Duration.seconds(1); +// A timed-out stat cannot be cancelled and keeps a libuv worker (4 by default) busy, +// so cap target stats in flight to leave most of the pool to other fs work. +const MAX_PENDING_SYMLINK_TARGET_STATS = 2; /** @public */ export const make = Effect.gen(function* () { const path = yield* Path.Path; const workspacePaths = yield* WorkspacePaths.WorkspacePaths; const workspaceSearchIndexes = yield* WorkspaceSearchIndex.WorkspaceSearchIndexMap; + let pendingSymlinkTargetStats = 0; + const statSymlinkTarget = (candidate: { readonly name: string; readonly fullPath: string }) => { + if (pendingSymlinkTargetStats >= MAX_PENDING_SYMLINK_TARGET_STATS) { + return Promise.resolve(null); + } + pendingSymlinkTargetStats++; + return NodeFSP.stat(candidate.fullPath) + .then( + (stats) => (stats.isDirectory() ? candidate : null), + () => null, + ) + .finally(() => { + pendingSymlinkTargetStats--; + }); + }; const vcsProcess = yield* VcsProcess.VcsProcess; const normalizeWorkspaceRoot = Effect.fn("WorkspaceEntries.normalizeWorkspaceRoot")(function* ( @@ -275,13 +293,11 @@ export const make = Effect.gen(function* () { const resolvedSymlinks = yield* Effect.forEach( symlinkCandidates, (candidate) => - Effect.promise(() => - NodeFSP.stat(candidate.fullPath).then( - (stats) => (stats.isDirectory() ? candidate : null), - () => null, - ), - ).pipe(Effect.timeoutOption(SYMLINK_TARGET_STAT_TIMEOUT), Effect.map(Option.getOrNull)), - { concurrency: 16 }, + Effect.promise(() => statSymlinkTarget(candidate)).pipe( + Effect.timeoutOption(SYMLINK_TARGET_STAT_TIMEOUT), + Effect.map(Option.getOrNull), + ), + { concurrency: MAX_PENDING_SYMLINK_TARGET_STATS }, ); for (const candidate of resolvedSymlinks) { if (candidate !== null) entries.push(candidate);