From de238add41566e67cd344db0cf54e7a54674b27e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 14 Jul 2026 16:04:57 +0000 Subject: [PATCH] refactor(server): use Duration for bootstrap timeout Co-authored-by: Julius Marminge --- apps/server/src/bootstrap.test.ts | 18 +++++++++++------- apps/server/src/bootstrap.ts | 7 ++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/server/src/bootstrap.test.ts b/apps/server/src/bootstrap.test.ts index 05155f32ec..affc06bc89 100644 --- a/apps/server/src/bootstrap.test.ts +++ b/apps/server/src/bootstrap.test.ts @@ -74,7 +74,9 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => { (fd) => Effect.sync(() => NodeFS.closeSync(fd)), ); - const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { timeoutMs: 100 }); + const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { + timeout: Duration.millis(100), + }); assertSome(payload, { mode: "desktop", }); @@ -100,7 +102,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => { openSyncInterceptor.failPath = `/proc/self/fd/${fd}`; try { const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { - timeoutMs: 100, + timeout: Duration.millis(100), }).pipe(Effect.provideService(HostProcessPlatform, "linux")); assertSome(payload, { mode: "desktop", @@ -125,7 +127,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => { openSyncInterceptor.errorCode = "EIO"; try { const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { - timeoutMs: 100, + timeout: Duration.millis(100), }).pipe(Effect.provideService(HostProcessPlatform, "linux"), Effect.flip); assert.instanceOf(error, BootstrapInputStreamOpenError); @@ -149,7 +151,9 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => { const fd = NodeFS.openSync("/dev/null", "r"); NodeFS.closeSync(fd); - const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { timeoutMs: 100 }); + const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { + timeout: Duration.millis(100), + }); assertNone(payload); }), ); @@ -164,7 +168,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => { fstatSyncInterceptor.failFd = fd; try { const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { - timeoutMs: 100, + timeout: Duration.millis(100), }).pipe(Effect.flip); assert.instanceOf(error, BootstrapFdStatError); @@ -188,7 +192,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => { (fd) => Effect.sync(() => NodeFS.closeSync(fd)), ); const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { - timeoutMs: 100, + timeout: Duration.millis(100), }).pipe(Effect.flip); assert.instanceOf(error, BootstrapEnvelopeDecodeError); @@ -227,7 +231,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => { ); const fiber = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { - timeoutMs: 100, + timeout: Duration.millis(100), }).pipe(Effect.forkScoped); yield* Effect.yieldNow; diff --git a/apps/server/src/bootstrap.ts b/apps/server/src/bootstrap.ts index 04dcf277e2..2275973214 100644 --- a/apps/server/src/bootstrap.ts +++ b/apps/server/src/bootstrap.ts @@ -4,6 +4,7 @@ import * as NodeNet from "node:net"; import * as NodeReadline from "node:readline"; import type * as NodeStream from "node:stream"; +import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; import * as Option from "effect/Option"; import * as Predicate from "effect/Predicate"; @@ -75,7 +76,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function schema: Schema.Codec, fd: number, options?: { - timeoutMs?: number; + readonly timeout?: Duration.Duration; }, ): Effect.fn.Return, BootstrapError> { const fdReady = yield* isFdReady(fd); @@ -83,7 +84,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function const stream = yield* makeBootstrapInputStream(fd); - const timeoutMs = options?.timeoutMs ?? 1000; + const timeout = options?.timeout ?? Duration.seconds(1); return yield* Effect.callback< Option.Option, @@ -142,7 +143,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function input.once("close", handleClose); return Effect.sync(cleanup); - }).pipe(Effect.timeoutOption(timeoutMs), Effect.map(Option.flatten)); + }).pipe(Effect.timeoutOption(timeout), Effect.map(Option.flatten)); }); const isUnavailableBootstrapFdError = Predicate.compose(