Skip to content

Commit b26bc7d

Browse files
perf(server): keep managed token helper imports lean
1 parent df7e270 commit b26bc7d

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎apps/server/src/provider/CodexManagedTokenBroker.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as NodeNet from "node:net";
44
import * as NodeOS from "node:os";
55
import * as NodePath from "node:path";
66
import * as NodeCrypto from "node:crypto";
7+
import { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts";
78
import * as HostProcess from "@t3tools/shared/HostProcess";
89
import * as Context from "effect/Context";
910
import * as Effect from "effect/Effect";
@@ -112,9 +113,19 @@ const acquireListener = Effect.gen(function* () {
112113
const sockets = new Set<NodeNet.Socket>();
113114
let closing = false;
114115
let admitted = 0;
115-
const decode = Schema.decodeUnknownEffect(Schema.fromJsonString(Protocol.Request), {
116-
onExcessProperty: "error",
117-
});
116+
// Keep branded validation here so the helper need not load the contracts graph.
117+
const decode = Schema.decodeUnknownEffect(
118+
Schema.fromJsonString(
119+
Schema.Struct({
120+
...Protocol.Request.fields,
121+
instanceId: ProviderInstanceId,
122+
environmentId: EnvironmentId,
123+
}),
124+
),
125+
{
126+
onExcessProperty: "error",
127+
},
128+
);
118129
const server = NodeNet.createServer((socket) => {
119130
socket.on("error", () => {});
120131
if (closing || sockets.size >= MAX_CONNECTIONS) {

‎apps/server/src/provider/CodexManagedTokenProtocol.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
// @effect-diagnostics nodeBuiltinImport:off - Private local IPC framing, shared by server and lean CLI.
22
import type * as NodeNet from "node:net";
3-
import { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts";
43
import * as Effect from "effect/Effect";
54
import * as Schema from "effect/Schema";
65

76
export const Request = Schema.Struct({
87
version: Schema.Literal(1),
9-
instanceId: ProviderInstanceId,
10-
environmentId: EnvironmentId,
8+
instanceId: Schema.NonEmptyString,
9+
environmentId: Schema.NonEmptyString,
1110
profileKey: Schema.String.check(Schema.isPattern(/^[a-f0-9]{64}$/u)),
1211
});
1312
export const Response = Schema.Struct({ token: Schema.NonEmptyString });
14-
// A request contains only a slug, UUID and SHA-256 binding. Tokens can be larger
15-
// JWTs. Never truncate either frame into something that could be accepted.
13+
// Selectors are small; tokens can be larger JWTs. Never truncate either frame
14+
// into something that could be accepted.
1615
export const REQUEST_BYTES = 1024;
1716
export const RESPONSE_BYTES = 64 * 1024;
1817
// Idle/incomplete peers and blocked response consumers must not retain sockets.

0 commit comments

Comments
 (0)