The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 14:30 UTC
test(server): data regression test now fails when recent fetch savings regress (#25795)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 26, 2026 at 23:38 UTC
278fdce1af7eb821c34ee416c441952df250ac63
4 files changed
+249
-85
apps/server/integration/TransferBudgetReport.integration.ts
+57
-18
@@ -11,7 +11,11 @@ import {
11
TRANSFER_MEASURED_MCP_RESULT_BYTES,
12
TRANSFER_MEASURED_TOOLS,
13
} from "./fixtures/transferBudget.ts";
14
-import { LONG_TURN_WORK_ROWS } from "./TransferBudgetV2Fixture.integration.ts";
14
+import {
15
+ LONG_TURN_WORK_ROWS,
16
+ SHELL_IDLE_SUBAGENTS,
17
+ SHELL_SETTLED_THREADS,
18
+} from "./TransferBudgetV2Fixture.integration.ts";
19
20
export interface WebSocketCatchUpMeasurement extends WebSocketTransferTotals {
21
readonly mode: "replay" | "snapshot";
@@ -36,6 +40,12 @@ export interface TransferBudgetRun {
40
/** The compact bounded snapshot web and mobile load when the long-turn thread opens. */
41
readonly longTurnColdOpen: TimelineHttpMeasurement;
42
readonly longTurnHistoryPage: TimelineHttpMeasurement;
43
+ /** The same reads as an older client that only sends `compactTurnItems`, to show the savings. */
44
+ readonly longTurnColdOpenLegacy: TimelineHttpMeasurement;
45
+ readonly longTurnHistoryPageLegacy: TimelineHttpMeasurement;
46
+ /** The cold-connect shell snapshot after the settled-thread fleet is written. */
47
+ readonly fleetShell: TimelineHttpMeasurement;
48
+ readonly fleetShellLegacy: TimelineHttpMeasurement;
49
}
50
51
interface ProviderTransferBudget {
@@ -46,11 +56,12 @@ interface ProviderTransferBudget {
56
readonly measuredTurnWebSocketMessages: number;
57
}
58
59
+// The measured turn decodes to about 22 KB; without live body dedupe its repeated answer makes it 26 KB.
60
const TRANSFER_BUDGET = {
61
totalWireBytes: 7_000,
62
threadSnapshotWireBytes: 5_000,
63
measuredTurnWebSocketWireBytes: 2_000,
53
- measuredTurnWebSocketDecodedBytes: 30_000,
64
+ measuredTurnWebSocketDecodedBytes: 25_000,
65
measuredTurnWebSocketMessages: 8,
66
} satisfies ProviderTransferBudget;
67
@@ -59,15 +70,20 @@ const TRANSFER_BUDGETS: Readonly<Record<string, ProviderTransferBudget>> = {
70
claudeAgent: TRANSFER_BUDGET,
71
};
72
62
-// Decoded bytes, not wire bytes: phones parse and keep the decoded JSON. About
63
-// 30% above the observed 92 KB; without row budgets inside user turns the cold
64
-// open carried all 920 rows (1.07 MB). Kept apart from TRANSFER_BUDGET because
65
-// the PR comment validates that object's keys.
73
+// Decoded bytes, not wire bytes: phones parse and keep the decoded JSON. About 7% above the
74
+// observed 103 KB, so a cold open without body dedupe (117 KB), the ID table, or row budgets
75
+// (all 920 rows) fails. Kept apart from TRANSFER_BUDGET because the PR comment validates its keys.
76
const LONG_TURN_BUDGET = {
67
- decodedBytes: 120_000,
77
+ decodedBytes: 110_000,
78
rows: 75,
79
};
80
81
+// About 30% above the observed 42 KB. Without the shell opt-ins it carries all 142 rows (217 KB).
82
+const FLEET_SHELL_BUDGET = {
83
+ decodedBytes: 55_000,
84
+ rows: 27,
85
+};
86
+
87
function totalWireBytes(run: TransferBudgetRun): number {
88
return run.threadSnapshot.wireBytes + run.measuredTurnWebSocket.wireBytes;
89
}
@@ -160,21 +176,28 @@ function webSocketRows(
176
];
177
}
178
163
-function longTurnRows(
179
+function timelineRows(
180
provider: ProviderDriverKind,
181
phase: string,
182
measured: TimelineHttpMeasurement,
183
+ budget: { readonly decodedBytes: number; readonly rows: number },
184
): string[] {
185
return [
186
infoRow(provider, phase, "HTTP wire", measured.http.wireBytes),
170
- row(
171
- provider,
172
- phase,
173
- "HTTP decoded",
174
- measured.http.decodedBodyBytes,
175
- LONG_TURN_BUDGET.decodedBytes,
176
- ),
177
- row(provider, phase, "rows", measured.rows, LONG_TURN_BUDGET.rows, String),
187
+ row(provider, phase, "HTTP decoded", measured.http.decodedBodyBytes, budget.decodedBytes),
188
+ row(provider, phase, "rows", measured.rows, budget.rows, String),
189
+ ];
190
+}
191
+
192
+function legacyRows(
193
+ provider: ProviderDriverKind,
194
+ phase: string,
195
+ measured: TimelineHttpMeasurement,
196
+): string[] {
197
+ return [
198
+ infoRow(provider, `${phase}, older client`, "HTTP wire", measured.http.wireBytes),
199
+ infoRow(provider, `${phase}, older client`, "HTTP decoded", measured.http.decodedBodyBytes),
200
+ infoRow(provider, `${phase}, older client`, "rows", measured.rows, String),
201
];
202
}
203
@@ -216,6 +239,12 @@ export function transferBudgetViolations(runs: ReadonlyArray<TransferBudgetRun>)
239
LONG_TURN_BUDGET.decodedBytes,
240
],
241
["long-turn history page rows", run.longTurnHistoryPage.rows, LONG_TURN_BUDGET.rows],
242
+ [
243
+ "fleet shell snapshot decoded bytes",
244
+ run.fleetShell.http.decodedBodyBytes,
245
+ FLEET_SHELL_BUDGET.decodedBytes,
246
+ ],
247
+ ["fleet shell snapshot rows", run.fleetShell.rows, FLEET_SHELL_BUDGET.rows],
248
] as const;
249
for (const [metric, observed, maximum] of checks) {
250
if (observed > maximum) {
@@ -234,6 +263,7 @@ export function formatTransferBudgetReport(runs: ReadonlyArray<TransferBudgetRun
263
"The measured turn is observed on three sockets at once: one with only the thread subscription (the capped rows), one with only the shell subscription, and a second client holding both. Server egress is the sum of the three. After the turn the second client disconnects and new sockets resubscribe from the cursor it held before the turn, which is the cursor a backgrounded phone would hold. SQL statements are the SQL client's per-statement spans, counted across V2 persistence and the HTTP/WebSocket handlers.",
264
`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. Synthetic V2 domain events exercise persistence, wire projection, and production HTTP/subscription handlers; this does not measure provider adapter ingestion. Payloads contain no user data.`,
265
`The long-turn rows open a second thread through the compact bounded snapshot web and mobile use, then load one older page. Its last user turn holds ${LONG_TURN_WORK_ROWS} rows of reasoning, commands, file changes, MCP calls, progress messages, checkpoints, and subagents.`,
266
+ `The fleet shell rows read the cold-connect shell after ${SHELL_SETTLED_THREADS} settled threads and ${SHELL_IDLE_SUBAGENTS} idle subagent children are added. Budgeted reads send the opt-ins current clients send; "older client" rows show the same read without the opt-ins added since row budgets.`,
267
"",
268
"| Provider | Total thread wire | Budget | Result |",
269
"| --- | ---: | ---: | --- |",
@@ -311,8 +341,17 @@ export function formatTransferBudgetReport(runs: ReadonlyArray<TransferBudgetRun
341
run.reconnectShell,
342
),
343
infoRow(run.provider, "reconnect", "SQL statements", run.reconnectSqlStatements, String),
314
- ...longTurnRows(run.provider, "long-turn cold open", run.longTurnColdOpen),
315
- ...longTurnRows(run.provider, "long-turn history page", run.longTurnHistoryPage),
344
+ ...timelineRows(run.provider, "long-turn cold open", run.longTurnColdOpen, LONG_TURN_BUDGET),
345
+ ...legacyRows(run.provider, "long-turn cold open", run.longTurnColdOpenLegacy),
346
+ ...timelineRows(
347
+ run.provider,
348
+ "long-turn history page",
349
+ run.longTurnHistoryPage,
350
+ LONG_TURN_BUDGET,
351
+ ),
352
+ ...legacyRows(run.provider, "long-turn history page", run.longTurnHistoryPageLegacy),
353
+ ...timelineRows(run.provider, "fleet shell snapshot", run.fleetShell, FLEET_SHELL_BUDGET),
354
+ ...legacyRows(run.provider, "fleet shell snapshot", run.fleetShellLegacy),
355
);
356
}
357
apps/server/integration/TransferBudgetV2Fixture.integration.ts
+111
-41
@@ -6,6 +6,8 @@ import {
6
NodeId,
7
ProjectId,
8
ProviderInstanceId,
9
+ ProviderThreadId,
10
+ ProviderTurnId,
11
RunId,
12
ThreadId,
13
TurnItemId,
@@ -23,10 +25,12 @@ import {
25
} from "./fixtures/transferBudget.ts";
26
27
export const THREAD_ID = ThreadId.make("transfer-budget-thread");
28
+type ThreadCreatedEvent = Extract<OrchestrationV2DomainEvent, { readonly type: "thread.created" }>;
29
export function threadCreated(
30
provider: ProviderDriverKind,
31
threadId: ThreadId = THREAD_ID,
29
-): OrchestrationV2DomainEvent {
32
+ overrides: Partial<ThreadCreatedEvent["payload"]> = {},
33
+): ThreadCreatedEvent {
34
const now = DateTime.makeUnsafe("2026-06-01T00:00:00Z");
35
return {
36
id: EventId.make(`thread-created:${threadId}`),
@@ -58,6 +62,7 @@ export function threadCreated(
62
settledAt: null,
63
lastVisitedAt: null,
64
deletedAt: null,
65
+ ...overrides,
66
},
67
};
68
}
@@ -102,6 +107,9 @@ export function turnEvents(
107
const events: OrchestrationV2DomainEvent[] = [
108
{ ...common, id: EventId.make(`run-${index}`), type: "run.created", payload: run },
109
];
110
+ const answer =
111
+ `Completed ${provider} inspection ${index}. ` +
112
+ "The projection preserves transcript text and bounds tool output. ".repeat(60);
113
for (const role of ["user", "assistant"] as const) {
114
events.push({
115
...common,
@@ -113,11 +121,7 @@ export function turnEvents(
121
runId,
122
nodeId,
123
role,
116
- text:
117
- role === "user"
118
- ? `Inspect transfer ${index}`
119
- : `Completed ${provider} inspection ${index}. ` +
120
- "The projection preserves transcript text and bounds tool output. ".repeat(60),
124
+ text: role === "user" ? `Inspect transfer ${index}` : answer,
125
attachments: [],
126
streaming: false,
127
createdAt: now,
@@ -128,6 +132,22 @@ export function turnEvents(
132
});
133
}
134
const toolCount = measured ? TRANSFER_MEASURED_TOOLS : TRANSFER_HISTORY_TOOLS_PER_TURN;
135
+ const item = (id: string, ordinal: number, title: string | null) => ({
136
+ id: TurnItemId.make(id),
137
+ threadId: THREAD_ID,
138
+ runId,
139
+ nodeId,
140
+ providerThreadId: null,
141
+ providerTurnId: null,
142
+ nativeItemRef: null,
143
+ parentItemId: null,
144
+ ordinal,
145
+ status: "completed" as const,
146
+ title,
147
+ startedAt: now,
148
+ completedAt: now,
149
+ updatedAt: now,
150
+ });
151
for (let tool = 0; tool <= toolCount; tool++) {
152
const mcp = tool === toolCount;
153
const output = diagnosticOutput({
@@ -140,22 +160,11 @@ export function turnEvents(
160
: TRANSFER_HISTORY_MCP_RESULT_BYTES
161
: 4096,
162
});
143
- const base = {
144
- id: TurnItemId.make(`item-${index}-${tool}`),
145
- threadId: THREAD_ID,
146
- runId,
147
- nodeId,
148
- providerThreadId: null,
149
- providerTurnId: null,
150
- nativeItemRef: null,
151
- parentItemId: null,
152
- ordinal: tool + 1,
153
- status: "completed" as const,
154
- title: mcp ? "MCP search" : `Inspect source ${tool}`,
155
- startedAt: now,
156
- completedAt: now,
157
- updatedAt: now,
158
- };
163
+ const base = item(
164
+ `item-${index}-${tool}`,
165
+ tool + 1,
166
+ mcp ? "MCP search" : `Inspect source ${tool}`,
167
+ );
168
events.push({
169
...common,
170
id: EventId.make(`tool-${index}-${tool}`),
@@ -177,6 +186,21 @@ export function turnEvents(
186
},
187
});
188
}
189
+ // The live turn repeats its answer in a turn item, as adapters do, so live dedupe has work.
190
+ // History turns skip it to keep the fallback thread snapshot under its wire ceiling.
191
+ if (measured)
192
+ events.push({
193
+ ...common,
194
+ id: EventId.make(`answer-item-${index}`),
195
+ type: "turn-item.updated",
196
+ payload: {
197
+ ...item(`item-${index}-answer`, toolCount + 2, null),
198
+ type: "assistant_message",
199
+ messageId: MessageId.make(`assistant-${index}`),
200
+ text: answer,
201
+ streaming: false,
202
+ },
203
+ });
204
events.push({
205
...common,
206
id: EventId.make(`complete-${index}`),
@@ -192,6 +216,8 @@ export const LONG_TURN_WORK_ROWS = 900;
216
/**
217
* Three short user turns, then one agent turn far longer than a cold-open
218
* window, with the item kinds a long agent run produces. One batch per turn.
219
+ * Run, node, provider and item IDs follow the composite shapes the Claude
220
+ * adapter stores, and every assistant message has its record, as real threads do.
221
*/
222
export function longTurnThreadBatches(
223
provider: ProviderDriverKind,
@@ -208,8 +234,14 @@ export function longTurnThreadBatches(
234
235
const turn = (index: number, workRows: number): OrchestrationV2DomainEvent[] => {
236
const now = DateTime.makeUnsafe(`2026-06-02T00:${String(index).padStart(2, "0")}:00Z`);
211
- const runId = RunId.make(`long-turn-run-${index}`);
212
- const nodeId = NodeId.make(`long-turn-node-${index}`);
237
+ const runId = RunId.make(`run:thread:${threadId}:ordinal:${index + 1}`);
238
+ const nodeId = NodeId.make(`node:run:${encodeURIComponent(runId)}:root`);
239
+ const providerThreadId = ProviderThreadId.make(
240
+ `provider-thread:provider:${provider}:native-thread:${encodeURIComponent(`pending:${runId}`)}`,
241
+ );
242
+ const providerTurnId = ProviderTurnId.make(
243
+ `provider-turn:provider:${provider}:native-turn:${encodeURIComponent(`turn:run-attempt:${encodeURIComponent(runId)}:attempt:1`)}`,
244
+ );
245
const common = {
246
threadId,
247
runId,
@@ -218,6 +250,10 @@ export function longTurnThreadBatches(
250
providerInstanceId,
251
occurredAt: now,
252
};
253
+ const messageId = (role: "user" | "assistant", row: string) =>
254
+ MessageId.make(
255
+ `message:provider:${provider}:native-item:msg_01LongTurn${role}${index}x${row}`,
256
+ );
257
const run = {
258
id: runId,
259
threadId,
@@ -225,7 +261,7 @@ export function longTurnThreadBatches(
261
providerInstanceId,
262
modelSelection,
263
providerThreadId: null,
228
- userMessageId: MessageId.make(`long-turn-user-${index}`),
264
+ userMessageId: messageId("user", "prompt"),
265
rootNodeId: nodeId,
266
activeAttemptId: null,
267
status: "running" as const,
@@ -237,14 +273,15 @@ export function longTurnThreadBatches(
273
};
274
const base = (row: string, title: string | null) => {
275
ordinal += 1;
276
+ const nativeId = `toolu_01LongTurn${index}x${row}`;
277
return {
241
- id: TurnItemId.make(`long-turn-item-${index}-${row}`),
278
+ id: TurnItemId.make(`turn-item:provider:${provider}:native-item:${nativeId}`),
279
threadId,
280
runId,
281
nodeId,
245
- providerThreadId: null,
246
- providerTurnId: null,
247
- nativeItemRef: null,
282
+ providerThreadId,
283
+ providerTurnId,
284
+ nativeItemRef: { driver: provider, nativeId, strength: "strong" as const },
285
parentItemId: null,
286
ordinal,
287
status: "completed" as const,
@@ -258,7 +295,7 @@ export function longTurnThreadBatches(
295
{ ...common, id: EventId.make(`long-turn-run-${index}`), type: "run.created", payload: run },
296
];
297
const message = (role: "user" | "assistant", row: string, messageText: string) => {
261
- const messageId = MessageId.make(`long-turn-${role}-${index}-${row}`);
298
+ const id = messageId(role, row);
299
const createdBy = role === "user" ? ("user" as const) : ("agent" as const);
300
events.push(
301
{
@@ -266,7 +303,7 @@ export function longTurnThreadBatches(
303
id: EventId.make(`long-turn-message-${index}-${row}`),
304
type: "message.updated",
305
payload: {
269
- id: messageId,
306
+ id,
307
threadId,
308
runId,
309
nodeId,
@@ -291,7 +328,7 @@ export function longTurnThreadBatches(
328
type: "user_message",
329
createdBy,
330
creationSource: "web",
294
- messageId,
331
+ messageId: id,
332
inputIntent: "turn_start",
333
text: messageText,
334
attachments: [],
@@ -299,7 +336,7 @@ export function longTurnThreadBatches(
336
: {
337
...base(row, null),
338
type: "assistant_message",
302
- messageId,
339
+ messageId: id,
340
text: messageText,
341
streaming: false,
342
},
@@ -360,14 +397,6 @@ export function longTurnThreadBatches(
397
input: { query: `module ${row}` },
398
output: { text: text(index, row, 6_144) },
399
};
363
- case 5:
364
- return {
365
- ...base(String(row), null),
366
- type: "assistant_message",
367
- messageId: MessageId.make(`long-turn-progress-${index}-${row}`),
368
- text: text(index, row, 600),
369
- streaming: false,
370
- };
400
default:
401
return {
402
...base(String(row), `Run check ${row}`),
@@ -381,6 +410,10 @@ export function longTurnThreadBatches(
410
411
message("user", "prompt", `Continue the feature work, step ${index}.`);
412
for (let row = 0; row < workRows; row++) {
413
+ if (row % 8 === 5) {
414
+ message("assistant", String(row), text(index, row, 1_500));
415
+ continue;
416
+ }
417
events.push({
418
...common,
419
id: EventId.make(`long-turn-work-${index}-${row}`),
@@ -406,3 +439,40 @@ export function longTurnThreadBatches(
439
turn(3, LONG_TURN_WORK_ROWS),
440
];
441
}
442
+
443
+export const SHELL_SETTLED_THREADS = 100;
444
+export const SHELL_IDLE_SUBAGENTS = 40;
445
+
446
+/**
447
+ * A busy sidebar: settled top-level threads, settled a minute apart, with idle subagent children
448
+ * under the newest ones. Opted-in cold connects skip the children and all but 25 settled threads.
449
+ */
450
+export function shellFleetEvents(
451
+ provider: ProviderDriverKind,
452
+): ReadonlyArray<OrchestrationV2DomainEvent> {
453
+ return Array.from({ length: SHELL_SETTLED_THREADS }, (_, index) => {
454
+ const threadId = ThreadId.make(`transfer-budget-settled-${index}`);
455
+ const settledAt = DateTime.makeUnsafe(Date.UTC(2026, 5, 3, 0, index));
456
+ const settled = threadCreated(provider, threadId, {
457
+ title: `Settled transfer thread ${index}`,
458
+ branch: `feature/settled-${index}`,
459
+ settledOverride: "settled",
460
+ settledAt,
461
+ updatedAt: settledAt,
462
+ });
463
+ if (index < SHELL_SETTLED_THREADS - SHELL_IDLE_SUBAGENTS) return [settled];
464
+ const childId = ThreadId.make(`transfer-budget-settled-${index}-subagent`);
465
+ return [
466
+ settled,
467
+ threadCreated(provider, childId, {
468
+ title: `Subagent of settled thread ${index}`,
469
+ createdBy: "agent",
470
+ lineage: {
471
+ parentThreadId: threadId,
472
+ relationshipToParent: "subagent",
473
+ rootThreadId: threadId,
474
+ },
475
+ }),
476
+ ];
477
+ }).flat();
478
+}
apps/server/integration/transferBudgetV2.integration.test.ts
+77
-23
@@ -55,6 +55,7 @@ import { subscribeOrchestrationV2Thread, subscribeOrchestrationV2Shell } from ".
55
import {
56
measureHttpGet,
57
openMeasuredWsClient,
58
+ type HttpTransferMeasurement,
59
type MeasuredWsClient,
60
} from "./NetworkTransferMeasurement.integration.ts";
61
import { makeSqlStatementCounter } from "./SqlStatementCounter.integration.ts";
@@ -68,11 +69,20 @@ import { TRANSFER_HISTORY_TURN_COUNT } from "./fixtures/transferBudget.ts";
69
import {
70
LONG_TURN_THREAD_ID,
71
longTurnThreadBatches,
72
+ SHELL_IDLE_SUBAGENTS,
73
+ SHELL_SETTLED_THREADS,
74
+ shellFleetEvents,
75
THREAD_ID,
76
threadCreated,
77
turnEvents,
78
} from "./TransferBudgetV2Fixture.integration.ts";
79
80
+// The opt-ins current web and mobile clients send; keep in sync with client-runtime's
81
+// boundedThreadSnapshotHttp.ts, threadHistoryHttp.ts, shellSnapshotHttp.ts, threads.ts and shell.ts.
82
+const CLIENT_BOUNDED_QUERY = "compactTurnItems=1&dedupeBodies=1&compactIds=1";
83
+const CLIENT_HISTORY_QUERY = "compactIds=1";
84
+const CLIENT_SHELL_QUERY = "omitIdleSubagents=1&omitOlderSettled=1";
85
+
86
const decodeThreadSnapshot = Schema.decodeUnknownEffect(
87
Schema.fromJsonString(Schema.toCodecJson(OrchestrationV2ThreadDetailSnapshot)),
88
);
@@ -220,10 +230,15 @@ const subscribe = Effect.fn("transfer.subscribe")(function* (
230
afterSequence,
231
requestCompletionMarker: true,
232
acceptBoundedSnapshot: true,
233
+ acceptCompactTurnItems: true,
234
+ acceptCompactIds: true,
235
+ acceptDedupedBodies: true,
236
})
237
: client.client[ORCHESTRATION_V2_WS_METHODS.subscribeShell]({
238
afterSequence,
239
requestCompletionMarker: true,
240
+ omitIdleSubagents: true,
241
+ omitOlderSettled: true,
242
});
243
yield* stream.pipe(
244
Stream.runForEach((item) => Queue.offer(queue, item)),
@@ -323,7 +338,18 @@ it.live("reports V2 thread HTTP and WebSocket transfer budgets", () =>
338
const finalShell = yield* projection.getThreadShell(THREAD_ID);
339
const shellTerminal = (item: StreamItem) =>
340
item.kind === "thread.updated" && NodeUtil.isDeepStrictEqual(item.thread, finalShell);
326
- for (const queue of [tq, ttq]) yield* collectUntil(queue, threadTerminal);
341
+ const liveTurn = yield* collectUntil(tq, threadTerminal);
342
+ yield* collectUntil(ttq, threadTerminal);
343
+ // A direct check, so live dedupe stays guarded however small the turn gets.
344
+ const liveAnswer = liveTurn.flatMap((item) =>
345
+ item.kind === "event" &&
346
+ item.event.type === "turn-item.updated" &&
347
+ item.event.payload.type === "assistant_message"
348
+ ? [item.event.payload]
349
+ : [],
350
+ );
351
+ assert.equal(liveAnswer.length, 1);
352
+ assert.equal(liveAnswer[0]!.textOmitted, true);
353
for (const queue of [sq, ssq]) yield* collectUntil(queue, shellTerminal);
354
const measuredTurnWebSocket = difference(thread.recorder.totals(), threadBefore);
355
const measuredTurnShellWebSocket = difference(shell.recorder.totals(), shellBefore);
@@ -353,25 +379,52 @@ it.live("reports V2 thread HTTP and WebSocket transfer budgets", () =>
379
assert.equal(threadMode, "snapshot");
380
381
for (const events of longTurnThreadBatches(provider)) yield* sink.write({ events });
356
- const longTurnColdOpen = yield* measureHttpGet({
357
- url: `${base}/api/orchestration/threads/${LONG_TURN_THREAD_ID}/bounded?compactTurnItems=1`,
358
- headers: { [ORCHESTRATION_PROTOCOL_HEADER]: String(ORCHESTRATION_PROTOCOL_VERSION) },
359
- });
360
- assert.equal(longTurnColdOpen.status, 200);
361
- const coldOpen = yield* decodeBoundedSnapshot(
362
- Buffer.from(longTurnColdOpen.decodedBody).toString(),
363
- );
364
- const cursor = coldOpen.historyCursor;
382
+ const get = (path: string) =>
383
+ measureHttpGet({
384
+ url: `${base}${path}`,
385
+ headers: { [ORCHESTRATION_PROTOCOL_HEADER]: String(ORCHESTRATION_PROTOCOL_VERSION) },
386
+ }).pipe(Effect.tap((http) => Effect.sync(() => assert.equal(http.status, 200))));
387
+ const decoded = (http: HttpTransferMeasurement) =>
388
+ Buffer.from(http.decodedBody).toString();
389
+ const longTurnPath = `/api/orchestration/threads/${LONG_TURN_THREAD_ID}`;
390
+ const readColdOpen = (query: string) =>
391
+ Effect.gen(function* () {
392
+ const http = yield* get(`${longTurnPath}/bounded?${query}`);
393
+ const snapshot = yield* decodeBoundedSnapshot(decoded(http));
394
+ const rows = snapshot.projection.visibleTurnItems.length;
395
+ return { http, rows, cursor: snapshot.historyCursor };
396
+ });
397
+ const readHistoryPage = (cursor: string, query: string) =>
398
+ Effect.gen(function* () {
399
+ const http = yield* get(
400
+ `${longTurnPath}/history?cursor=${encodeURIComponent(cursor)}&${query}`,
401
+ );
402
+ const page = yield* decodeHistoryPage(decoded(http));
403
+ assert.isTrue(page.hasMoreHistory);
404
+ return { http, rows: page.items.length };
405
+ });
406
+ const readShell = (query: string) =>
407
+ Effect.gen(function* () {
408
+ const http = yield* get(`/api/orchestration/shell?${query}`);
409
+ return { http, rows: (yield* decodeShellSnapshot(decoded(http))).threads.length };
410
+ });
411
+
412
+ const { cursor: _, ...longTurnColdOpenLegacy } =
413
+ yield* readColdOpen("compactTurnItems=1");
414
+ const { cursor, ...longTurnColdOpen } = yield* readColdOpen(CLIENT_BOUNDED_QUERY);
415
if (cursor === null) return yield* Effect.die("Expected older long-turn history");
366
- const longTurnHistoryPage = yield* measureHttpGet({
367
- url: `${base}/api/orchestration/threads/${LONG_TURN_THREAD_ID}/history?cursor=${encodeURIComponent(cursor)}`,
368
- headers: { [ORCHESTRATION_PROTOCOL_HEADER]: String(ORCHESTRATION_PROTOCOL_VERSION) },
369
- });
370
- assert.equal(longTurnHistoryPage.status, 200);
371
- const historyPage = yield* decodeHistoryPage(
372
- Buffer.from(longTurnHistoryPage.decodedBody).toString(),
416
+ const longTurnHistoryPageLegacy = yield* readHistoryPage(cursor, "");
417
+ const longTurnHistoryPage = yield* readHistoryPage(cursor, CLIENT_HISTORY_QUERY);
418
+
419
+ // The transfer thread plus the long-turn thread.
420
+ const earlierThreads = decodedShell.threads.length + 1;
421
+ yield* sink.write({ events: shellFleetEvents(provider) });
422
+ const fleetShellLegacy = yield* readShell("");
423
+ const fleetShell = yield* readShell(CLIENT_SHELL_QUERY);
424
+ assert.equal(
425
+ fleetShellLegacy.rows,
426
+ earlierThreads + SHELL_SETTLED_THREADS + SHELL_IDLE_SUBAGENTS,
427
);
374
- assert.isTrue(historyPage.hasMoreHistory);
428
return {
429
provider,
430
threadSnapshot,
@@ -383,11 +436,12 @@ it.live("reports V2 thread HTTP and WebSocket transfer budgets", () =>
436
reconnectThread,
437
reconnectShell,
438
reconnectSqlStatements,
386
- longTurnColdOpen: {
387
- http: longTurnColdOpen,
388
- rows: coldOpen.projection.visibleTurnItems.length,
389
- },
390
- longTurnHistoryPage: { http: longTurnHistoryPage, rows: historyPage.items.length },
439
+ longTurnColdOpenLegacy,
440
+ longTurnColdOpen,
441
+ longTurnHistoryPageLegacy,
442
+ longTurnHistoryPage,
443
+ fleetShellLegacy,
444
+ fleetShell,
445
} satisfies TransferBudgetRun;
446
}).pipe(
447
Effect.provide(Layer.fresh(layerServices).pipe(Layer.provideMerge(NodeServices.layer))),
docs/internals/performance-regressions.md
+4
-3
@@ -63,9 +63,10 @@ for the same synthetic workload, preserving historical application-object counts
63
These are neither compressed WebSocket captures nor measurements of server RSS, and command
64
fixtures exclude unrelated settings calls and subscription events. Payload budgets belong in
65
these tests so regressions fail locally. The transfer budget integration test
66
-(`apps/server/integration/transferBudgetV2.integration.test.ts`) caps the decoded bytes and rows
67
-of the compact bounded snapshot that web and mobile load, and of one older page, for a 900-row
68
-agent turn.
66
+(`apps/server/integration/transferBudgetV2.integration.test.ts`) sends the opt-ins current clients
67
+send and caps the decoded bytes and rows of the bounded snapshot and one older page for a 900-row
68
+agent turn, and of the cold-connect shell for a sidebar of settled threads and idle subagents. When
69
+clients gain an opt-in, add it to the test's client queries and give a fixture the data it saves.
70
71
## Event store and startup
72