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
perf(server): connects no longer wait on editor and SSH target discovery (#14519)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com>
Alex Southwell committed
Nov 1, 2026 at 02:03 UTC
7115a0b7f200310181dee2835302e7a64017b75d
7 files changed
+422
-78
apps/server/src/environment/RemoteOpenTargets.ts
+8
-1
@@ -7,7 +7,10 @@ import * as Effect from "effect/Effect";
7
import * as Layer from "effect/Layer";
8
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
9
10
+import { makeStaleWhileRevalidate } from "./staleWhileRevalidate.ts";
11
+
12
const SSH_PORT = 22;
13
+const TARGETS_CACHE_TTL = "60 seconds";
14
15
export class RemoteOpenTargets extends Context.Service<
16
RemoteOpenTargets,
@@ -21,7 +24,7 @@ export const make = Effect.gen(function* () {
24
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
25
const net = yield* NetService.NetService;
26
24
- const resolveTargets = Effect.gen(function* () {
27
+ const discoverTargets = Effect.gen(function* () {
28
// Check both loopback families: sshd can be bound IPv6-only.
29
const sshdListening = yield* Effect.zipWith(
30
net.hasListenerOnHost(SSH_PORT, "127.0.0.1"),
@@ -78,6 +81,10 @@ export const make = Effect.gen(function* () {
81
return targets;
82
});
83
84
+ // Advertised on every client connect; probing sshd and tailscaled is slow
85
+ // on a loaded host, so serve the last result while it refreshes.
86
+ const resolveTargets = yield* makeStaleWhileRevalidate(discoverTargets, TARGETS_CACHE_TTL);
87
+
88
return RemoteOpenTargets.of({
89
resolveTargets: Effect.fn("RemoteOpenTargets.resolveTargets")(function () {
90
return resolveTargets;
apps/server/src/environment/staleWhileRevalidate.test.ts
new
+177
@@ -0,0 +1,177 @@
1
+import { assert, it } from "@effect/vitest";
2
+import * as Deferred from "effect/Deferred";
3
+import * as Effect from "effect/Effect";
4
+import * as Exit from "effect/Exit";
5
+import * as Fiber from "effect/Fiber";
6
+import * as Ref from "effect/Ref";
7
+import * as Scope from "effect/Scope";
8
+import * as TestClock from "effect/testing/TestClock";
9
+
10
+import { makeStaleWhileRevalidate } from "./staleWhileRevalidate.ts";
11
+
12
+it.effect("computes once, then answers from memory until the ttl lapses", () =>
13
+ Effect.gen(function* () {
14
+ const calls = yield* Ref.make(0);
15
+ const read = yield* makeStaleWhileRevalidate(
16
+ Ref.updateAndGet(calls, (count) => count + 1),
17
+ "60 seconds",
18
+ );
19
+
20
+ assert.equal(yield* read, 1);
21
+ yield* TestClock.adjust("59 seconds");
22
+ assert.equal(yield* read, 1);
23
+ assert.equal(yield* Ref.get(calls), 1);
24
+ }).pipe(Effect.scoped),
25
+);
26
+
27
+it.effect("serves the stale value while one background refresh replaces it", () =>
28
+ Effect.gen(function* () {
29
+ const calls = yield* Ref.make(0);
30
+ const release = yield* Deferred.make<void>();
31
+ const started = yield* Deferred.make<void>();
32
+ const refreshed = yield* Deferred.make<Fiber.Fiber<unknown, unknown>>();
33
+ const read = yield* makeStaleWhileRevalidate(
34
+ Effect.gen(function* () {
35
+ const call = yield* Ref.updateAndGet(calls, (count) => count + 1);
36
+ if (call > 1) {
37
+ yield* Deferred.succeed(started, undefined);
38
+ yield* Deferred.await(release);
39
+ yield* Deferred.succeed(refreshed, yield* Effect.fiber);
40
+ }
41
+ return call;
42
+ }),
43
+ "60 seconds",
44
+ );
45
+
46
+ assert.equal(yield* read, 1);
47
+ yield* TestClock.adjust("61 seconds");
48
+ // The refresh is blocked, yet callers are answered immediately and only
49
+ // one refresh starts however many callers arrive.
50
+ assert.equal(yield* read, 1);
51
+ assert.equal(yield* read, 1);
52
+ yield* Deferred.await(started);
53
+ assert.equal(yield* Ref.get(calls), 2);
54
+
55
+ yield* Deferred.succeed(release, undefined);
56
+ yield* Fiber.await(yield* Deferred.await(refreshed));
57
+ assert.equal(yield* read, 2);
58
+ }),
59
+);
60
+
61
+it.effect("shares one first scan that an interrupted caller does not cancel", () =>
62
+ Effect.gen(function* () {
63
+ const calls = yield* Ref.make(0);
64
+ const release = yield* Deferred.make<void>();
65
+ const started = yield* Deferred.make<void>();
66
+ const read = yield* makeStaleWhileRevalidate(
67
+ Ref.updateAndGet(calls, (count) => count + 1).pipe(
68
+ Effect.tap(() => Deferred.succeed(started, undefined)),
69
+ Effect.tap(() => Deferred.await(release)),
70
+ ),
71
+ "60 seconds",
72
+ );
73
+
74
+ // A connect that times out or disconnects mid-scan leaves the scan running.
75
+ const interrupted = yield* read.pipe(Effect.forkChild);
76
+ yield* Deferred.await(started);
77
+ yield* Fiber.interrupt(interrupted);
78
+
79
+ const next = yield* read.pipe(Effect.forkChild);
80
+ yield* Deferred.succeed(release, undefined);
81
+ assert.equal(yield* Fiber.join(next), 1);
82
+ assert.equal(yield* Ref.get(calls), 1);
83
+ }).pipe(Effect.scoped),
84
+);
85
+
86
+it.effect("starts over after a failed first scan", () =>
87
+ Effect.gen(function* () {
88
+ const calls = yield* Ref.make(0);
89
+ const read = yield* makeStaleWhileRevalidate(
90
+ Ref.updateAndGet(calls, (count) => count + 1).pipe(
91
+ Effect.filterOrElse(
92
+ (call) => call !== 1,
93
+ () => Effect.die("probe crashed"),
94
+ ),
95
+ ),
96
+ "60 seconds",
97
+ );
98
+
99
+ assert.isTrue(Exit.isFailure(yield* Effect.exit(read)));
100
+ assert.equal(yield* read, 2);
101
+ }).pipe(Effect.scoped),
102
+);
103
+
104
+it.effect("abandons a hung refresh so a later call can start another", () =>
105
+ Effect.gen(function* () {
106
+ const calls = yield* Ref.make(0);
107
+ const started = yield* Deferred.make<Fiber.Fiber<unknown, unknown>>();
108
+ const interrupted = yield* Deferred.make<void>();
109
+ const refreshed = yield* Deferred.make<Fiber.Fiber<unknown, unknown>>();
110
+ const read = yield* makeStaleWhileRevalidate(
111
+ Ref.updateAndGet(calls, (count) => count + 1).pipe(
112
+ Effect.flatMap((call) =>
113
+ call === 2
114
+ ? Effect.fiber.pipe(
115
+ Effect.flatMap((fiber) => Deferred.succeed(started, fiber)),
116
+ Effect.andThen(Effect.never),
117
+ Effect.onInterrupt(() => Deferred.succeed(interrupted, undefined)),
118
+ )
119
+ : Effect.succeed(call).pipe(
120
+ Effect.tap(() =>
121
+ call === 3
122
+ ? Effect.fiber.pipe(
123
+ Effect.flatMap((fiber) => Deferred.succeed(refreshed, fiber)),
124
+ )
125
+ : Effect.void,
126
+ ),
127
+ ),
128
+ ),
129
+ ),
130
+ "60 seconds",
131
+ );
132
+
133
+ assert.equal(yield* read, 1);
134
+ yield* TestClock.adjust("61 seconds");
135
+ assert.equal(yield* read, 1);
136
+ yield* Deferred.await(started);
137
+ assert.equal(yield* Ref.get(calls), 2);
138
+
139
+ // The hung refresh times out, releasing the claim for the next caller.
140
+ yield* TestClock.adjust("30 seconds");
141
+ yield* Deferred.await(interrupted);
142
+ yield* Fiber.await(yield* Deferred.await(started));
143
+ assert.equal(yield* read, 1);
144
+ yield* Fiber.await(yield* Deferred.await(refreshed));
145
+ assert.equal(yield* Ref.get(calls), 3);
146
+ assert.equal(yield* read, 3);
147
+ }).pipe(Effect.scoped),
148
+);
149
+
150
+it.effect("interrupts a background refresh when the owning scope closes", () =>
151
+ Effect.gen(function* () {
152
+ const interrupted = yield* Deferred.make<void>();
153
+ const started = yield* Deferred.make<void>();
154
+ const scope = yield* Scope.make();
155
+ const calls = yield* Ref.make(0);
156
+ const read = yield* makeStaleWhileRevalidate(
157
+ Ref.updateAndGet(calls, (count) => count + 1).pipe(
158
+ Effect.filterOrElse(
159
+ (call) => call === 1,
160
+ () =>
161
+ Deferred.succeed(started, undefined).pipe(
162
+ Effect.andThen(Effect.never),
163
+ Effect.onInterrupt(() => Deferred.succeed(interrupted, undefined)),
164
+ ),
165
+ ),
166
+ ),
167
+ "60 seconds",
168
+ ).pipe(Scope.provide(scope));
169
+
170
+ yield* read;
171
+ yield* TestClock.adjust("61 seconds");
172
+ yield* read;
173
+ yield* Deferred.await(started);
174
+ yield* Scope.close(scope, Exit.void);
175
+ yield* Deferred.await(interrupted);
176
+ }),
177
+);
apps/server/src/environment/staleWhileRevalidate.ts
new
+81
@@ -0,0 +1,81 @@
1
+import * as Clock from "effect/Clock";
2
+import * as Deferred from "effect/Deferred";
3
+import * as Duration from "effect/Duration";
4
+import * as Effect from "effect/Effect";
5
+import * as Exit from "effect/Exit";
6
+import * as Ref from "effect/Ref";
7
+
8
+const REFRESH_TIMEOUT = Duration.seconds(30);
9
+
10
+type Entry<A> =
11
+ | { readonly _tag: "Empty" }
12
+ | { readonly _tag: "Scanning"; readonly scan: Deferred.Deferred<A> }
13
+ | {
14
+ readonly _tag: "Ready";
15
+ readonly value: A;
16
+ readonly expiresAtNanos: bigint;
17
+ readonly refreshing: boolean;
18
+ };
19
+
20
+// Shared scans survive caller cancellation; monotonic TTL bounds cache age.
21
+// Warm reads return stale data while a scope-owned, bounded refresh runs.
22
+export const makeStaleWhileRevalidate = Effect.fn("StaleWhileRevalidate.make")(function* <A>(
23
+ discover: Effect.Effect<A>,
24
+ ttl: Duration.Input,
25
+) {
26
+ const ttlNanos = Duration.toNanosUnsafe(Duration.fromInputUnsafe(ttl));
27
+ const scope = yield* Effect.scope;
28
+ const state = yield* Ref.make<Entry<A>>({ _tag: "Empty" });
29
+
30
+ const settle = Effect.fn("StaleWhileRevalidate.settle")(function* (exit: Exit.Exit<A>) {
31
+ const now = yield* Clock.monotonicTimeNanos;
32
+ yield* Ref.update(state, (entry): Entry<A> =>
33
+ Exit.isSuccess(exit)
34
+ ? {
35
+ _tag: "Ready",
36
+ value: exit.value,
37
+ expiresAtNanos: now + ttlNanos,
38
+ refreshing: false,
39
+ }
40
+ : entry._tag === "Ready"
41
+ ? { ...entry, refreshing: false }
42
+ : { _tag: "Empty" },
43
+ );
44
+ });
45
+ const fork = (scan: Effect.Effect<unknown>) =>
46
+ scan.pipe(Effect.ignoreCause({ log: true }), Effect.interruptible, Effect.forkIn(scope));
47
+ const firstScan = (scan: Deferred.Deferred<A>) =>
48
+ fork(
49
+ discover.pipe(
50
+ Effect.onExit((exit) => settle(exit).pipe(Effect.andThen(Deferred.done(scan, exit)))),
51
+ ),
52
+ );
53
+ const refresh = fork(discover.pipe(Effect.onExit(settle), Effect.timeoutOption(REFRESH_TIMEOUT)));
54
+
55
+ return Effect.gen(function* () {
56
+ const now = yield* Clock.monotonicTimeNanos;
57
+ // Claiming a scan and starting it are one uninterruptible step: a caller
58
+ // interrupted between them would leave a claimed scan that never runs.
59
+ const result = yield* Ref.modify(
60
+ state,
61
+ (entry): readonly [readonly [Effect.Effect<unknown>, Effect.Effect<A>], Entry<A>] => {
62
+ switch (entry._tag) {
63
+ case "Empty": {
64
+ const scan = Deferred.makeUnsafe<A>();
65
+ return [[firstScan(scan), Deferred.await(scan)], { _tag: "Scanning", scan }];
66
+ }
67
+ case "Scanning":
68
+ return [[Effect.void, Deferred.await(entry.scan)], entry];
69
+ case "Ready":
70
+ return entry.refreshing || entry.expiresAtNanos > now
71
+ ? [[Effect.void, Effect.succeed(entry.value)], entry]
72
+ : [[refresh, Effect.succeed(entry.value)], { ...entry, refreshing: true }];
73
+ }
74
+ },
75
+ ).pipe(
76
+ Effect.flatMap(([start, result]) => Effect.as(start, result)),
77
+ Effect.uninterruptible,
78
+ );
79
+ return yield* result;
80
+ });
81
+});
apps/server/src/process/externalLauncher.test.ts
+74
@@ -5,6 +5,7 @@ import * as ConfigProvider from "effect/ConfigProvider";
5
import * as Deferred from "effect/Deferred";
6
import * as Cause from "effect/Cause";
7
import * as Effect from "effect/Effect";
8
+import * as TestClock from "effect/testing/TestClock";
9
import * as Exit from "effect/Exit";
10
import * as Fiber from "effect/Fiber";
11
import * as FileSystem from "effect/FileSystem";
@@ -714,6 +715,79 @@ it.effect.skipIf(windowsHost)("ignores unusable app bundles and keeps PATH launc
715
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
716
);
717
718
+it.effect(
719
+ "memoizes editor discovery and refreshes in the background after the cache window",
720
+ () => {
721
+ let statCalls = 0;
722
+ const rescanned = Deferred.makeUnsafe<void>();
723
+ let initialScanDone = false;
724
+ const fileInfo = { type: "File" } as FileSystem.File.Info;
725
+ const layerLauncher = ExternalLauncher.layer.pipe(
726
+ Layer.provide(
727
+ Layer.mergeAll(
728
+ FileSystem.layerNoop({
729
+ stat: () =>
730
+ Effect.sync(() => {
731
+ statCalls += 1;
732
+ return fileInfo;
733
+ }).pipe(
734
+ Effect.tap(() =>
735
+ initialScanDone ? Deferred.succeed(rescanned, undefined) : Effect.void,
736
+ ),
737
+ ),
738
+ }),
739
+ Path.layer,
740
+ Layer.succeed(
741
+ ChildProcessSpawner.ChildProcessSpawner,
742
+ ChildProcessSpawner.make(() => Effect.sync(() => makeMockDetachedHandle())),
743
+ ),
744
+ ),
745
+ ),
746
+ );
747
+
748
+ return Effect.gen(function* () {
749
+ const launcher = yield* ExternalLauncher.ExternalLauncher;
750
+
751
+ const first = yield* launcher.resolveAvailableEditors();
752
+ assert.equal(first.includes("vscode"), true);
753
+ const statCallsAfterFirstScan = statCalls;
754
+ initialScanDone = true;
755
+ assert.isAbove(statCallsAfterFirstScan, 0);
756
+
757
+ // Past the shared command-resolution cache TTL (30s) but within the
758
+ // discovery cache window: the memoized set is reused without any scan.
759
+ yield* TestClock.adjust("31 seconds");
760
+ const second = yield* launcher.resolveAvailableEditors();
761
+ assert.deepEqual([...second], [...first]);
762
+ assert.equal(statCalls, statCallsAfterFirstScan);
763
+
764
+ // Past the discovery cache window the next call still answers from the
765
+ // memoized set and rescans in the background.
766
+ yield* TestClock.adjust("30 seconds");
767
+ const third = yield* launcher.resolveAvailableEditors();
768
+ assert.deepEqual([...third], [...first]);
769
+ yield* Deferred.await(rescanned);
770
+ assert.isAbove(statCalls, statCallsAfterFirstScan);
771
+ }).pipe(
772
+ Effect.provide(
773
+ Layer.mergeAll(
774
+ layerLauncher,
775
+ Layer.succeed(HostProcess.Platform, "win32"),
776
+ ConfigProvider.layer(
777
+ ConfigProvider.fromEnv({
778
+ env: {
779
+ PATH: "C:\\t3-editor-discovery-cache-test",
780
+ PATHEXT: ".COM;.EXE;.BAT;.CMD",
781
+ },
782
+ }),
783
+ ),
784
+ TestClock.layer(),
785
+ ),
786
+ ),
787
+ );
788
+ },
789
+);
790
+
791
it.effect("keeps scanning after the caller is interrupted and shares that scan", () => {
792
const fileInfo = { type: "File" } as FileSystem.File.Info;
793
const release = Deferred.makeUnsafe<void>();
apps/server/src/process/externalLauncher.ts
+15
-67
@@ -19,24 +19,20 @@ import {
19
resolveSpawnCommand,
20
withPathDirectoryListings,
21
} from "@t3tools/shared/shell";
22
-import * as Clock from "effect/Clock";
22
import * as Config from "effect/Config";
23
import * as Context from "effect/Context";
25
-import * as Deferred from "effect/Deferred";
24
import * as Effect from "effect/Effect";
25
import * as Base64 from "effect/encoding/Base64";
28
-import * as Exit from "effect/Exit";
26
import * as FileSystem from "effect/FileSystem";
27
import * as Layer from "effect/Layer";
28
import * as Option from "effect/Option";
29
import * as Path from "effect/Path";
33
-import * as Ref from "effect/Ref";
30
import * as Schema from "effect/Schema";
35
-import * as Scope from "effect/Scope";
31
import * as Stream from "effect/Stream";
32
import * as ChildProcess from "effect/process/ChildProcess";
33
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
34
35
+import { makeStaleWhileRevalidate } from "../environment/staleWhileRevalidate.ts";
36
export {
37
ExternalLauncherError,
38
ExternalLauncherBrowserSpawnError,
@@ -447,13 +443,7 @@ const resolveFileManagerRevealKind = Effect.fn("externalLauncher.resolveFileMana
443
},
444
);
445
450
-// Shared scans must survive caller timeouts/disconnects; monotonic expiry prevents clock rollback extending stale entries.
451
-const EDITOR_DISCOVERY_CACHE_TTL_NANOS = 60_000_000_000n;
452
-
453
-interface EditorDiscoveryCacheEntry {
454
- readonly scan: Deferred.Deferred<ReadonlyArray<EditorId>>;
455
- readonly expiresAtNanos: bigint | undefined;
456
-}
446
+const EDITOR_DISCOVERY_CACHE_TTL = "60 seconds";
447
448
export class ExternalLauncher extends Context.Service<
449
ExternalLauncher,
@@ -817,69 +807,27 @@ export const make = Effect.gen(function* () {
807
Effect.provideService(Path.Path, path),
808
);
809
820
- const scope = yield* Scope.Scope;
821
- const editorDiscoveryCache = yield* Ref.make<Option.Option<EditorDiscoveryCacheEntry>>(
822
- Option.none(),
823
- );
824
- const runEditorDiscovery = (scan: Deferred.Deferred<ReadonlyArray<EditorId>>) =>
810
+ const cachedAvailableEditors = yield* makeStaleWhileRevalidate(
811
provideCommandResolutionServices(resolveAvailableEditors()).pipe(
812
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
827
- Effect.onExit((exit) =>
828
- Effect.gen(function* () {
829
- const expiresAtNanos =
830
- (yield* Clock.monotonicTimeNanos) + EDITOR_DISCOVERY_CACHE_TTL_NANOS;
831
- yield* Ref.update(editorDiscoveryCache, (current) =>
832
- Option.isNone(current) || current.value.scan !== scan
833
- ? current
834
- : Exit.isSuccess(exit)
835
- ? Option.some({ scan, expiresAtNanos })
836
- : Option.none(),
837
- );
838
- yield* Deferred.done(scan, exit);
839
- }),
840
- ),
841
- Effect.interruptible,
842
- Effect.forkIn(scope),
843
- );
844
- // Claim and start atomically; interruption between them would leave an entry waiting on no scan.
845
- const acquireEditorDiscovery = Effect.gen(function* () {
846
- const nowNanos = yield* Clock.monotonicTimeNanos;
847
- const [scan, isNewScan] = yield* Ref.modify(
848
- editorDiscoveryCache,
849
- (
850
- current,
851
- ): [
852
- [EditorDiscoveryCacheEntry["scan"], boolean],
853
- Option.Option<EditorDiscoveryCacheEntry>,
854
- ] => {
855
- if (
856
- Option.isSome(current) &&
857
- (current.value.expiresAtNanos === undefined || current.value.expiresAtNanos > nowNanos)
858
- ) {
859
- return [[current.value.scan, false], current];
860
- }
861
- const scan = Deferred.makeUnsafe<ReadonlyArray<EditorId>>();
862
- return [[scan, true], Option.some({ scan, expiresAtNanos: undefined })];
863
- },
864
- );
865
- if (isNewScan) {
866
- yield* runEditorDiscovery(scan);
867
- }
868
- return scan;
869
- }).pipe(Effect.uninterruptible);
870
- const cachedAvailableEditors = Effect.flatMap(acquireEditorDiscovery, Deferred.await);
813
+ ),
814
+ EDITOR_DISCOVERY_CACHE_TTL,
815
+ );
816
+ const cachedFileManagerRevealKind = yield* makeStaleWhileRevalidate(
817
+ provideCommandResolutionServices(resolveFileManagerRevealKind()).pipe(
818
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
819
+ ),
820
+ EDITOR_DISCOVERY_CACHE_TTL,
821
+ );
822
823
// Forwarders retain the underlying launcher and discovery spans.
824
return ExternalLauncher.of({
825
resolveAvailableEditors: Effect.fnUntraced(function* () {
826
return yield* cachedAvailableEditors;
827
}),
877
- resolveFileManagerRevealKind: Effect.fnUntraced(
878
- function* () {
879
- return yield* provideCommandResolutionServices(resolveFileManagerRevealKind());
880
- },
881
- Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
882
- ),
828
+ resolveFileManagerRevealKind: Effect.fnUntraced(function* () {
829
+ return yield* cachedFileManagerRevealKind;
830
+ }),
831
launchBrowser: Effect.fnUntraced(
832
function* (target) {
833
return yield* launchBrowser(target);
apps/server/src/ws.test.ts
+33
@@ -123,6 +123,7 @@ import * as ProjectEnrichment from "./project/ProjectEnrichmentService.ts";
123
import * as ProjectService from "./project/ProjectService.ts";
124
import {
125
layerWsRpc,
126
+ resolveOpenDiscoveryForConfig,
127
subscribeOrchestrationV2Shell,
128
subscribeOrchestrationV2Thread,
129
WS_RPC_SERVER_OPTIONS,
@@ -188,6 +189,38 @@ it.effect("resends a file manager reveal kind that missed the snapshot", () =>
189
}),
190
);
191
192
+it.effect("runs editor, remote open target and direct endpoint discovery side by side", () =>
193
+ Effect.gen(function* () {
194
+ // Each discovery finishes only once the other two have started, so a
195
+ // config that ran them one after another would never resolve.
196
+ const editorsStarted = yield* Deferred.make<void>();
197
+ const targetsStarted = yield* Deferred.make<void>();
198
+ const endpointsStarted = yield* Deferred.make<void>();
199
+ const startThenAwait = <A>(started: Deferred.Deferred<void>, value: A) =>
200
+ Deferred.succeed(started, undefined).pipe(
201
+ Effect.andThen(
202
+ Effect.forEach([editorsStarted, targetsStarted, endpointsStarted], Deferred.await),
203
+ ),
204
+ Effect.as(value),
205
+ );
206
+
207
+ const discovery = yield* resolveOpenDiscoveryForConfig({
208
+ editors: startThenAwait(editorsStarted, ["file-manager" as const]),
209
+ fileManagerRevealKind: Effect.succeed("finder" as const),
210
+ remoteOpenTargets: startThenAwait(targetsStarted, []),
211
+ directEndpoints: startThenAwait(endpointsStarted, []),
212
+ });
213
+
214
+ assert.deepEqual(discovery, {
215
+ availableEditors: ["file-manager"],
216
+ shellRevealInFileManager: true,
217
+ shellRevealInFileManagerKind: "finder",
218
+ remoteOpenTargets: [],
219
+ directEndpoints: [],
220
+ });
221
+ }),
222
+);
223
+
224
const ReplayTestLayer = OrchestrationEventStore.layer.pipe(
225
Layer.provideMerge(SqlitePersistence.layerMemory),
226
);
apps/server/src/ws.ts
+34
-10
@@ -324,7 +324,8 @@ export const withLateEditorConfig = <E, R>(
324
editors.join() !== config.availableEditors.join() ||
325
(editors.includes("file-manager") && config.shellRevealInFileManagerKind === undefined),
326
),
327
- // Leave the unshared reveal probe unbounded so timeouts cannot cancel every attempt on slow hosts.
327
+ // Unbounded, unlike the snapshot: this exists to deliver a probe that
328
+ // outlasts the snapshot's timeout.
329
Stream.mapEffect((editors) =>
330
resolveEditorConfig(editors, launcher.resolveFileManagerRevealKind()),
331
),
@@ -366,6 +367,31 @@ export const withLateEditorConfig = <E, R>(
367
);
368
};
369
370
+// Discoveries run side by side so the slowest one, not their sum, bounds the
371
+// server config snapshot. Each degrades on timeout rather than failing it.
372
+export const resolveOpenDiscoveryForConfig = <T, D, E1, R1, E2, R2, E3, R3, E4, R4>(discovery: {
373
+ readonly editors: Effect.Effect<ReadonlyArray<EditorId>, E1, R1>;
374
+ readonly fileManagerRevealKind: Effect.Effect<FileManagerRevealKind | undefined, E2, R2>;
375
+ readonly remoteOpenTargets: Effect.Effect<ReadonlyArray<T>, E3, R3>;
376
+ readonly directEndpoints: Effect.Effect<ReadonlyArray<D>, E4, R4>;
377
+}) =>
378
+ Effect.all(
379
+ {
380
+ editorConfig: resolveAvailableEditorsForConfig(discovery.editors).pipe(
381
+ Effect.flatMap((availableEditors) =>
382
+ resolveEditorConfig(
383
+ availableEditors,
384
+ resolveFileManagerRevealKindForConfig(discovery.fileManagerRevealKind),
385
+ ),
386
+ ),
387
+ ),
388
+ // Same discovery-with-timeout treatment as editors: a slow probe must
389
+ // not stall server.getConfig, so it degrades to an empty list.
390
+ remoteOpenTargets: resolveAvailableEditorsForConfig(discovery.remoteOpenTargets),
391
+ directEndpoints: resolveAvailableEditorsForConfig(discovery.directEndpoints),
392
+ },
393
+ { concurrency: "unbounded" },
394
+ ).pipe(Effect.map(({ editorConfig, ...endpoints }) => ({ ...editorConfig, ...endpoints })));
395
function withoutWorkspaceSnapshots(providers: ReadonlyArray<ServerProvider>): ServerProvider[] {
396
return providers.map(({ workspaceSnapshots: _workspaceSnapshots, ...provider }) => provider);
397
}
@@ -1744,10 +1770,12 @@ export const layerWsRpc = (
1770
const auth = yield* serverAuth.getDescriptor();
1771
const scratchWorkspaceRoot = yield* managedFolders.scratchRoot;
1772
const lastEventLoopStall = yield* eventLoopMonitor.latestNoticeableStall;
1747
- const editorConfig = yield* resolveEditorConfig(
1748
- yield* resolveAvailableEditorsForConfig(externalLauncher.resolveAvailableEditors()),
1749
- resolveFileManagerRevealKindForConfig(externalLauncher.resolveFileManagerRevealKind()),
1750
- );
1773
+ const discovery = yield* resolveOpenDiscoveryForConfig({
1774
+ editors: externalLauncher.resolveAvailableEditors(),
1775
+ fileManagerRevealKind: externalLauncher.resolveFileManagerRevealKind(),
1776
+ remoteOpenTargets: remoteOpenTargets.resolveTargets(),
1777
+ directEndpoints: directEndpoints.resolve(),
1778
+ });
1779
1780
return {
1781
environment,
@@ -1757,11 +1785,7 @@ export const layerWsRpc = (
1785
keybindings: keybindingsConfig.keybindings,
1786
issues: keybindingsConfig.issues,
1787
providers,
1760
- ...editorConfig,
1761
- remoteOpenTargets: yield* resolveAvailableEditorsForConfig(
1762
- remoteOpenTargets.resolveTargets(),
1763
- ),
1764
- directEndpoints: yield* resolveAvailableEditorsForConfig(directEndpoints.resolve()),
1788
+ ...discovery,
1789
observability: {
1790
logsDirectoryPath: config.logsDir,
1791
localTracingEnabled: true,