The best way to control Claude Code, Codex and more from any computer or phone
fix(server): stop the relay client a crashed server left running (#36465)
Julius Marminge committed
Nov 13, 2026 at 17:19 UTC
913181c439732e0d50add8e920b95dd6afa3456f
5 files changed
+456
-16
apps/server/src/cloud/ManagedEndpointRuntime.test.ts
+47
@@ -30,6 +30,7 @@ import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
30
import * as ServerConfig from "../config.ts";
31
import * as ManagedEndpointRuntime from "./ManagedEndpointRuntime.ts";
32
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
33
+import * as RelayClientLedger from "./RelayClientLedger.ts";
34
35
const layerRelayClientAvailable = Layer.succeed(
36
RelayClient.RelayClient,
@@ -74,6 +75,7 @@ const runtimeDependencies = (
75
Layer.succeed(HttpClient.HttpClient, httpClient),
76
relayClientLayer,
77
secretStoreLayer,
78
+ RelayClientLedger.layerTest,
79
ServerConfig.layerTest(process.cwd(), { prefix: "t3-managed-endpoint-" }),
80
).pipe(Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)));
81
@@ -430,6 +432,51 @@ describe("CloudManagedEndpointRuntime", () => {
432
}),
433
);
434
435
+ it.effect("still owns a relay client when activation is interrupted while recording it", () =>
436
+ Effect.gen(function* () {
437
+ const fixture = yield* makeTransportSpawner();
438
+ const recording = yield* Deferred.make<void>();
439
+ const recorded = yield* Deferred.make<void>();
440
+ const ledger = Layer.succeed(
441
+ RelayClientLedger.RelayClientLedger,
442
+ RelayClientLedger.RelayClientLedger.of({
443
+ track: () =>
444
+ Deferred.succeed(recording, undefined).pipe(
445
+ Effect.andThen(Deferred.await(recorded)),
446
+ Effect.as(Effect.void),
447
+ ),
448
+ }),
449
+ );
450
+ const context = yield* Layer.build(
451
+ ManagedEndpointRuntime.layer.pipe(
452
+ Layer.provide(Layer.merge(runtimeDependencies(fixture.spawner), ledger)),
453
+ ),
454
+ );
455
+ const runtime = yield* Effect.service(
456
+ ManagedEndpointRuntime.CloudManagedEndpointRuntime,
457
+ ).pipe(Effect.provide(context));
458
+
459
+ const activation = yield* Effect.forkChild(runtime.applyConfig(tunnelConfig));
460
+ yield* Deferred.await(recording);
461
+ const interrupting = yield* Effect.forkChild(Fiber.interrupt(activation), {
462
+ startImmediately: true,
463
+ });
464
+ yield* Deferred.succeed(recorded, undefined);
465
+ yield* Fiber.join(interrupting);
466
+
467
+ // The handed-over connector is supervised: its exit starts a replacement.
468
+ expect(yield* Queue.take(fixture.started)).toBe(0);
469
+ yield* Deferred.succeed(fixture.exits[0]!, ChildProcessSpawner.ExitCode(1));
470
+ expect(yield* Queue.take(fixture.started)).toBe(1);
471
+
472
+ yield* runtime.applyConfig(null);
473
+ expect(fixture.killed).toEqual([800, 801]);
474
+ }).pipe(
475
+ Effect.provideService(HostProcess.Environment, {}),
476
+ Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} }))),
477
+ ),
478
+ );
479
+
480
it.effect("preserves an explicit transport choice despite repeated QUIC stalls", () =>
481
Effect.gen(function* () {
482
const fixture = yield* makeTransportSpawner({ transport: "quic" });
apps/server/src/cloud/ManagedEndpointRuntime.ts
+30
-16
@@ -28,6 +28,7 @@ import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
28
import * as ServerConfig from "../config.ts";
29
import * as ManagedLimits from "../policy/managedLimits.ts";
30
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
31
+import * as RelayClientLedger from "./RelayClientLedger.ts";
32
33
export type CloudManagedEndpointRuntimeStatus =
34
| {
@@ -210,6 +211,7 @@ const stopConnector = (connector: ActiveConnector | null) =>
211
export const make = Effect.gen(function* () {
212
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
213
const relayClient = yield* RelayClient.RelayClient;
214
+ const relayClientLedger = yield* RelayClientLedger.RelayClientLedger;
215
const secrets = yield* ServerSecretStore.ServerSecretStore;
216
const httpClient = HttpClient.withScope(yield* HttpClient.HttpClient);
217
// Without T3 Connect no connector ever runs, whoever asks for one.
@@ -755,6 +757,12 @@ export const make = Effect.gen(function* () {
757
758
const http2 = yield* Ref.get(http2Ref);
759
const connectorScope = yield* Scope.make("sequential");
760
+ // Added before the spawn so it runs after the spawner's finalizer has stopped the client.
761
+ let forgetRelayClient: Effect.Effect<void> = Effect.void;
762
+ yield* Scope.addFinalizer(
763
+ connectorScope,
764
+ Effect.suspend(() => forgetRelayClient),
765
+ );
766
const child = yield* spawner
767
.spawn(
768
ChildProcess.make(
@@ -819,22 +827,28 @@ export const make = Effect.gen(function* () {
827
}
828
829
if (!("status" in child)) {
822
- const connector = {
823
- child,
824
- executable,
825
- scope: connectorScope,
826
- configKey: nextConfigKey,
827
- config,
828
- startedAtMillis: yield* Clock.currentTimeMillis,
829
- registered: yield* Deferred.make<void>(),
830
- metricsAddress: yield* Deferred.make<string>(),
831
- protocol: yield* Ref.make<string | null>(null),
832
- } satisfies ActiveConnector;
833
- yield* Ref.set(activeRef, connector);
834
- yield* Effect.forkIn(observeConnectorOutput(connector), connectorScope);
835
- yield* Effect.forkIn(superviseConnector(connector), connectorScope);
836
- yield* Effect.forkIn(watchConnectorRegistration(connector), connectorScope);
837
- yield* Effect.forkIn(watchConnectorReadiness(connector), connectorScope);
830
+ // An interrupt before activeRef owns a supervised connector would leave its client open or unwatched.
831
+ yield* Effect.uninterruptibleMask((restore) =>
832
+ Effect.gen(function* () {
833
+ forgetRelayClient = yield* relayClientLedger.track(Number(child.pid));
834
+ const connector = {
835
+ child,
836
+ executable,
837
+ scope: connectorScope,
838
+ configKey: nextConfigKey,
839
+ config,
840
+ startedAtMillis: yield* Clock.currentTimeMillis,
841
+ registered: yield* Deferred.make<void>(),
842
+ metricsAddress: yield* Deferred.make<string>(),
843
+ protocol: yield* Ref.make<string | null>(null),
844
+ } satisfies ActiveConnector;
845
+ yield* Ref.set(activeRef, connector);
846
+ yield* Effect.forkIn(restore(observeConnectorOutput(connector)), connectorScope);
847
+ yield* Effect.forkIn(restore(superviseConnector(connector)), connectorScope);
848
+ yield* Effect.forkIn(restore(watchConnectorRegistration(connector)), connectorScope);
849
+ yield* Effect.forkIn(restore(watchConnectorReadiness(connector)), connectorScope);
850
+ }),
851
+ );
852
return {
853
status: "running",
854
providerKind: "cloudflare_tunnel",
apps/server/src/cloud/RelayClientLedger.test.ts
new
+112
@@ -0,0 +1,112 @@
1
+// @effect-diagnostics nodeBuiltinImport:off
2
+import * as NodeChildProcess from "node:child_process";
3
+
4
+import * as NodeServices from "@effect/platform-node/NodeServices";
5
+import { describe, expect, it } from "@effect/vitest";
6
+import * as HostProcess from "@t3tools/shared/HostProcess";
7
+import * as Deferred from "effect/Deferred";
8
+import * as Effect from "effect/Effect";
9
+import * as FileSystem from "effect/FileSystem";
10
+import * as Path from "effect/Path";
11
+
12
+import * as RelayClientLedger from "./RelayClientLedger.ts";
13
+
14
+const isAlive = (pid: number) => {
15
+ try {
16
+ process.kill(pid, 0);
17
+ return true;
18
+ } catch {
19
+ return false;
20
+ }
21
+};
22
+
23
+const spawnSleep = Effect.acquireRelease(
24
+ Effect.gen(function* () {
25
+ const child = NodeChildProcess.spawn("sleep", ["600"], { stdio: "ignore" });
26
+ const pid = child.pid;
27
+ if (pid === undefined) return yield* Effect.die("spawn failed");
28
+ const exited = yield* Deferred.make<void>();
29
+ child.once("exit", () => Deferred.doneUnsafe(exited, Effect.void));
30
+ return {
31
+ pid,
32
+ kill: Effect.sync(() => child.kill("SIGKILL")).pipe(Effect.andThen(Deferred.await(exited))),
33
+ };
34
+ }),
35
+ ({ kill }) => kill,
36
+);
37
+
38
+const entryNames = (stateDir: string) =>
39
+ Effect.gen(function* () {
40
+ const fs = yield* FileSystem.FileSystem;
41
+ const path = yield* Path.Path;
42
+ return yield* fs
43
+ .readDirectory(path.join(stateDir, "relay-clients"))
44
+ .pipe(Effect.orElseSucceed(() => []));
45
+ });
46
+
47
+const hostPlatform = HostProcess.Platform.defaultValue();
48
+// procps accepts the same `ps` flags as macOS, so Linux also covers the macOS path.
49
+const observedPlatforms: ReadonlyArray<NodeJS.Platform> =
50
+ hostPlatform === "linux" ? ["linux", "darwin"] : hostPlatform === "darwin" ? ["darwin"] : [];
51
+
52
+describe.each(observedPlatforms)("RelayClientLedger observing as %s", (platform) => {
53
+ const run = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
54
+ effect.pipe(
55
+ Effect.scoped,
56
+ Effect.provideService(HostProcess.Platform, platform),
57
+ Effect.provide(NodeServices.layer),
58
+ );
59
+
60
+ it.live("stops a client left by a dead server and keeps one whose server still runs", () =>
61
+ run(
62
+ Effect.gen(function* () {
63
+ const fs = yield* FileSystem.FileSystem;
64
+ const stateDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-relay-ledger-" });
65
+ const deadOwner = yield* spawnSleep;
66
+ const liveOwner = yield* spawnSleep;
67
+ const orphan = yield* spawnSleep;
68
+ const adopted = yield* spawnSleep;
69
+
70
+ const dead = yield* RelayClientLedger.make({ stateDir, ownerPid: deadOwner.pid });
71
+ yield* Effect.asVoid(dead.track(orphan.pid));
72
+ const live = yield* RelayClientLedger.make({ stateDir, ownerPid: liveOwner.pid });
73
+ yield* Effect.asVoid(live.track(adopted.pid));
74
+ yield* deadOwner.kill;
75
+
76
+ const restarted = yield* RelayClientLedger.make({ stateDir });
77
+ yield* restarted.reapOrphans;
78
+
79
+ expect(isAlive(orphan.pid)).toBe(false);
80
+ expect(isAlive(adopted.pid)).toBe(true);
81
+ expect(yield* entryNames(stateDir)).toEqual([`${adopted.pid}.json`]);
82
+ }),
83
+ ),
84
+ );
85
+
86
+ it.live("never signals a recycled pid and forgets the stale record", () =>
87
+ run(
88
+ Effect.gen(function* () {
89
+ const fs = yield* FileSystem.FileSystem;
90
+ const path = yield* Path.Path;
91
+ const stateDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-relay-ledger-" });
92
+ const deadOwner = yield* spawnSleep;
93
+ const unrelated = yield* spawnSleep;
94
+
95
+ const dead = yield* RelayClientLedger.make({ stateDir, ownerPid: deadOwner.pid });
96
+ yield* Effect.asVoid(dead.track(unrelated.pid));
97
+ yield* deadOwner.kill;
98
+ // The recorded client has exited and its pid now belongs to another process.
99
+ const entryPath = path.join(stateDir, "relay-clients", `${unrelated.pid}.json`);
100
+ const entry = JSON.parse(yield* fs.readFileString(entryPath));
101
+ entry.client.startTime = "0";
102
+ yield* fs.writeFileString(entryPath, JSON.stringify(entry));
103
+
104
+ const restarted = yield* RelayClientLedger.make({ stateDir });
105
+ yield* restarted.reapOrphans;
106
+
107
+ expect(isAlive(unrelated.pid)).toBe(true);
108
+ expect(yield* entryNames(stateDir)).toEqual([]);
109
+ }),
110
+ ),
111
+ );
112
+});
apps/server/src/cloud/RelayClientLedger.ts
new
+258
@@ -0,0 +1,258 @@
1
+import * as HostProcess from "@t3tools/shared/HostProcess";
2
+import { writeFileStringAtomically } from "@t3tools/shared/atomicWrite";
3
+import * as Context from "effect/Context";
4
+import * as Effect from "effect/Effect";
5
+import * as FileSystem from "effect/FileSystem";
6
+import * as Layer from "effect/Layer";
7
+import * as Option from "effect/Option";
8
+import * as Path from "effect/Path";
9
+import * as Schema from "effect/Schema";
10
+import * as ChildProcess from "effect/process/ChildProcess";
11
+import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
12
+
13
+const ProcessIdentity = Schema.Struct({
14
+ pid: Schema.Int,
15
+ startTime: Schema.String,
16
+ command: Schema.optional(Schema.String),
17
+});
18
+type ProcessIdentity = typeof ProcessIdentity.Type;
19
+
20
+const RelayClientEntry = Schema.Struct({
21
+ version: Schema.Literal(1),
22
+ client: ProcessIdentity,
23
+ // A process may rewrite its own argv, so the owner is identified by pid and start time.
24
+ owner: ProcessIdentity,
25
+});
26
+type RelayClientEntry = typeof RelayClientEntry.Type;
27
+const RelayClientEntryJson = Schema.fromJsonString(RelayClientEntry);
28
+const decodeEntry = Schema.decodeUnknownOption(RelayClientEntryJson);
29
+const encodeEntry = Schema.encodeEffect(RelayClientEntryJson);
30
+
31
+/** Remembers running relay clients so a server can stop the ones a crashed server left behind. */
32
+export class RelayClientLedger extends Context.Service<
33
+ RelayClientLedger,
34
+ {
35
+ /** Records a started relay client; the returned effect forgets it once it has stopped. */
36
+ readonly track: (pid: number) => Effect.Effect<Effect.Effect<void>>;
37
+ }
38
+>()("t3/cloud/RelayClientLedger") {}
39
+
40
+const ENTRY_DIRECTORY = "relay-clients";
41
+const ENTRY_FILE = /^\d+\.json$/;
42
+const STOP_POLL_INTERVAL = "50 millis";
43
+const STOP_POLL_ATTEMPTS = 40;
44
+
45
+interface ObservedProcess {
46
+ readonly startTime: string;
47
+ readonly command: string;
48
+ readonly zombie: boolean;
49
+}
50
+
51
+// ps lstart needs C locale and UTC for stable parsing.
52
+const DARWIN_PS_LINE = /^\s*(\d+)\s+(\S+)\s+(\w{3} \w{3} +\d{1,2} \d{2}:\d{2}:\d{2} \d{4})\s+(.*)$/;
53
+
54
+const processExists = (pid: number) => {
55
+ try {
56
+ process.kill(pid, 0);
57
+ return true;
58
+ } catch (cause) {
59
+ return (cause as NodeJS.ErrnoException | undefined)?.code !== "ESRCH";
60
+ }
61
+};
62
+
63
+const signal = (pid: number, name: NodeJS.Signals) => {
64
+ try {
65
+ process.kill(pid, name);
66
+ } catch {}
67
+};
68
+
69
+export const make = Effect.fn("RelayClientLedger.make")(function* (input: {
70
+ readonly stateDir: string;
71
+ readonly ownerPid?: number;
72
+}) {
73
+ const fs = yield* FileSystem.FileSystem;
74
+ const path = yield* Path.Path;
75
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
76
+ const platform = yield* HostProcess.Platform;
77
+ const directory = path.join(input.stateDir, ENTRY_DIRECTORY);
78
+ const recordable = platform === "linux" || platform === "darwin";
79
+
80
+ const observeLinux = Effect.fnUntraced(function* (pid: number) {
81
+ const stat = yield* fs.readFileString(`/proc/${pid}/stat`);
82
+ const fields = stat
83
+ .slice(stat.lastIndexOf(")") + 2)
84
+ .trim()
85
+ .split(/\s+/);
86
+ const startTime = fields[19];
87
+ if (startTime === undefined) return undefined;
88
+ const cmdline = yield* fs.readFileString(`/proc/${pid}/cmdline`);
89
+ return {
90
+ startTime,
91
+ command: cmdline.replace(/\0$/, "").replaceAll("\0", " "),
92
+ zombie: fields[0] === "Z",
93
+ } satisfies ObservedProcess;
94
+ });
95
+
96
+ const observeDarwin = (pid: number) =>
97
+ spawner
98
+ .string(
99
+ ChildProcess.make("/bin/ps", ["-ww", "-o", "pid=,stat=,lstart=,args=", "-p", String(pid)], {
100
+ env: { LC_ALL: "C", TZ: "UTC" },
101
+ extendEnv: true,
102
+ stdin: "ignore",
103
+ stderr: "ignore",
104
+ }),
105
+ )
106
+ .pipe(
107
+ Effect.timeout("5 seconds"),
108
+ Effect.map((output) => {
109
+ for (const line of output.split("\n")) {
110
+ const match = DARWIN_PS_LINE.exec(line);
111
+ if (match === null || Number(match[1]) !== pid) continue;
112
+ return {
113
+ zombie: match[2]!.startsWith("Z"),
114
+ startTime: match[3]!,
115
+ command: match[4]!.trimEnd(),
116
+ } satisfies ObservedProcess;
117
+ }
118
+ return undefined;
119
+ }),
120
+ );
121
+
122
+ const observe = (pid: number): Effect.Effect<ObservedProcess | undefined> => {
123
+ if (platform === "linux") return observeLinux(pid).pipe(Effect.orElseSucceed(() => undefined));
124
+ if (platform === "darwin")
125
+ return observeDarwin(pid).pipe(Effect.orElseSucceed(() => undefined));
126
+ return Effect.undefined;
127
+ };
128
+
129
+ // "unknown" means the pid exists but could not be read, so nothing may be concluded about it.
130
+ const compare = (identity: ProcessIdentity) =>
131
+ observe(identity.pid).pipe(
132
+ Effect.map((observed): "same" | "gone" | "unknown" => {
133
+ if (observed === undefined) return processExists(identity.pid) ? "unknown" : "gone";
134
+ return !observed.zombie &&
135
+ observed.startTime === identity.startTime &&
136
+ (identity.command === undefined || observed.command === identity.command)
137
+ ? "same"
138
+ : "gone";
139
+ }),
140
+ );
141
+
142
+ const identify = (pid: number) =>
143
+ observe(pid).pipe(
144
+ Effect.map((observed) =>
145
+ observed === undefined || observed.zombie
146
+ ? undefined
147
+ : { pid, startTime: observed.startTime, command: observed.command },
148
+ ),
149
+ );
150
+
151
+ const ownerProcess = yield* identify(input.ownerPid ?? process.pid);
152
+ const owner =
153
+ ownerProcess === undefined
154
+ ? undefined
155
+ : { pid: ownerProcess.pid, startTime: ownerProcess.startTime };
156
+
157
+ const track: RelayClientLedger["Service"]["track"] = Effect.fn("RelayClientLedger.track")(
158
+ function* (pid) {
159
+ if (!recordable) return Effect.void;
160
+ const client = yield* identify(pid);
161
+ if (owner === undefined || client?.command === undefined) {
162
+ yield* Effect.logWarning(
163
+ "Could not record the relay client; it will keep running if this server crashes",
164
+ { pid },
165
+ );
166
+ return Effect.void;
167
+ }
168
+ const entryPath = path.join(directory, `${pid}.json`);
169
+ yield* writeFileStringAtomically({
170
+ filePath: entryPath,
171
+ contents: yield* encodeEntry({ version: 1, client, owner }),
172
+ }).pipe(
173
+ Effect.provideService(FileSystem.FileSystem, fs),
174
+ Effect.provideService(Path.Path, path),
175
+ );
176
+ return fs
177
+ .remove(entryPath, { force: true })
178
+ .pipe(
179
+ Effect.catchCause((cause) =>
180
+ Effect.logWarning("Could not forget a stopped relay client", { cause }),
181
+ ),
182
+ );
183
+ },
184
+ Effect.catchCause((cause) =>
185
+ Effect.logWarning("Could not record the relay client", { cause }).pipe(
186
+ Effect.as(Effect.void),
187
+ ),
188
+ ),
189
+ );
190
+
191
+ // Signals only a process that still has the recorded pid, start time and command line,
192
+ // so a recycled pid is never touched. Returns whether the client is gone.
193
+ const stopOrphan = Effect.fn("RelayClientLedger.stopOrphan")(function* (client: ProcessIdentity) {
194
+ let state = yield* compare(client);
195
+ if (state !== "same") return state === "gone";
196
+ yield* Effect.logInfo("Stopping a relay client left by a previous T3 Code server", {
197
+ pid: client.pid,
198
+ });
199
+ for (const name of ["SIGTERM", "SIGKILL"] as const) {
200
+ signal(client.pid, name);
201
+ for (let attempt = 0; attempt < STOP_POLL_ATTEMPTS && state === "same"; attempt++) {
202
+ yield* Effect.sleep(STOP_POLL_INTERVAL);
203
+ state = yield* compare(client);
204
+ }
205
+ if (state !== "same") break;
206
+ }
207
+ return state === "gone";
208
+ });
209
+
210
+ const reapEntry = Effect.fn("RelayClientLedger.reapEntry")(
211
+ function* (entryPath: string) {
212
+ const entry = decodeEntry(yield* fs.readFileString(entryPath));
213
+ if (Option.isSome(entry)) {
214
+ if ((yield* compare(entry.value.owner)) !== "gone") return;
215
+ if (!(yield* stopOrphan(entry.value.client))) return;
216
+ }
217
+ yield* fs.remove(entryPath, { force: true });
218
+ },
219
+ (effect, entryPath) =>
220
+ effect.pipe(
221
+ Effect.catchCause((cause) =>
222
+ Effect.logWarning("Could not clean up a recorded relay client", { entryPath, cause }),
223
+ ),
224
+ ),
225
+ );
226
+
227
+ const reapOrphans = Effect.gen(function* () {
228
+ if (!recordable) return;
229
+ const names = yield* fs.readDirectory(directory).pipe(Effect.orElseSucceed(() => []));
230
+ yield* Effect.forEach(
231
+ names.filter((name) => ENTRY_FILE.test(name)),
232
+ (name) => reapEntry(path.join(directory, name)),
233
+ { concurrency: "unbounded", discard: true },
234
+ );
235
+ });
236
+
237
+ return { track, reapOrphans };
238
+});
239
+
240
+// Reaping finishes before any connector starts, so exactly one serves the tunnel.
241
+export const layer = (input: { readonly stateDir: string }) =>
242
+ Layer.effect(
243
+ RelayClientLedger,
244
+ Effect.gen(function* () {
245
+ const ledger = yield* make(input);
246
+ yield* ledger.reapOrphans;
247
+ return RelayClientLedger.of({ track: ledger.track });
248
+ }),
249
+ );
250
+
251
+export const layerTest = Layer.succeed(
252
+ RelayClientLedger,
253
+ RelayClientLedger.of({
254
+ track: Effect.fn("RelayClientLedger.track")(function () {
255
+ return Effect.succeed(Effect.void);
256
+ }),
257
+ }),
258
+);
apps/server/src/server.ts
+9
@@ -176,6 +176,7 @@ import * as ConnectReachability from "./cloud/ConnectReachability.ts";
176
import { pendingServiceUpdateExists } from "./cloud/updateHandoff.ts";
177
import * as RelayTracing from "./cloud/relayTracing.ts";
178
import * as CloudManagedEndpointRuntime from "./cloud/ManagedEndpointRuntime.ts";
179
+import * as RelayClientLedger from "./cloud/RelayClientLedger.ts";
180
import {
181
MANAGED_TUNNEL_FIRST_REGISTRATION_JITTER,
182
makeManagedTunnelRecovery,
@@ -553,6 +554,14 @@ const layerCloudManagedEndpointRuntime = Layer.mergeAll(
554
CloudManagedEndpointRuntime.layer.pipe(
555
Layer.provide(ServerSecretStore.layer),
556
Layer.provide(layerRelayClient),
557
+ Layer.provide(
558
+ Layer.unwrap(
559
+ Effect.gen(function* () {
560
+ const config = yield* ServerConfig.ServerConfig;
561
+ return RelayClientLedger.layer({ stateDir: config.stateDir });
562
+ }),
563
+ ),
564
+ ),
565
),
566
);
567