fix(server): keep the file tree working without the native index #8402
Closedalejacre(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/8402/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/workspace/WorkspaceEntries.ts lines 417 to 417OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -284,3 +414,4 @@284414 WorkspaceSearchIndex.workspaceSearchIndexKey(normalizedCwd, "paths"),285415 ),286416 ),417+ Effect.catchTag("WorkspaceSearchIndexCreateFailed", recoverWithFilesystemList),
- apps/server/src/workspace/WorkspaceEntries.ts line 149OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -138,3 +144,6 @@138144 return path.resolve(expandHomePath(input.cwd, path), input.partialPath);139145 });140146147+function normalizeFallbackEntryPath(input: string): string {148+ return input149+ .replaceAll("\\", "/")
- apps/server/src/workspace/WorkspaceEntries.ts line 436Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -275,3 +388,16 @@275388 const list: WorkspaceEntries["Service"]["list"] = Effect.fn("WorkspaceEntries.list")(276389 function* (input) {277390 const normalizedCwd = yield* normalizeWorkspaceRoot(input.cwd);391+ // The fallback only covers an index that could not be created at all392+ // (for example the native binding failed to load on this host). Scan393+ // timeouts and search failures on a live index still surface so they394+ // are not silently masked by a slower listing.395+ const recoverWithFilesystemList = (396+ cause: WorkspaceSearchIndex.WorkspaceSearchIndexCreateFailed,397+ ) =>398+ Effect.gen(function* () {399+ yield* Effect.logWarning("Falling back to filesystem workspace listing", {400+ cwd: normalizedCwd,401+ cause,402+ });403+ return yield* listWorkspaceEntriesFromFilesystem(normalizedCwd, path, vcsProcess);apps/server/src/workspace/WorkspaceEntries.ts line 436Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -275,3 +388,16 @@275388 const list: WorkspaceEntries["Service"]["list"] = Effect.fn("WorkspaceEntries.list")(276389 function* (input) {277390 const normalizedCwd = yield* normalizeWorkspaceRoot(input.cwd);391+ // The fallback only covers an index that could not be created at all392+ // (for example the native binding failed to load on this host). Scan393+ // timeouts and search failures on a live index still surface so they394+ // are not silently masked by a slower listing.395+ const recoverWithFilesystemList = (396+ cause: WorkspaceSearchIndex.WorkspaceSearchIndexCreateFailed,397+ ) =>398+ Effect.gen(function* () {399+ yield* Effect.logWarning("Falling back to filesystem workspace listing", {400+ cwd: normalizedCwd,401+ cause,402+ });403+ return yield* listWorkspaceEntriesFromFilesystem(normalizedCwd, path, vcsProcess);
- apps/server/src/workspace/WorkspaceEntries.ts line 243Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -140,0 +190,21 @@190+ .run({191+ operation: "WorkspaceEntries.fallbackList.gitLsFiles",192+ command: "git",193+ cwd,194+ args: ["ls-files", "--cached", "--others", "--exclude-standard", "-z"],195+ allowNonZeroExit: true,196+ timeoutMs: 15_000,197+ maxOutputBytes: FALLBACK_LIST_GIT_OUTPUT_MAX_BYTES,198+ })199+ .pipe(Effect.orElseSucceed(() => null));200+201+ if (gitResult !== null && gitResult.exitCode === 0) {202+ const files = gitResult.stdout.split("\0").filter(Boolean);203+ if (gitResult.stdoutTruncated && !gitResult.stdout.endsWith("\0")) {204+ files.pop();205+ }206+ const exceededEntryLimit = files.length > FALLBACK_LIST_MAX_ENTRIES;207+ return buildFallbackListResult(208+ files.slice(0, FALLBACK_LIST_MAX_ENTRIES + 1),209+ gitResult.stdoutTruncated || exceededEntryLimit,210+ );@@ -140,0 +179,21 @@179+ );180+ return {181+ entries: sortedEntries.slice(0, FALLBACK_LIST_MAX_ENTRIES),182+ truncated: truncated || sortedEntries.length > FALLBACK_LIST_MAX_ENTRIES,183+ };184+}185+186+const listWorkspaceEntriesFromFilesystem = Effect.fn(187+ "WorkspaceEntries.listWorkspaceEntriesFromFilesystem",188+)(function* (cwd: string, path: Path.Path, vcsProcess: VcsProcess.VcsProcess["Service"]) {189+ const gitResult = yield* vcsProcess190+ .run({191+ operation: "WorkspaceEntries.fallbackList.gitLsFiles",192+ command: "git",193+ cwd,194+ args: ["ls-files", "--cached", "--others", "--exclude-standard", "-z"],195+ allowNonZeroExit: true,196+ timeoutMs: 15_000,197+ maxOutputBytes: FALLBACK_LIST_GIT_OUTPUT_MAX_BYTES,198+ })199+ .pipe(Effect.orElseSucceed(() => null));
- @@ -140,0 +174,21 @@174+ }175+ }176+177+ const sortedEntries = [...entryByPath.values()].toSorted((left, right) =>178+ left.path.localeCompare(right.path),179+ );180+ return {181+ entries: sortedEntries.slice(0, FALLBACK_LIST_MAX_ENTRIES),182+ truncated: truncated || sortedEntries.length > FALLBACK_LIST_MAX_ENTRIES,183+ };184+}185+186+const listWorkspaceEntriesFromFilesystem = Effect.fn(187+ "WorkspaceEntries.listWorkspaceEntriesFromFilesystem",188+)(function* (cwd: string, path: Path.Path, vcsProcess: VcsProcess.VcsProcess["Service"]) {189+ const gitResult = yield* vcsProcess190+ .run({191+ operation: "WorkspaceEntries.fallbackList.gitLsFiles",192+ command: "git",193+ cwd,194+ args: ["ls-files", "--cached", "--others", "--exclude-standard", "-z"],
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
e6a1db64-7990-4f92-8dba-562177e3bf4dYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.