Skip to content

Commit ad5a66f

Browse files
committed
test(server): scope transfer budget to thread data
1 parent 9c4cf72 commit ad5a66f

3 files changed

Lines changed: 33 additions & 127 deletions

File tree

‎apps/server/integration/TransferBudgetReport.integration.ts‎

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@ import {
1414

1515
export interface TransferBudgetRun {
1616
readonly provider: ProviderDriverKind;
17-
readonly document: HttpTransferMeasurement;
18-
readonly shellSnapshot: HttpTransferMeasurement;
1917
readonly threadSnapshot: HttpTransferMeasurement;
20-
readonly coldOpenWebSocket: WebSocketTransferTotals;
2118
readonly measuredTurnWebSocket: WebSocketTransferTotals;
2219
}
2320

2421
interface ProviderTransferBudget {
2522
readonly totalWireBytes: number;
26-
readonly documentWireBytes: number;
27-
readonly shellSnapshotWireBytes: number;
2823
readonly threadSnapshotWireBytes: number;
29-
readonly coldOpenWebSocketWireBytes: number;
3024
readonly measuredTurnWebSocketWireBytes: number;
3125
readonly measuredTurnWebSocketDecodedBytes: number;
3226
readonly measuredTurnWebSocketMessages: number;
@@ -35,37 +29,21 @@ interface ProviderTransferBudget {
3529
// These caps leave roughly 30% headroom above the deterministic fixture. The
3630
// CI report preserves the exact values so intentional protocol growth can be
3731
// reviewed and the caps raised explicitly.
32+
const TRANSFER_BUDGET = {
33+
totalWireBytes: 2_900_000,
34+
threadSnapshotWireBytes: 2_600_000,
35+
measuredTurnWebSocketWireBytes: 320_000,
36+
measuredTurnWebSocketDecodedBytes: 1_550_000,
37+
measuredTurnWebSocketMessages: 20,
38+
} satisfies ProviderTransferBudget;
39+
3840
export const TRANSFER_BUDGETS: Readonly<Record<string, ProviderTransferBudget>> = {
39-
codex: {
40-
totalWireBytes: 2_900_000,
41-
documentWireBytes: 1_700,
42-
shellSnapshotWireBytes: 1_000,
43-
threadSnapshotWireBytes: 2_550_000,
44-
coldOpenWebSocketWireBytes: 1_600,
45-
measuredTurnWebSocketWireBytes: 315_000,
46-
measuredTurnWebSocketDecodedBytes: 1_550_000,
47-
measuredTurnWebSocketMessages: 32,
48-
},
49-
claudeAgent: {
50-
totalWireBytes: 2_900_000,
51-
documentWireBytes: 1_700,
52-
shellSnapshotWireBytes: 1_000,
53-
threadSnapshotWireBytes: 2_550_000,
54-
coldOpenWebSocketWireBytes: 1_600,
55-
measuredTurnWebSocketWireBytes: 315_000,
56-
measuredTurnWebSocketDecodedBytes: 1_550_000,
57-
measuredTurnWebSocketMessages: 32,
58-
},
41+
codex: TRANSFER_BUDGET,
42+
claudeAgent: TRANSFER_BUDGET,
5943
};
6044

6145
function totalWireBytes(run: TransferBudgetRun): number {
62-
return (
63-
run.document.wireBytes +
64-
run.shellSnapshot.wireBytes +
65-
run.threadSnapshot.wireBytes +
66-
run.coldOpenWebSocket.wireBytes +
67-
run.measuredTurnWebSocket.wireBytes
68-
);
46+
return run.threadSnapshot.wireBytes + run.measuredTurnWebSocket.wireBytes;
6947
}
7048

7149
function formatBytes(bytes: number): string {
@@ -97,15 +75,8 @@ export function transferBudgetViolations(runs: ReadonlyArray<TransferBudgetRun>)
9775
continue;
9876
}
9977
const checks = [
100-
["total client-bound wire bytes", totalWireBytes(run), budget.totalWireBytes],
101-
["document wire bytes", run.document.wireBytes, budget.documentWireBytes],
102-
["shell snapshot wire bytes", run.shellSnapshot.wireBytes, budget.shellSnapshotWireBytes],
78+
["total thread wire bytes", totalWireBytes(run), budget.totalWireBytes],
10379
["thread snapshot wire bytes", run.threadSnapshot.wireBytes, budget.threadSnapshotWireBytes],
104-
[
105-
"cold-open WebSocket wire bytes",
106-
run.coldOpenWebSocket.wireBytes,
107-
budget.coldOpenWebSocketWireBytes,
108-
],
10980
[
11081
"measured-turn WebSocket wire bytes",
11182
run.measuredTurnWebSocket.wireBytes,
@@ -133,12 +104,12 @@ export function transferBudgetViolations(runs: ReadonlyArray<TransferBudgetRun>)
133104

134105
export function formatTransferBudgetReport(runs: ReadonlyArray<TransferBudgetRun>): string {
135106
const lines = [
136-
"# T3 Code stress transfer budget",
107+
"# T3 Code thread transfer budget",
137108
"",
138-
"Wire values are client-bound bytes read from local HTTP and WebSocket sockets. They include HTTP response headers and the WebSocket upgrade, but exclude TCP/IP and TLS framing. WebSocket permessage-deflate is negotiated.",
109+
"Wire values are thread data bytes read from local HTTP and WebSocket sockets. HTTP includes response headers; WebSocket measurement starts after the resumed thread subscription synchronizes. TCP/IP, TLS framing, and the WebSocket upgrade are excluded. WebSocket permessage-deflate is negotiated.",
139110
`Scenario: ${TRANSFER_HISTORY_TURN_COUNT} historical turns with ${TRANSFER_HISTORY_TOOLS_PER_TURN} command tools and one retained ${formatBytes(TRANSFER_HISTORY_MCP_RESULT_BYTES)} MCP result each, followed by one measured turn with ${TRANSFER_MEASURED_TOOLS} command tools and a retained ${formatBytes(TRANSFER_MEASURED_MCP_RESULT_BYTES)} MCP result. Payload sizes are calibrated from heavy local Codex and Claude histories and contain no user data.`,
140111
"",
141-
"| Provider | Total client-bound wire | Budget | Result |",
112+
"| Provider | Total thread wire | Budget | Result |",
142113
"| --- | ---: | ---: | --- |",
143114
...runs.flatMap((run) => {
144115
const budget = TRANSFER_BUDGETS[run.provider];
@@ -159,28 +130,13 @@ export function formatTransferBudgetReport(runs: ReadonlyArray<TransferBudgetRun
159130
const budget = TRANSFER_BUDGETS[run.provider];
160131
if (!budget) continue;
161132
lines.push(
162-
row(run.provider, "document", "HTTP wire", run.document.wireBytes, budget.documentWireBytes),
163-
row(
164-
run.provider,
165-
"shell snapshot",
166-
"HTTP wire",
167-
run.shellSnapshot.wireBytes,
168-
budget.shellSnapshotWireBytes,
169-
),
170133
row(
171134
run.provider,
172135
"thread snapshot",
173136
"HTTP wire",
174137
run.threadSnapshot.wireBytes,
175138
budget.threadSnapshotWireBytes,
176139
),
177-
row(
178-
run.provider,
179-
"cold open",
180-
"WebSocket wire",
181-
run.coldOpenWebSocket.wireBytes,
182-
budget.coldOpenWebSocketWireBytes,
183-
),
184140
row(
185141
run.provider,
186142
"measured turn",
@@ -209,7 +165,7 @@ export function formatTransferBudgetReport(runs: ReadonlyArray<TransferBudgetRun
209165
lines.push("", "## Compression diagnostics", "");
210166
for (const run of runs) {
211167
lines.push(
212-
`- ${run.provider}: document body ${formatBytes(run.document.encodedBodyBytes)}; shell ${formatBytes(run.shellSnapshot.decodedBodyBytes)} decoded to ${formatBytes(run.shellSnapshot.encodedBodyBytes)} gzip; thread ${formatBytes(run.threadSnapshot.decodedBodyBytes)} decoded to ${formatBytes(run.threadSnapshot.encodedBodyBytes)} gzip.`,
168+
`- ${run.provider}: thread snapshot ${formatBytes(run.threadSnapshot.decodedBodyBytes)} decoded to ${formatBytes(run.threadSnapshot.encodedBodyBytes)} gzip.`,
213169
);
214170
}
215171

‎apps/server/integration/fixtures/transferBudget.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ const sourceModules = [
1919
"connection/supervisor.ts",
2020
"rpc/client.ts",
2121
"rpc/protocol.ts",
22-
"state/shell.ts",
2322
"state/threads.ts",
2423
"state/threadReducer.ts",
25-
"state/shellReducer.ts",
2624
"state/threadSnapshotHttp.ts",
27-
"state/shellSnapshotHttp.ts",
2825
"orchestration/http.ts",
2926
"orchestration/Normalizer.ts",
3027
"orchestration/ActivityPayloadProjection.ts",

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

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
22
import * as NodeSocket from "@effect/platform-node/NodeSocket";
33
import * as NodeServices from "@effect/platform-node/NodeServices";
44
import * as NodeCrypto from "node:crypto";
5-
import * as NodeURL from "node:url";
65
import { HostProcessEnvironment, HostProcessPlatform } from "@t3tools/shared/hostProcess";
76

87
import {
@@ -17,8 +16,6 @@ import {
1716
KeybindingRule,
1817
MessageId,
1918
ExternalLauncherCommandNotFoundError,
20-
OrchestrationShellSnapshot,
21-
type OrchestrationShellStreamItem,
2219
OrchestrationThreadDetailSnapshot,
2320
type OrchestrationThreadStreamItem,
2421
type OrchestrationThreadShell,
@@ -78,23 +75,28 @@ import * as Socket from "effect/unstable/socket/Socket";
7875
import { vi } from "vite-plus/test";
7976

8077
const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
81-
const decodeTransferShellSnapshot = Schema.decodeUnknownEffect(
82-
Schema.fromJsonString(OrchestrationShellSnapshot),
83-
);
8478
const decodeTransferThreadSnapshot = Schema.decodeUnknownEffect(
8579
Schema.fromJsonString(OrchestrationThreadDetailSnapshot),
8680
);
8781

8882
const collectQueueUntil = Effect.fn("TransferBudget.collectQueueUntil")(function* <A>(
8983
queue: Queue.Queue<A>,
9084
predicate: (value: A) => boolean,
85+
waitDescription: string,
9186
) {
92-
const values: A[] = [];
93-
while (true) {
94-
const value = yield* Queue.take(queue);
95-
values.push(value);
96-
if (predicate(value)) return values;
97-
}
87+
return yield* Effect.gen(function* () {
88+
const values: A[] = [];
89+
while (true) {
90+
const value = yield* Queue.take(queue);
91+
values.push(value);
92+
if (predicate(value)) return values;
93+
}
94+
}).pipe(
95+
Effect.timeoutOrElse({
96+
duration: "10 seconds",
97+
orElse: () => Effect.die(new Error(`Timed out waiting for ${waitDescription}`)),
98+
}),
99+
);
98100
});
99101

100102
import * as BackgroundPolicy from "./background/BackgroundPolicy.ts";
@@ -7761,14 +7763,13 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
77617763
});
77627764

77637765
it.live(
7764-
"reports stress HTTP and WebSocket transfer budgets",
7766+
"reports thread HTTP and WebSocket transfer budgets",
77657767
() =>
77667768
Effect.gen(function* () {
77677769
const providers = [
77687770
ProviderDriverKind.make("codex"),
77697771
ProviderDriverKind.make("claudeAgent"),
77707772
] as const;
7771-
const staticDir = NodeURL.fileURLToPath(new URL("../../web", import.meta.url));
77727773

77737774
const runs = yield* Effect.forEach(
77747775
providers,
@@ -7779,7 +7780,6 @@ it.live(
77797780
Effect.gen(function* () {
77807781
yield* seedTransferBudgetHistory(harness, provider);
77817782
yield* buildAppUnderTest({
7782-
config: { staticDir },
77837783
layers: {
77847784
orchestrationEngine: harness.engine,
77857785
projectionSnapshotQuery: harness.snapshotQuery,
@@ -7788,8 +7788,6 @@ it.live(
77887788

77897789
const baseUrl = yield* getHttpServerUrl();
77907790
const cookie = yield* getAuthenticatedSessionCookieHeader();
7791-
const document = yield* measureHttpGet({ url: `${baseUrl}/` });
7792-
assert.equal(document.status, 200);
77937791

77947792
const recorder = makeWebSocketTransferRecorder();
77957793
const wsUrl = baseUrl.replace(/^http:/, "ws:") + "/ws";
@@ -7802,42 +7800,6 @@ it.live(
78027800
return yield* Effect.scoped(
78037801
Effect.gen(function* () {
78047802
const client = yield* makeCountingWsRpcClient;
7805-
yield* client[WS_METHODS.serverGetConfig]({});
7806-
7807-
const configEvents = yield* Queue.unbounded<unknown>();
7808-
yield* client[WS_METHODS.subscribeServerConfig]({}).pipe(
7809-
Stream.runForEach((event) =>
7810-
Queue.offer(configEvents, event).pipe(Effect.asVoid),
7811-
),
7812-
Effect.forkScoped,
7813-
);
7814-
yield* Queue.take(configEvents);
7815-
7816-
const shellSnapshot = yield* measureHttpGet({
7817-
url: `${baseUrl}/api/orchestration/shell`,
7818-
headers: { cookie },
7819-
});
7820-
assert.equal(shellSnapshot.status, 200);
7821-
assert.equal(shellSnapshot.contentEncoding, "gzip");
7822-
const decodedShell = yield* decodeTransferShellSnapshot(
7823-
Buffer.from(shellSnapshot.decodedBody).toString("utf8"),
7824-
);
7825-
7826-
const shellItems = yield* Queue.unbounded<OrchestrationShellStreamItem>();
7827-
yield* client[ORCHESTRATION_WS_METHODS.subscribeShell]({
7828-
afterSequence: decodedShell.snapshotSequence,
7829-
requestCompletionMarker: true,
7830-
}).pipe(
7831-
Stream.runForEach((item) =>
7832-
Queue.offer(shellItems, item).pipe(Effect.asVoid),
7833-
),
7834-
Effect.forkScoped,
7835-
);
7836-
const initialShellItems = yield* collectQueueUntil(
7837-
shellItems,
7838-
(item) => item.kind === "synchronized",
7839-
);
7840-
assert.isFalse(initialShellItems.some((item) => item.kind === "snapshot"));
78417803

78427804
const threadSnapshot = yield* measureHttpGet({
78437805
url: `${baseUrl}/api/orchestration/threads/${TRANSFER_THREAD_ID}`,
@@ -7867,11 +7829,11 @@ it.live(
78677829
const initialThreadItems = yield* collectQueueUntil(
78687830
threadItems,
78697831
(item) => item.kind === "synchronized",
7832+
`${provider} thread subscription to synchronize`,
78707833
);
78717834
assert.isFalse(initialThreadItems.some((item) => item.kind === "snapshot"));
78727835
assert.include(recorder.negotiatedExtensions(), "permessage-deflate");
78737836

7874-
const coldOpenWebSocket = recorder.totals();
78757837
yield* queueMeasuredTransferTurn(harness, provider);
78767838
const turnStartTotals = recorder.totals();
78777839
yield* client[ORCHESTRATION_WS_METHODS.dispatchCommand]({
@@ -7895,13 +7857,7 @@ it.live(
78957857
yield* collectQueueUntil(
78967858
threadItems,
78977859
(item) => item.kind === "event" && item.event.sequence >= finalSequence,
7898-
);
7899-
yield* collectQueueUntil(
7900-
shellItems,
7901-
(item) =>
7902-
item.kind !== "snapshot" &&
7903-
item.kind !== "synchronized" &&
7904-
item.sequence >= finalSequence,
7860+
`${provider} thread stream to reach sequence ${finalSequence}`,
79057861
);
79067862
const measuredTurnWebSocket = transferDelta(turnStartTotals, recorder.totals());
79077863

@@ -7926,10 +7882,7 @@ it.live(
79267882

79277883
return {
79287884
provider,
7929-
document,
7930-
shellSnapshot,
79317885
threadSnapshot,
7932-
coldOpenWebSocket,
79337886
measuredTurnWebSocket,
79347887
} satisfies TransferBudgetRun;
79357888
}).pipe(Effect.provide(protocolLayer)),

0 commit comments

Comments
 (0)