Repository navigation
fix(server): keep native workspace indexing off the event loop #11376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
yashranaway
wants to merge
10
commits into
pingdotgg:main
from
yashranaway:fix/isolate-workspace-search
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7e131b1
fix(server): isolate native workspace indexing from the event loop
yashranaway 1db36c6
fix(server): preserve active searches during index cleanup
yashranaway 394f707
fix(server): retain search workers after recoverable errors
yashranaway 33fb8ad
fix(server): retain isolated workspace search across runtime packagin…
yashranaway c5b9ac4
fix(server): launch search workers on supported Node runtimes
yashranaway bad2456
fix(server): retain public workspace search construction API
yashranaway 75adfc4
fix(server): retry bounded candidates for whole-word searches
yashranaway 182851b
refactor(server): consume workspace index service through its namespace
yashranaway c7e5f96
fix(server): preserve POSIX filenames in native search results
yashranaway bcd2407
fix(server): give queued searches a fresh active deadline
yashranaway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // @effect-diagnostics nodeBuiltinImport:off | ||
| // Native IPC tests use Node sockets to signal blocked and retired workers. | ||
| import * as NodeNet from "node:net"; | ||
| import * as Exit from "effect/Exit"; | ||
| import * as Schema from "effect/Schema"; | ||
| import { SearchRequest, SearchResponse } from "../src/workspace/workspaceSearchProtocol.ts"; | ||
| import { | ||
| WorkspaceSearchIndexRefreshFailed, | ||
| WorkspaceSearchIndexScanTimedOut, | ||
| WorkspaceSearchIndexSearchFailed, | ||
| } from "../src/workspace/WorkspaceSearchIndexService.ts"; | ||
|
|
||
| const decodeSearchRequest = Schema.decodeUnknownSync(SearchRequest); | ||
| const encodeSearchResponse = Schema.encodeSync(SearchResponse); | ||
|
|
||
| const directories = new Map<number, string>(); | ||
| const hold = (value: unknown) => { | ||
| const socket = NodeNet.connect(Number(process.env.T3_SEARCH_TEST_RECEIPT_PORT), "127.0.0.1", () => | ||
| socket.write("blocked"), | ||
| ); | ||
| socket.once("data", () => { | ||
| socket.end(); | ||
| process.send?.(encodeSearchResponse(Exit.succeed(value))); | ||
| }); | ||
| }; | ||
| const block = () => { | ||
| const socket = NodeNet.connect( | ||
| Number(process.env.T3_SEARCH_TEST_RECEIPT_PORT), | ||
| "127.0.0.1", | ||
| () => { | ||
| socket.write("blocked"); | ||
| // Model a synchronous FFI call which cannot service IPC or JS timers. | ||
| Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0); | ||
| }, | ||
| ); | ||
| }; | ||
| process.on("disconnect", () => process.exit(0)); | ||
| process.on("message", (message) => { | ||
| const { id, operation: input } = decodeSearchRequest(message); | ||
| if (input.method === "initialize") directories.set(id, input.cwd); | ||
| const cwd = directories.get(id) ?? ""; | ||
| if ( | ||
| input.method === "initialize" && | ||
| cwd === "hold-initialize" && | ||
| process.env.T3_SEARCH_TEST_HOLD_INITIALIZE === "1" | ||
| ) { | ||
| hold(null); | ||
| return; | ||
| } | ||
| if (input.method === "dispose") { | ||
| if (cwd === "block-dispose") { | ||
| block(); | ||
| return; | ||
| } | ||
| directories.delete(id); | ||
| process.send?.(encodeSearchResponse(Exit.succeed(null))); | ||
| return; | ||
| } | ||
| if (cwd === "block-initialize" || (input.method === "search" && input.query === "block")) { | ||
| block(); | ||
| return; | ||
| } | ||
| if (input.method === "search" && input.query === "crash") process.exit(1); | ||
| if (input.method === "search" && input.query === "search-error") { | ||
| process.send?.( | ||
| encodeSearchResponse( | ||
| Exit.fail( | ||
| new WorkspaceSearchIndexSearchFailed({ | ||
| cwd, | ||
| queryLength: input.query.length, | ||
| pageSize: input.limit + 1, | ||
| reason: "search rejected", | ||
| }), | ||
| ), | ||
| ), | ||
| ); | ||
| return; | ||
| } | ||
| if (input.method === "search" && input.query === "hold") { | ||
| hold({ | ||
| entries: [{ path: String(process.pid), kind: "file" }], | ||
| truncated: false, | ||
| }); | ||
| return; | ||
| } | ||
| if (input.method === "refresh") { | ||
| process.send?.( | ||
| encodeSearchResponse( | ||
| Exit.fail(new WorkspaceSearchIndexRefreshFailed({ cwd, reason: "scan failed" })), | ||
| ), | ||
| ); | ||
| return; | ||
| } | ||
| if (cwd === "scan-timeout") { | ||
| process.send?.( | ||
| encodeSearchResponse( | ||
| Exit.fail(new WorkspaceSearchIndexScanTimedOut({ cwd, timeout: "15 seconds" })), | ||
| ), | ||
| ); | ||
| return; | ||
| } | ||
| process.send?.( | ||
| encodeSearchResponse( | ||
| Exit.succeed( | ||
| input.method === "initialize" | ||
| ? null | ||
| : { | ||
| entries: [{ path: String(process.pid), kind: "file" }], | ||
| truncated: false, | ||
| }, | ||
| ), | ||
| ), | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import * as Effect from "effect/Effect"; | ||
| import { Command } from "effect/unstable/cli"; | ||
|
|
||
| // Load the native index only in the worker process, including standalone installs. | ||
| export const workspaceSearchCommand = Command.make("__workspace-search").pipe( | ||
| Command.unlisted, | ||
| Command.withHandler(() => | ||
| Effect.promise(async () => { | ||
| const { runWorkspaceSearchWorker } = await import("../workspaceSearchWorker.ts"); | ||
| runWorkspaceSearchWorker(); | ||
| }).pipe(Effect.andThen(Effect.never)), | ||
| ), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { runWorkspaceSearchWorker } from "./workspaceSearchWorker.ts"; | ||
|
|
||
| runWorkspaceSearchWorker(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.