Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(server): bound editor discovery during config loading (#4291)

maria6e3b73884bf4
diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.ts
index 4a9e73062..a3b2e3715 100644
--- a/apps/server/src/server.test.ts
+++ b/apps/server/src/server.test.ts
@@ -73,6 +73,7 @@ const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
import * as ServerConfig from "./config.ts";
import { makeRoutesLayer } from "./server.ts";
+import { resolveAvailableEditorsForConfig } from "./ws.ts";
import * as CheckpointDiffQuery from "./checkpointing/CheckpointDiffQuery.ts";
import * as GitManager from "./git/GitManager.ts";
import * as Keybindings from "./keybindings.ts";
@@ -3763,6 +3764,23 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
+ it.effect("does not block server config when editor discovery never resolves", () =>
+ Effect.gen(function* () {
+ const discoveryInterrupted = yield* Deferred.make<void>();
+ const responseFiber = yield* resolveAvailableEditorsForConfig(
+ Effect.never.pipe(
+ Effect.onInterrupt(() => Deferred.succeed(discoveryInterrupted, undefined)),
+ ),
+ ).pipe(Effect.forkChild);
+
+ yield* TestClock.adjust(Duration.seconds(5));
+
+ const availableEditors = yield* Fiber.join(responseFiber);
+ yield* Deferred.await(discoveryInterrupted);
+ assert.deepEqual(availableEditors, []);
+ }),
+ );
+
it.effect(
"rejects websocket rpc handshake when a session token is only provided via query string",
() =>
diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts
index b8f4b0712..2a8be25a7 100644
--- a/apps/server/src/ws.ts
+++ b/apps/server/src/ws.ts
@@ -123,6 +123,15 @@ import * as RelayClient from "@t3tools/shared/relayClient";
const isOrchestrationDispatchCommandError = Schema.is(OrchestrationDispatchCommandError);
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
+const EDITOR_DISCOVERY_TIMEOUT = Duration.seconds(5);
+
+export const resolveAvailableEditorsForConfig = <A, E, R>(
+ discovery: Effect.Effect<ReadonlyArray<A>, E, R>,
+) =>
+ discovery.pipe(
+ Effect.timeoutOption(EDITOR_DISCOVERY_TIMEOUT),
+ Effect.map(Option.getOrElse(() => [])),
+ );
function unexpectedCompatibilityError(error: never): never {
throw new Error(`Unhandled compatibility error: ${String(error)}`);
@@ -1087,7 +1096,9 @@ const makeWsRpcLayer = (
keybindings: keybindingsConfig.keybindings,
issues: keybindingsConfig.issues,
providers,
- availableEditors: yield* externalLauncher.resolveAvailableEditors(),
+ availableEditors: yield* resolveAvailableEditorsForConfig(
+ externalLauncher.resolveAvailableEditors(),
+ ),
observability: {
logsDirectoryPath: config.logsDir,
localTracingEnabled: true,