Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions apps/server/integration/transferBudgetV2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ const CLIENT_HISTORY_OPT_INS = { compactIds: "1", deferWork: "1" } satisfies Req
const CLIENT_SHELL_OPT_INS = {
omitIdleSubagents: "1",
omitOlderSettled: "1",
compactShell: "1",
compactIds: "1",
} satisfies Required<Omit<typeof EnvironmentOrchestrationShellSnapshotQuery.Type, "resumeFrom">>;
const CLIENT_THREAD_SUBSCRIPTION = {
requestCompletionMarker: true,
Expand All @@ -127,6 +129,9 @@ const CLIENT_SHELL_SUBSCRIPTION = {
requestCompletionMarker: true,
omitIdleSubagents: true,
omitOlderSettled: true,
compactShell: true,
compactIds: true,
acceptShellDeltas: true,
} satisfies Required<Omit<OrchestrationV2SubscribeShellInput, ShellResumeField>>;
const query = (optIns: Readonly<Record<string, string>>) => new URLSearchParams(optIns).toString();
const CLIENT_BOUNDED_QUERY = query(CLIENT_BOUNDED_OPT_INS);
Expand Down Expand Up @@ -365,7 +370,7 @@ it.live("reports V2 thread HTTP and WebSocket transfer budgets", () =>
assert.equal(decodedThread.projection.turnItems.length, TRANSFER_HISTORY_TURN_COUNT * 6);
assert.notInclude(Buffer.from(threadSnapshot.decodedBody).toString(), "digest=");
const shellSnapshot = yield* measureHttpGet({
url: `${base}/api/orchestration/shell`,
url: `${base}/api/orchestration/shell?${CLIENT_SHELL_QUERY}`,
headers: { [ORCHESTRATION_PROTOCOL_HEADER]: String(ORCHESTRATION_PROTOCOL_VERSION) },
});
assert.equal(shellSnapshot.status, 200);
Expand Down Expand Up @@ -400,8 +405,26 @@ it.live("reports V2 thread HTTP and WebSocket transfer budgets", () =>
// shells are skipped, so a turn split across batches may never yield an item at
// the last sequence. Wait for the final shell instead.
const finalShell = yield* projection.getThreadShell(THREAD_ID);
const shellTerminal = (item: StreamItem) =>
item.kind === "thread.updated" && NodeUtil.isDeepStrictEqual(item.thread, finalShell);
if (finalShell === null) return yield* Effect.die("Expected final thread shell");
const initialShell = decodedShell.threads[0];
if (initialShell === undefined) return yield* Effect.die("Expected initial thread shell");
const makeShellTerminal = () => {
let current = initialShell;
return (item: StreamItem) => {
if (item.kind === "thread.updated" && item.thread.id === THREAD_ID) {
current = item.thread;
} else if (item.kind === "thread.patched" && item.threadId === THREAD_ID) {
const patched: Record<string, unknown> = { ...current };
for (const [key, value] of Object.entries(item.patch)) {
if (value !== undefined) patched[key] = value;
}
current = patched as typeof current;
} else {
return false;
}
return NodeUtil.isDeepStrictEqual(current, finalShell);
};
};
const liveTurn = yield* collectUntil(tq, threadTerminal);
yield* collectUntil(ttq, threadTerminal);
// A direct check, so live dedupe stays guarded however small the turn gets.
Expand All @@ -414,7 +437,7 @@ it.live("reports V2 thread HTTP and WebSocket transfer budgets", () =>
);
assert.equal(liveAnswer.length, 1);
assert.equal(liveAnswer[0]!.textOmitted, true);
for (const queue of [sq, ssq]) yield* collectUntil(queue, shellTerminal);
for (const queue of [sq, ssq]) yield* collectUntil(queue, makeShellTerminal());
const measuredTurnWebSocket = difference(thread.recorder.totals(), threadBefore);
const measuredTurnShellWebSocket = difference(shell.recorder.totals(), shellBefore);
const measuredTurnSecondClientWebSocket = difference(
Expand Down
Loading
Loading