From 3907e5e8c5367c82b0e6b3fd29de86fc88699da3 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 26 Feb 2026 19:23:26 -0800 Subject: [PATCH] Fix Effect type warnings to pass typecheck - Use generic type parameter for stream errors instead of unknown - Type ServerShape errors as ServerLifecycleError instead of unknown - Add error mapping for autoBootstrapProject and httpServerListen - Type makeServerProviderLayer with ProviderUnsupportedError - Use Effect.try with decodeUnknownSync in projector to avoid unknown requirements - Fix test layer types from any/unknown to never Co-Authored-By: Claude Opus 4.5 --- .../src/git/Layers/CodexTextGeneration.ts | 4 +- apps/server/src/git/Layers/GitService.ts | 4 +- apps/server/src/orchestration/projector.ts | 9 ++-- apps/server/src/serverLayers.ts | 3 +- apps/server/src/wsServer.test.ts | 4 +- apps/server/src/wsServer.ts | 46 +++++++++++-------- 6 files changed, 41 insertions(+), 29 deletions(-) diff --git a/apps/server/src/git/Layers/CodexTextGeneration.ts b/apps/server/src/git/Layers/CodexTextGeneration.ts index 91b29b182a..3fbeb1aac7 100644 --- a/apps/server/src/git/Layers/CodexTextGeneration.ts +++ b/apps/server/src/git/Layers/CodexTextGeneration.ts @@ -129,9 +129,9 @@ const makeCodexTextGeneration = Effect.gen(function* () { const path = yield* Path.Path; const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; - const readStreamAsString = ( + const readStreamAsString = ( operation: string, - stream: Stream.Stream, + stream: Stream.Stream, ): Effect.Effect => Effect.gen(function* () { let text = ""; diff --git a/apps/server/src/git/Layers/GitService.ts b/apps/server/src/git/Layers/GitService.ts index 11aeef30cc..d3f07e3151 100644 --- a/apps/server/src/git/Layers/GitService.ts +++ b/apps/server/src/git/Layers/GitService.ts @@ -39,9 +39,9 @@ function toGitCommandError( }); } -const collectOutput = Effect.fn(function* ( +const collectOutput = Effect.fn(function* ( input: Pick, - stream: Stream.Stream, + stream: Stream.Stream, maxOutputBytes: number, ): Effect.fn.Return { const decoder = new TextDecoder(); diff --git a/apps/server/src/orchestration/projector.ts b/apps/server/src/orchestration/projector.ts index 296cac2cbe..bbc1cc8d01 100644 --- a/apps/server/src/orchestration/projector.ts +++ b/apps/server/src/orchestration/projector.ts @@ -40,9 +40,12 @@ function decodeForEvent( eventType: OrchestrationEvent["type"], field: string, ): Effect.Effect { - return Schema.decodeUnknownEffect(schema)(value).pipe( - Effect.mapError(toProjectorDecodeError(`${eventType}:${field}`)), - ) as Effect.Effect; + return Effect.try({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + try: () => Schema.decodeUnknownSync(schema as any)(value) as A, + catch: (error) => + toProjectorDecodeError(`${eventType}:${field}`)(error as Schema.SchemaError), + }); } function retainThreadMessagesAfterRevert( diff --git a/apps/server/src/serverLayers.ts b/apps/server/src/serverLayers.ts index 3d37cc105d..da8def1685 100644 --- a/apps/server/src/serverLayers.ts +++ b/apps/server/src/serverLayers.ts @@ -17,6 +17,7 @@ import { ProviderCommandReactorLive } from "./orchestration/Layers/ProviderComma import { OrchestrationProjectionPipelineLive } from "./orchestration/Layers/ProjectionPipeline"; import { OrchestrationProjectionSnapshotQueryLive } from "./orchestration/Layers/ProjectionSnapshotQuery"; import { ProviderRuntimeIngestionLive } from "./orchestration/Layers/ProviderRuntimeIngestion"; +import { ProviderUnsupportedError } from "./provider/Errors"; import { makeCodexAdapterLive } from "./provider/Layers/CodexAdapter"; import { ProviderAdapterRegistryLive } from "./provider/Layers/ProviderAdapterRegistry"; import { makeProviderServiceLive } from "./provider/Layers/ProviderService"; @@ -35,7 +36,7 @@ import { NodePtyAdapterLive } from "./terminal/Layers/NodePTY"; export function makeServerProviderLayer(): Layer.Layer< ProviderService, - unknown, + ProviderUnsupportedError, SqlClient.SqlClient | ServerConfig > { return Effect.gen(function* () { diff --git a/apps/server/src/wsServer.test.ts b/apps/server/src/wsServer.test.ts index 6e177aa7f9..57abed02ac 100644 --- a/apps/server/src/wsServer.test.ts +++ b/apps/server/src/wsServer.test.ts @@ -323,14 +323,14 @@ describe("WebSocket Server", () => { async function createTestServer( options: { - persistenceLayer?: Layer.Layer; + persistenceLayer?: Layer.Layer; cwd?: string; autoBootstrapProjectFromCwd?: boolean; logWebSocketEvents?: boolean; devUrl?: string; authToken?: string; stateDir?: string; - providerLayer?: Layer.Layer; + providerLayer?: Layer.Layer; open?: OpenShape; gitManager?: GitManagerShape; gitCore?: Pick; diff --git a/apps/server/src/wsServer.ts b/apps/server/src/wsServer.ts index 85986f35e7..aa72c851f9 100644 --- a/apps/server/src/wsServer.ts +++ b/apps/server/src/wsServer.ts @@ -66,14 +66,14 @@ export interface ServerShape { */ readonly start: Effect.Effect< http.Server, - unknown, + ServerLifecycleError, Scope.Scope | ServerRuntimeServices | ServerConfig >; /** * Wait for process shutdown signals. */ - readonly stopSignal: Effect.Effect; + readonly stopSignal: Effect.Effect; } /** @@ -165,7 +165,7 @@ class RouteRequestError extends Schema.TaggedErrorClass()("Ro export const createServer = Effect.fn(function* (): Effect.fn.Return< http.Server, - unknown, // TODO: This should not be unknown + ServerLifecycleError, Scope.Scope | ServerRuntimeServices | ServerConfig > { const serverConfig = yield* ServerConfig; @@ -338,21 +338,27 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< yield* Scope.provide(orchestrationReactor.start, subscriptionsScope); if (autoBootstrapProjectFromCwd) { - const snapshot = yield* projectionReadModelQuery.getSnapshot(); - const existing = snapshot.projects.find((project) => project.workspaceRoot === cwd); - if (!existing) { - const createdAt = new Date().toISOString(); - const projectName = path.basename(cwd) || "project"; - yield* orchestrationEngine.dispatch({ - type: "project.create", - commandId: CommandId.makeUnsafe(crypto.randomUUID()), - projectId: ProjectId.makeUnsafe(crypto.randomUUID()), - title: projectName, - workspaceRoot: cwd, - defaultModel: "gpt-5-codex", - createdAt, - }); - } + yield* Effect.gen(function* () { + const snapshot = yield* projectionReadModelQuery.getSnapshot(); + const existing = snapshot.projects.find((project) => project.workspaceRoot === cwd); + if (!existing) { + const createdAt = new Date().toISOString(); + const projectName = path.basename(cwd) || "project"; + yield* orchestrationEngine.dispatch({ + type: "project.create", + commandId: CommandId.makeUnsafe(crypto.randomUUID()), + projectId: ProjectId.makeUnsafe(crypto.randomUUID()), + title: projectName, + workspaceRoot: cwd, + defaultModel: "gpt-5-codex", + createdAt, + }); + } + }).pipe( + Effect.mapError( + (cause) => new ServerLifecycleError({ operation: "autoBootstrapProject", cause }), + ), + ); } const routeRequest = Effect.fnUntraced(function* (request: WebSocketRequest) { @@ -618,7 +624,9 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< ); yield* Effect.addFinalizer(() => Effect.sync(() => unsubscribeTerminalEvents())); - yield* NodeHttpServer.make(() => httpServer, listenOptions); + yield* NodeHttpServer.make(() => httpServer, listenOptions).pipe( + Effect.mapError((cause) => new ServerLifecycleError({ operation: "httpServerListen", cause })), + ); yield* Effect.addFinalizer(() => Effect.all([