Skip to content

Commit 9b11fb0

Browse files
refactor(server): drop the Bun runtime branches
The server now ships as a Node single-executable and is never run under Bun, so the Bun pty adapter, BunHttpServer/BunServices selection, the bun:sqlite client, and the build-only external exemption that existed to keep those imports unresolved all go. One implementation per service. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent bce75fe commit 9b11fb0

11 files changed

Lines changed: 37 additions & 401 deletions

File tree

‎apps/server/package.json‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
},
2525
"dependencies": {
2626
"@anthropic-ai/claude-agent-sdk": "^0.3.260",
27-
"@effect/platform-bun": "catalog:",
2827
"@effect/platform-node": "catalog:",
2928
"@effect/platform-node-shared": "catalog:",
30-
"@effect/sql-sqlite-bun": "catalog:",
3129
"@ff-labs/fff-node": "0.9.4",
3230
"@opencode-ai/sdk": "^1.3.15",
3331
"effect": "catalog:",
@@ -45,7 +43,6 @@
4543
"@t3tools/ssh": "workspace:*",
4644
"@t3tools/tailscale": "workspace:*",
4745
"@t3tools/web": "workspace:*",
48-
"@types/bun": "1.3.14",
4946
"@types/node": "catalog:",
5047
"@types/yauzl": "^3.4.0",
5148
"effect-acp": "workspace:*",

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
33
import * as Effect from "effect/Effect";
44
import * as Schema from "effect/Schema";
55
import * as SqlClient from "effect/unstable/sql/SqlClient";
6-
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
76

87
import { PersistenceDecodeError, PersistenceSqlError, toPersistenceSqlError } from "./Errors.ts";
98

@@ -55,24 +54,6 @@ it("reads the condition through a wrapping driver error", () => {
5554
assert.equal(error.detail, "SQLITE(5) database is locked");
5655
});
5756

58-
it.each([{ errno: 1555, code: "SQLITE_CONSTRAINT_PRIMARYKEY" }, { errno: 1 }])(
59-
"names Bun SQLite condition $errno through the SQL error wrapper",
60-
(condition) => {
61-
const driver = Object.assign(new Error("bun-sql-private-sentinel"), {
62-
name: "SQLiteError",
63-
...condition,
64-
});
65-
const cause = new SqlError({ reason: classifySqliteError(driver) });
66-
const error = toPersistenceSqlError("AuthSessionRepository.create:query")(cause);
67-
68-
assert.equal(
69-
error.message,
70-
`SQL error in AuthSessionRepository.create:query: SQLITE(${condition.errno})`,
71-
);
72-
assert.equal(error.cause, cause);
73-
},
74-
);
75-
7657
it.each([
7758
new Error("unhelpful"),
7859
Object.assign(new Error("file not found"), { errno: -2, code: "ENOENT" }),

‎apps/server/src/persistence/Errors.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const isPersistenceDecodeError = Schema.is(PersistenceDecodeError);
7575

7676
/**
7777
* Read a SQLite condition through SQL error wrappers.
78-
* Use Node's fixed description or Bun's numeric code, never the driver message.
78+
* Use node:sqlite's fixed description, never the driver message.
7979
*/
8080
function sqliteCondition(cause: unknown): string | undefined {
8181
let value = cause;
@@ -88,15 +88,6 @@ function sqliteCondition(cause: unknown): string | undefined {
8888
) {
8989
return `SQLITE(${value.errcode}) ${value.errstr}`;
9090
}
91-
if (
92-
"name" in value &&
93-
value.name === "SQLiteError" &&
94-
"errno" in value &&
95-
typeof value.errno === "number" &&
96-
Number.isInteger(value.errno)
97-
) {
98-
return `SQLITE(${value.errno})`;
99-
}
10091
value = "cause" in value ? value.cause : undefined;
10192
}
10293
return undefined;

‎apps/server/src/persistence/Layers/Sqlite.ts‎

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,11 @@ import * as Layer from "effect/Layer";
33
import * as FileSystem from "effect/FileSystem";
44
import * as Path from "effect/Path";
55
import * as SqlClient from "effect/unstable/sql/SqlClient";
6-
import type { SqlError } from "effect/unstable/sql/SqlError";
6+
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
77

88
import { runMigrations } from "../Migrations.ts";
99
import { ServerConfig } from "../../config.ts";
1010

11-
type RuntimeSqliteLayerConfig = {
12-
readonly filename: string;
13-
readonly spanAttributes?: Record<string, unknown>;
14-
};
15-
16-
type Loader = {
17-
layer: (config: RuntimeSqliteLayerConfig) => Layer.Layer<SqlClient.SqlClient, SqlError>;
18-
};
19-
const defaultSqliteClientLoaders = {
20-
bun: () => import("@effect/sql-sqlite-bun/SqliteClient"),
21-
node: () => import("@t3tools/shared/nodeSqliteClient"),
22-
} satisfies Record<string, () => Promise<Loader>>;
23-
24-
const makeRuntimeSqliteLayer = Effect.fn("makeRuntimeSqliteLayer")(function* (
25-
config: RuntimeSqliteLayerConfig,
26-
) {
27-
const runtime = process.versions.bun !== undefined ? "bun" : "node";
28-
const loader = defaultSqliteClientLoaders[runtime];
29-
const clientModule = yield* Effect.promise<Loader>(loader);
30-
return clientModule.layer(config);
31-
}, Layer.unwrap);
32-
3311
const setup = Layer.effectDiscard(
3412
Effect.gen(function* () {
3513
const sql = yield* SqlClient.SqlClient;
@@ -50,7 +28,7 @@ export const makeSqlitePersistenceLive = Effect.fn("makeSqlitePersistenceLive")(
5028

5129
return Layer.provideMerge(
5230
setup,
53-
makeRuntimeSqliteLayer({
31+
NodeSqliteClient.layer({
5432
filename: dbPath,
5533
spanAttributes: {
5634
"db.name": path.basename(dbPath),
@@ -62,7 +40,7 @@ export const makeSqlitePersistenceLive = Effect.fn("makeSqlitePersistenceLive")(
6240

6341
export const SqlitePersistenceMemory = Layer.provideMerge(
6442
setup,
65-
makeRuntimeSqliteLayer({ filename: ":memory:" }),
43+
NodeSqliteClient.layer({ filename: ":memory:" }),
6644
);
6745

6846
export const layerConfig = Layer.unwrap(

‎apps/server/src/server.ts‎

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// @effect-diagnostics nodeBuiltinImport:off
2+
import * as NodeHttp from "node:http";
3+
4+
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
5+
import * as NodeServices from "@effect/platform-node/NodeServices";
16
import { EnvironmentHttpApi, ProviderDriverKind } from "@t3tools/contracts";
27
import * as Cause from "effect/Cause";
38
import * as Duration from "effect/Duration";
@@ -25,6 +30,7 @@ import { guardHttpResponseWriteErrors } from "./httpResponseErrorGuard.ts";
2530
import { fixPath } from "./os-jank.ts";
2631
import { websocketRpcRouteLayer } from "./ws.ts";
2732
import * as ExternalLauncher from "./process/externalLauncher.ts";
33+
import * as NodePtyAdapter from "./terminal/NodePtyAdapter.ts";
2834
import { pullRequestHttpApiLayer } from "./pullRequest/http.ts";
2935
import * as PullRequestProviderRegistry from "./pullRequest/PullRequestProviderRegistry.ts";
3036
import * as PullRequestService from "./pullRequest/PullRequestService.ts";
@@ -158,17 +164,7 @@ const ApplicationObservabilityLive = ObservabilityLive.pipe(
158164
Layer.provideMerge(ResourceAttributionLayerLive),
159165
);
160166

161-
const PtyAdapterLive = Layer.unwrap(
162-
Effect.gen(function* () {
163-
if (typeof Bun !== "undefined") {
164-
const BunPtyAdapter = yield* Effect.promise(() => import("./terminal/BunPtyAdapter.ts"));
165-
return BunPtyAdapter.layer;
166-
} else {
167-
const NodePtyAdapter = yield* Effect.promise(() => import("./terminal/NodePtyAdapter.ts"));
168-
return NodePtyAdapter.layer;
169-
}
170-
}),
171-
);
167+
const PtyAdapterLive = NodePtyAdapter.layer;
172168

173169
const ServerSettingsLayerLive = ServerSettings.layer.pipe(
174170
Layer.provide(ServerSecretStore.layer),
@@ -221,61 +217,22 @@ const RelayClientLive = Layer.unwrap(
221217
const HttpServerLive = Layer.unwrap(
222218
Effect.gen(function* () {
223219
const config = yield* ServerConfig.ServerConfig;
224-
if (typeof Bun !== "undefined") {
225-
const BunHttpServer = yield* Effect.promise(
226-
() => import("@effect/platform-bun/BunHttpServer"),
227-
);
228-
return BunHttpServer.layer({
229-
port: config.port,
230-
hostname: config.host ?? "127.0.0.1",
231-
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
232-
websocket: {
233-
// Negotiate permessage-deflate with clients that offer it; clients
234-
// that don't still get uncompressed frames on their connection. A
235-
// dedicated compressor keeps a per-connection sliding window
236-
// (context takeover) so the compression dictionary is shared across
237-
// server-to-client frames. Decompression uses the shared
238-
// decompressor: uWebSockets' dedicated decompressor path can abort
239-
// connections (close 1006) on valid DEFLATE input — see
240-
// https://github.com/uNetworking/uWebSockets.js/issues/633.
241-
perMessageDeflate: {
242-
compress: "dedicated",
243-
decompress: "shared",
244-
},
245-
},
246-
});
247-
} else {
248-
const [NodeHttpServer, NodeHttp] = yield* Effect.all([
249-
Effect.promise(() => import("@effect/platform-node/NodeHttpServer")),
250-
Effect.promise(() => import("node:http")),
251-
]);
252-
return NodeHttpServer.layer(() => guardHttpResponseWriteErrors(NodeHttp.createServer()), {
253-
host: config.host ?? "127.0.0.1",
254-
port: config.port,
255-
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
256-
// Negotiate permessage-deflate with clients that offer it; clients
257-
// that don't still get uncompressed frames on their connection.
258-
// Context takeover stays enabled (ws default) so the compression
259-
// window is shared across frames — that also makes small frames cheap
260-
// to compress, so no size threshold is set (ws only honors
261-
// `threshold` when context takeover is disabled).
262-
websocket: { perMessageDeflate: true },
263-
});
264-
}
220+
return NodeHttpServer.layer(() => guardHttpResponseWriteErrors(NodeHttp.createServer()), {
221+
host: config.host ?? "127.0.0.1",
222+
port: config.port,
223+
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
224+
// Negotiate permessage-deflate with clients that offer it; clients
225+
// that don't still get uncompressed frames on their connection.
226+
// Context takeover stays enabled (ws default) so the compression
227+
// window is shared across frames — that also makes small frames cheap
228+
// to compress, so no size threshold is set (ws only honors
229+
// `threshold` when context takeover is disabled).
230+
websocket: { perMessageDeflate: true },
231+
});
265232
}),
266233
);
267234

268-
const PlatformServicesLive = Layer.unwrap(
269-
Effect.gen(function* () {
270-
if (typeof Bun !== "undefined") {
271-
const { layer } = yield* Effect.promise(() => import("@effect/platform-bun/BunServices"));
272-
return layer;
273-
} else {
274-
const { layer } = yield* Effect.promise(() => import("@effect/platform-node/NodeServices"));
275-
return layer;
276-
}
277-
}),
278-
);
235+
const PlatformServicesLive = NodeServices.layer;
279236

280237
const ReactorLayerLive = Layer.empty.pipe(
281238
Layer.provideMerge(OrchestrationReactorLive),

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

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)