The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 09:30 UTC
fix(server): keep the live search index when a refresh times out (#23182)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 31, 2026 at 21:26 UTC
e03b6967a914d67bc4314e3f0e400037b9846695
2 files changed
+52
-5
apps/server/src/workspace/WorkspaceEntries.test.ts
+48
@@ -1,6 +1,7 @@
1
// @effect-diagnostics nodeBuiltinImport:off
2
import * as NodeFSP from "node:fs/promises";
3
import * as NodeServices from "@effect/platform-node/NodeServices";
4
+import { FileFinder } from "@ff-labs/fff-node";
5
import { it, afterEach, describe, expect } from "@effect/vitest";
6
import * as Effect from "effect/Effect";
7
import * as FileSystem from "effect/FileSystem";
@@ -673,6 +674,53 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
674
expect(match.lineContent.slice(range.start, range.end)).toBe("wörld");
675
}),
676
);
677
+
678
+ it.effect("keeps answering from the live index when a refresh outlasts the scan wait", () =>
679
+ Effect.gen(function* () {
680
+ const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-refresh-" });
681
+ yield* writeTextFile(cwd, "src/notes.ts", "const needle = 1;\n");
682
+ let scansOutlastWait = false;
683
+ let finders = 0;
684
+ let rescans = 0;
685
+ const createFinder = FileFinder.create.bind(FileFinder);
686
+ vi.spyOn(FileFinder, "create").mockImplementation((options) => {
687
+ const created = createFinder(options);
688
+ if (created.ok) {
689
+ const finder = created.value;
690
+ finders += 1;
691
+ const scanFiles = finder.scanFiles.bind(finder);
692
+ finder.scanFiles = () => {
693
+ rescans += 1;
694
+ return scanFiles();
695
+ };
696
+ const waitForIndexReady = finder.waitForIndexReady.bind(finder);
697
+ finder.waitForIndexReady = (timeoutMs) =>
698
+ scansOutlastWait
699
+ ? Promise.resolve({ ok: true, value: false })
700
+ : waitForIndexReady(timeoutMs);
701
+ }
702
+ return created;
703
+ });
704
+ const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
705
+ const searchNeedle = workspaceEntries.searchContents({
706
+ cwd,
707
+ query: "needle",
708
+ limit: 100,
709
+ caseSensitive: true,
710
+ wholeWord: false,
711
+ useRegex: false,
712
+ });
713
+ yield* searchNeedle;
714
+
715
+ scansOutlastWait = true;
716
+ yield* workspaceEntries.refresh(cwd);
717
+ const result = yield* searchNeedle;
718
+
719
+ expect(result.matches.map((match) => match.path)).toEqual(["src/notes.ts"]);
720
+ // The second search ran on the rescanned live finder, not a rebuild.
721
+ expect({ finders, rescans }).toEqual({ finders: 1, rescans: 1 });
722
+ }),
723
+ );
724
});
725
726
describe("browse", () => {
apps/server/src/workspace/WorkspaceSearchIndex.ts
+4
-5
@@ -117,10 +117,7 @@ export class WorkspaceSearchIndex extends Context.Service<
117
readonly searchContents: (
118
input: Omit<ProjectSearchContentsInput, "cwd">,
119
) => Effect.Effect<ProjectSearchContentsResult, WorkspaceSearchIndexSearchFailed>;
120
- readonly refresh: () => Effect.Effect<
121
- void,
122
- WorkspaceSearchIndexRefreshFailed | WorkspaceSearchIndexScanTimedOut
123
- >;
120
+ readonly refresh: () => Effect.Effect<void, WorkspaceSearchIndexRefreshFailed>;
121
}
122
>()("t3/workspace/WorkspaceSearchIndex") {}
123
@@ -419,6 +416,8 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
416
reason: result.error,
417
});
418
}
419
+ // A rescan that outlasts the wait keeps running, and the finder answers
420
+ // from its previous index until it finishes, so the index stays usable.
421
yield* waitForIndexReady(
422
cwd,
423
finder,
@@ -428,7 +427,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
427
reason,
428
cause,
429
}),
431
- );
430
+ ).pipe(Effect.catchTags({ WorkspaceSearchIndexScanTimedOut: () => Effect.void }));
431
});
432
433
const list: WorkspaceSearchIndex["Service"]["list"] = Effect.fn("WorkspaceSearchIndex.list")(