Skip to content

Commit 4bd5bcf

Browse files
committed
fix(server): bound editor discovery during config loading
1 parent 9a0a071 commit 4bd5bcf

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎apps/server/src/server.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
7373

7474
import * as ServerConfig from "./config.ts";
7575
import { makeRoutesLayer } from "./server.ts";
76+
import { resolveAvailableEditorsForConfig } from "./ws.ts";
7677
import * as CheckpointDiffQuery from "./checkpointing/CheckpointDiffQuery.ts";
7778
import * as GitManager from "./git/GitManager.ts";
7879
import * as Keybindings from "./keybindings.ts";
@@ -3728,6 +3729,23 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
37283729
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
37293730
);
37303731

3732+
it.effect("does not block server config when editor discovery never resolves", () =>
3733+
Effect.gen(function* () {
3734+
const discoveryInterrupted = yield* Deferred.make<void>();
3735+
const responseFiber = yield* resolveAvailableEditorsForConfig(
3736+
Effect.never.pipe(
3737+
Effect.onInterrupt(() => Deferred.succeed(discoveryInterrupted, undefined)),
3738+
),
3739+
).pipe(Effect.forkChild);
3740+
3741+
yield* TestClock.adjust(Duration.seconds(5));
3742+
3743+
const availableEditors = yield* Fiber.join(responseFiber);
3744+
yield* Deferred.await(discoveryInterrupted);
3745+
assert.deepEqual(availableEditors, []);
3746+
}),
3747+
);
3748+
37313749
it.effect(
37323750
"rejects websocket rpc handshake when a session token is only provided via query string",
37333751
() =>

‎apps/server/src/ws.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ import * as RelayClient from "@t3tools/shared/relayClient";
118118
const isOrchestrationDispatchCommandError = Schema.is(OrchestrationDispatchCommandError);
119119

120120
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
121+
const EDITOR_DISCOVERY_TIMEOUT = Duration.seconds(5);
122+
123+
export const resolveAvailableEditorsForConfig = <A, E, R>(
124+
discovery: Effect.Effect<ReadonlyArray<A>, E, R>,
125+
) =>
126+
discovery.pipe(
127+
Effect.timeoutOption(EDITOR_DISCOVERY_TIMEOUT),
128+
Effect.map(Option.getOrElse(() => [])),
129+
);
121130

122131
function unexpectedCompatibilityError(error: never): never {
123132
throw new Error(`Unhandled compatibility error: ${String(error)}`);
@@ -1080,7 +1089,9 @@ const makeWsRpcLayer = (
10801089
keybindings: keybindingsConfig.keybindings,
10811090
issues: keybindingsConfig.issues,
10821091
providers,
1083-
availableEditors: yield* externalLauncher.resolveAvailableEditors(),
1092+
availableEditors: yield* resolveAvailableEditorsForConfig(
1093+
externalLauncher.resolveAvailableEditors(),
1094+
),
10841095
observability: {
10851096
logsDirectoryPath: config.logsDir,
10861097
localTracingEnabled: true,

0 commit comments

Comments
 (0)