@devries-cameron20 / t3code-1 / commits / fec71c5ab4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): return partial workspace index on timeout (#11500)

Michel Liao committed Oct 6, 2026 at 00:08 UTC fec71c5ab4fd860331fb15ce37c15edf6db1c236
2 files changed +89 -4
apps/server/src/workspace/WorkspaceSearchIndex.test.ts
+68
@@ -140,6 +140,74 @@ it.effect("preserves a full-index warmup timeout as a structured error", () =>
140 }),
141 );
142
143 +it.effect("returns partial path results when the initial scan times out", () =>
144 + Effect.scoped(
145 + Effect.gen(function* () {
146 + const mixedSearch = vi.fn(() => ({
147 + ok: true as const,
148 + value: {
149 + items: [
150 + {
151 + type: "directory" as const,
152 + item: { relativePath: "src", fileName: "src", fileCount: 1 },
153 + },
154 + { type: "file" as const, item: fileItem("src/index.ts") },
155 + ],
156 + scores: [],
157 + totalMatched: 2,
158 + totalFiles: 1,
159 + },
160 + }));
161 + let scanning = true;
162 + const finder = {
163 + destroy: vi.fn(),
164 + isScanning: vi.fn(() => scanning),
165 + waitForIndexReady: vi.fn(async () => ({ ok: true as const, value: false })),
166 + mixedSearch,
167 + } as unknown as FileFinder;
168 + vi.spyOn(FileFinder, "create").mockReturnValueOnce({ ok: true, value: finder });
169 +
170 + const searchIndex = yield* WorkspaceSearchIndex.make("/workspace/project", "paths");
171 + const list = yield* searchIndex.list();
172 + const search = yield* searchIndex.search("src", 10);
173 + scanning = true;
174 + mixedSearch.mockImplementationOnce(() => {
175 + scanning = false;
176 + return {
177 + ok: true as const,
178 + value: {
179 + items: [
180 + {
181 + type: "directory" as const,
182 + item: { relativePath: "src", fileName: "src", fileCount: 1 },
183 + },
184 + { type: "file" as const, item: fileItem("src/index.ts") },
185 + ],
186 + scores: [],
187 + totalMatched: 2,
188 + totalFiles: 1,
189 + },
190 + };
191 + });
192 + const searchCompletingDuringQuery = yield* searchIndex.search("src", 10);
193 + scanning = false;
194 + const completedSearch = yield* searchIndex.search("src", 10);
195 +
196 + expect(list).toEqual({
197 + entries: [
198 + { kind: "directory", path: "src" },
199 + { kind: "file", path: "src/index.ts" },
200 + ],
201 + truncated: true,
202 + });
203 + expect(search.truncated).toBe(true);
204 + expect(searchCompletingDuringQuery.truncated).toBe(true);
205 + expect(completedSearch.truncated).toBe(false);
206 + expect(mixedSearch).toHaveBeenCalledTimes(4);
207 + }),
208 + ),
209 +);
210 +
211 it.effect("preserves FileFinder destroy failures as structured defects", () =>
212 Effect.gen(function* () {
213 const cause = new Error("native destroy failed");
apps/server/src/workspace/WorkspaceSearchIndex.ts
+21 -4
@@ -365,6 +365,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
365 catch: (cause) => new WorkspaceSearchIndexDestroyFailed({ cwd, cause }),
366 }).pipe(Effect.orDie),
367 );
368 + let initialScanTimedOut = false;
369 yield* waitForIndexReady(
370 cwd,
371 finder,
@@ -374,8 +375,18 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
375 reason,
376 cause,
377 }),
378 + ).pipe(
379 + Effect.catchTag("WorkspaceSearchIndexScanTimedOut", (error) =>
380 + variant === "paths"
381 + ? Effect.sync(() => {
382 + initialScanTimedOut = true;
383 + })
384 + : Effect.fail(error),
385 + ),
386 );
387
388 + const hasIncompleteInitialScan = () => initialScanTimedOut && finder.isScanning();
389 +
390 const runSearch = Effect.fn("WorkspaceSearchIndex.runSearch")(function* <A>(
391 query: string,
392 pageSize: number,
@@ -436,6 +447,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
447
448 const list: WorkspaceSearchIndex["Service"]["list"] = Effect.fn("WorkspaceSearchIndex.list")(
449 function* () {
450 + const incompleteBeforeQuery = hasIncompleteInitialScan();
451 const result = yield* runSearch("", WORKSPACE_INDEX_PAGE_SIZE, "mixedSearch", () =>
452 finder.mixedSearch("", { pageSize: WORKSPACE_INDEX_PAGE_SIZE }),
453 );
@@ -446,7 +458,8 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
458 const entries = sortedEntries.slice(0, WORKSPACE_INDEX_MAX_ENTRIES);
459 return {
460 entries,
449 - truncated: mapped.truncated || entries.length < sortedEntries.length,
461 + truncated:
462 + incompleteBeforeQuery || mapped.truncated || entries.length < sortedEntries.length,
463 };
464 },
465 );
@@ -455,22 +468,26 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
468 "WorkspaceSearchIndex.search",
469 )(function* (query, limit, kind, imageOnly) {
470 const pageSize = imageOnly ? WORKSPACE_INDEX_PAGE_SIZE : Math.max(1, limit + 1);
471 + const incompleteBeforeQuery = hasIncompleteInitialScan();
472 if (kind === "file" || imageOnly) {
473 const result = yield* runSearch(query, pageSize, "fileSearch", () =>
474 finder.fileSearch(query, { pageSize }),
475 );
462 - return mapFileSearchResult(result, limit, imageOnly);
476 + const mapped = mapFileSearchResult(result, limit, imageOnly);
477 + return { ...mapped, truncated: incompleteBeforeQuery || mapped.truncated };
478 }
479 if (kind === "directory") {
480 const result = yield* runSearch(query, pageSize, "directorySearch", () =>
481 finder.directorySearch(query, { pageSize }),
482 );
468 - return mapDirectorySearchResult(result, limit);
483 + const mapped = mapDirectorySearchResult(result, limit);
484 + return { ...mapped, truncated: incompleteBeforeQuery || mapped.truncated };
485 }
486 const result = yield* runSearch(query, pageSize, "mixedSearch", () =>
487 finder.mixedSearch(query, { pageSize }),
488 );
473 - return mapMixedSearchResult(result, limit);
489 + const mapped = mapMixedSearchResult(result, limit);
490 + return { ...mapped, truncated: incompleteBeforeQuery || mapped.truncated };
491 });
492
493 const searchContents: WorkspaceSearchIndex["Service"]["searchContents"] = Effect.fn(