Skip to content

Commit a7c675c

Browse files
Merge remote-tracking branch 'origin/main' into takeover/pr-14496
2 parents 60e3e65 + 5a969c1 commit a7c675c

38 files changed

Lines changed: 1621 additions & 349 deletions

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ import {
1111
TRANSFER_MEASURED_MCP_RESULT_BYTES,
1212
TRANSFER_MEASURED_TOOLS,
1313
} from "./fixtures/transferBudget.ts";
14+
import { LONG_TURN_WORK_ROWS } from "./TransferBudgetV2Fixture.integration.ts";
1415

1516
export interface WebSocketCatchUpMeasurement extends WebSocketTransferTotals {
1617
readonly mode: "replay" | "snapshot";
1718
}
1819

20+
export interface TimelineHttpMeasurement {
21+
readonly http: HttpTransferMeasurement;
22+
readonly rows: number;
23+
}
24+
1925
export interface TransferBudgetRun {
2026
readonly provider: ProviderDriverKind;
2127
readonly threadSnapshot: HttpTransferMeasurement;
@@ -27,6 +33,9 @@ export interface TransferBudgetRun {
2733
readonly reconnectShell: WebSocketCatchUpMeasurement;
2834
readonly measuredTurnSqlStatements: number;
2935
readonly reconnectSqlStatements: number;
36+
/** The compact bounded snapshot web and mobile load when the long-turn thread opens. */
37+
readonly longTurnColdOpen: TimelineHttpMeasurement;
38+
readonly longTurnHistoryPage: TimelineHttpMeasurement;
3039
}
3140

3241
interface ProviderTransferBudget {
@@ -50,6 +59,15 @@ const TRANSFER_BUDGETS: Readonly<Record<string, ProviderTransferBudget>> = {
5059
claudeAgent: TRANSFER_BUDGET,
5160
};
5261

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.
66+
const LONG_TURN_BUDGET = {
67+
decodedBytes: 120_000,
68+
rows: 75,
69+
};
70+
5371
function totalWireBytes(run: TransferBudgetRun): number {
5472
return run.threadSnapshot.wireBytes + run.measuredTurnWebSocket.wireBytes;
5573
}
@@ -144,6 +162,24 @@ function webSocketRows(
144162
];
145163
}
146164

165+
function longTurnRows(
166+
provider: ProviderDriverKind,
167+
phase: string,
168+
measured: TimelineHttpMeasurement,
169+
): string[] {
170+
return [
171+
infoRow(provider, phase, "HTTP wire", measured.http.wireBytes),
172+
row(
173+
provider,
174+
phase,
175+
"HTTP decoded",
176+
measured.http.decodedBodyBytes,
177+
LONG_TURN_BUDGET.decodedBytes,
178+
),
179+
row(provider, phase, "rows", measured.rows, LONG_TURN_BUDGET.rows, String),
180+
];
181+
}
182+
147183
export function transferBudgetViolations(runs: ReadonlyArray<TransferBudgetRun>): string[] {
148184
const violations: string[] = [];
149185
for (const run of runs) {
@@ -170,6 +206,18 @@ export function transferBudgetViolations(runs: ReadonlyArray<TransferBudgetRun>)
170206
run.measuredTurnWebSocket.messages,
171207
budget.measuredTurnWebSocketMessages,
172208
],
209+
[
210+
"long-turn cold open decoded bytes",
211+
run.longTurnColdOpen.http.decodedBodyBytes,
212+
LONG_TURN_BUDGET.decodedBytes,
213+
],
214+
["long-turn cold open rows", run.longTurnColdOpen.rows, LONG_TURN_BUDGET.rows],
215+
[
216+
"long-turn history page decoded bytes",
217+
run.longTurnHistoryPage.http.decodedBodyBytes,
218+
LONG_TURN_BUDGET.decodedBytes,
219+
],
220+
["long-turn history page rows", run.longTurnHistoryPage.rows, LONG_TURN_BUDGET.rows],
173221
] as const;
174222
for (const [metric, observed, maximum] of checks) {
175223
if (observed > maximum) {
@@ -187,6 +235,7 @@ export function formatTransferBudgetReport(runs: ReadonlyArray<TransferBudgetRun
187235
"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.",
188236
"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.",
189237
`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.`,
238+
`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.`,
190239
"",
191240
"| Provider | Total thread wire | Budget | Result |",
192241
"| --- | ---: | ---: | --- |",
@@ -264,6 +313,8 @@ export function formatTransferBudgetReport(runs: ReadonlyArray<TransferBudgetRun
264313
run.reconnectShell,
265314
),
266315
infoRow(run.provider, "reconnect", "SQL statements", run.reconnectSqlStatements, String),
316+
...longTurnRows(run.provider, "long-turn cold open", run.longTurnColdOpen),
317+
...longTurnRows(run.provider, "long-turn history page", run.longTurnHistoryPage),
267318
);
268319
}
269320

‎apps/server/integration/TransferBudgetV2Fixture.integration.ts‎

Lines changed: 232 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {
2+
CheckpointId,
3+
CheckpointScopeId,
24
EventId,
35
MessageId,
46
NodeId,
@@ -9,6 +11,7 @@ import {
911
TurnItemId,
1012
type ProviderDriverKind,
1113
type OrchestrationV2DomainEvent,
14+
type OrchestrationV2TurnItem,
1215
} from "@t3tools/contracts";
1316
import * as DateTime from "effect/DateTime";
1417
import {
@@ -20,15 +23,18 @@ import {
2023
} from "./fixtures/transferBudget.ts";
2124

2225
export const THREAD_ID = ThreadId.make("transfer-budget-thread");
23-
export function threadCreated(provider: ProviderDriverKind): OrchestrationV2DomainEvent {
26+
export function threadCreated(
27+
provider: ProviderDriverKind,
28+
threadId: ThreadId = THREAD_ID,
29+
): OrchestrationV2DomainEvent {
2430
const now = DateTime.makeUnsafe("2026-06-01T00:00:00Z");
2531
return {
26-
id: EventId.make("thread-created"),
32+
id: EventId.make(`thread-created:${threadId}`),
2733
type: "thread.created",
28-
threadId: THREAD_ID,
34+
threadId,
2935
occurredAt: now,
3036
payload: {
31-
id: THREAD_ID,
37+
id: threadId,
3238
projectId: ProjectId.make("transfer-project"),
3339
title: "Transfer budget",
3440
providerInstanceId: ProviderInstanceId.make(provider),
@@ -41,7 +47,7 @@ export function threadCreated(provider: ProviderDriverKind): OrchestrationV2Doma
4147
branch: null,
4248
worktreePath: null,
4349
activeProviderThreadId: null,
44-
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: THREAD_ID },
50+
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
4551
forkedFrom: null,
4652
createdBy: "user",
4753
creationSource: "web",
@@ -179,3 +185,224 @@ export function turnEvents(
179185
});
180186
return events;
181187
}
188+
189+
export const LONG_TURN_THREAD_ID = ThreadId.make("transfer-budget-long-turn");
190+
export const LONG_TURN_WORK_ROWS = 900;
191+
192+
/**
193+
* Three short user turns, then one agent turn far longer than a cold-open
194+
* window, with the item kinds a long agent run produces. One batch per turn.
195+
*/
196+
export function longTurnThreadBatches(
197+
provider: ProviderDriverKind,
198+
): ReadonlyArray<ReadonlyArray<OrchestrationV2DomainEvent>> {
199+
const threadId = LONG_TURN_THREAD_ID;
200+
const providerInstanceId = ProviderInstanceId.make(provider);
201+
const modelSelection = {
202+
instanceId: providerInstanceId,
203+
model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
204+
};
205+
let ordinal = 0;
206+
const text = (turn: number, row: number, targetBytes: number) =>
207+
diagnosticOutput({ provider, turnIndex: 100 + turn, toolIndex: row, targetBytes });
208+
209+
const turn = (index: number, workRows: number): OrchestrationV2DomainEvent[] => {
210+
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}`);
213+
const common = {
214+
threadId,
215+
runId,
216+
nodeId,
217+
driver: provider,
218+
providerInstanceId,
219+
occurredAt: now,
220+
};
221+
const run = {
222+
id: runId,
223+
threadId,
224+
ordinal: index + 1,
225+
providerInstanceId,
226+
modelSelection,
227+
providerThreadId: null,
228+
userMessageId: MessageId.make(`long-turn-user-${index}`),
229+
rootNodeId: nodeId,
230+
activeAttemptId: null,
231+
status: "running" as const,
232+
requestedAt: now,
233+
startedAt: now,
234+
completedAt: null,
235+
checkpointId: null,
236+
contextHandoffId: null,
237+
};
238+
const base = (row: string, title: string | null) => {
239+
ordinal += 1;
240+
return {
241+
id: TurnItemId.make(`long-turn-item-${index}-${row}`),
242+
threadId,
243+
runId,
244+
nodeId,
245+
providerThreadId: null,
246+
providerTurnId: null,
247+
nativeItemRef: null,
248+
parentItemId: null,
249+
ordinal,
250+
status: "completed" as const,
251+
title,
252+
startedAt: now,
253+
completedAt: now,
254+
updatedAt: now,
255+
};
256+
};
257+
const events: OrchestrationV2DomainEvent[] = [
258+
{ ...common, id: EventId.make(`long-turn-run-${index}`), type: "run.created", payload: run },
259+
];
260+
const message = (role: "user" | "assistant", row: string, messageText: string) => {
261+
const messageId = MessageId.make(`long-turn-${role}-${index}-${row}`);
262+
const createdBy = role === "user" ? ("user" as const) : ("agent" as const);
263+
events.push(
264+
{
265+
...common,
266+
id: EventId.make(`long-turn-message-${index}-${row}`),
267+
type: "message.updated",
268+
payload: {
269+
id: messageId,
270+
threadId,
271+
runId,
272+
nodeId,
273+
role,
274+
text: messageText,
275+
attachments: [],
276+
streaming: false,
277+
createdAt: now,
278+
updatedAt: now,
279+
createdBy,
280+
creationSource: "web",
281+
},
282+
},
283+
{
284+
...common,
285+
id: EventId.make(`long-turn-item-event-${index}-${row}`),
286+
type: "turn-item.updated",
287+
payload:
288+
role === "user"
289+
? {
290+
...base(row, null),
291+
type: "user_message",
292+
createdBy,
293+
creationSource: "web",
294+
messageId,
295+
inputIntent: "turn_start",
296+
text: messageText,
297+
attachments: [],
298+
}
299+
: {
300+
...base(row, null),
301+
type: "assistant_message",
302+
messageId,
303+
text: messageText,
304+
streaming: false,
305+
},
306+
},
307+
);
308+
};
309+
const workItem = (row: number): OrchestrationV2TurnItem => {
310+
if (row % 100 === 50) {
311+
return {
312+
...base(String(row), "Checkpoint"),
313+
type: "checkpoint",
314+
checkpointId: CheckpointId.make(`long-turn-checkpoint-${index}-${row}`),
315+
scopeId: CheckpointScopeId.make(`long-turn-scope-${index}`),
316+
files: Array.from({ length: 40 }, (_, file) => ({
317+
path: `src/feature/module-${row}-${file}.ts`,
318+
kind: "modified",
319+
additions: file + 1,
320+
deletions: file,
321+
})),
322+
};
323+
}
324+
if (row % 100 === 99) {
325+
return {
326+
...base(String(row), "Subagent"),
327+
type: "subagent",
328+
subagentId: NodeId.make(`long-turn-subagent-${index}-${row}`),
329+
origin: "app_owned",
330+
driver: provider,
331+
providerInstanceId,
332+
childThreadId: null,
333+
prompt: text(index, row, 2_048),
334+
result: text(index, row + 1, 3_072),
335+
};
336+
}
337+
switch (row % 8) {
338+
case 0:
339+
case 7:
340+
return {
341+
...base(String(row), "Reasoning"),
342+
type: "reasoning",
343+
text: text(index, row, 1_536),
344+
streaming: false,
345+
};
346+
case 3:
347+
return {
348+
...base(String(row), `Edit module ${row}`),
349+
type: "file_change",
350+
fileName: `src/feature/module-${row}.ts`,
351+
additions: 12,
352+
deletions: 4,
353+
diffStr: text(index, row, 2_048),
354+
};
355+
case 4:
356+
return {
357+
...base(String(row), "MCP search"),
358+
type: "dynamic_tool",
359+
toolName: "mcp__test__search",
360+
input: { query: `module ${row}` },
361+
output: { text: text(index, row, 6_144) },
362+
};
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+
};
371+
default:
372+
return {
373+
...base(String(row), `Run check ${row}`),
374+
type: "command_execution",
375+
input: `vp test run src/feature/module-${row}.test.ts`,
376+
output: text(index, row, 4_096),
377+
exitCode: 0,
378+
};
379+
}
380+
};
381+
382+
message("user", "prompt", `Continue the feature work, step ${index}.`);
383+
for (let row = 0; row < workRows; row++) {
384+
events.push({
385+
...common,
386+
id: EventId.make(`long-turn-work-${index}-${row}`),
387+
type: "turn-item.updated",
388+
payload: workItem(row),
389+
});
390+
}
391+
message("assistant", "answer", text(index, workRows, 1_200));
392+
events.push({
393+
...common,
394+
id: EventId.make(`long-turn-complete-${index}`),
395+
type: "run.updated",
396+
payload: { ...run, status: "completed", completedAt: now },
397+
});
398+
return events;
399+
};
400+
401+
return [
402+
[threadCreated(provider, threadId)],
403+
turn(0, 4),
404+
turn(1, 4),
405+
turn(2, 4),
406+
turn(3, LONG_TURN_WORK_ROWS),
407+
];
408+
}

0 commit comments

Comments
 (0)