Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Two CI flakes: the trace recorder's 50 ms budget and S4's in-test Chrome starts (#5321)

Milind Soni752993d8d089
diff --git a/server/browser/cdp/s4-pages.e2e.test.ts b/server/browser/cdp/s4-pages.e2e.test.ts
index af4e520f43..21625458ae 100644
--- a/server/browser/cdp/s4-pages.e2e.test.ts
+++ b/server/browser/cdp/s4-pages.e2e.test.ts
@@ -34,6 +34,11 @@ suite("S4 pages, tabs and page state on real Chrome", () => {
let page: CdpPage;
let pages = 0;
const extra: RunningChrome[] = [];
+ // The Chromes a test needs with other options. A fresh profile's start takes a start's time (on Windows it also
+ // opens the harness's first page), which a test's own timeout is not for.
+ let limited: RunningChrome;
+ let retina: RunningChrome;
+ let fitted: RunningChrome;
beforeAll(async () => {
fx = await FixtureServer.start();
@@ -41,6 +46,12 @@ suite("S4 pages, tabs and page state on real Chrome", () => {
page = await run.browser.waitForPage();
}, hostTimeout(180_000));
+ beforeAll(async () => {
+ extra.push(limited = await startChrome("limit", { browser: { maxPages: 2 } }));
+ extra.push(retina = await startChrome("retina", { launch: { screen: { width: 1512, height: 982, deviceScaleFactor: 2 } } }));
+ extra.push(fitted = await startChrome("fit", { browser: { viewport: { width: 1366, height: 768 } } }));
+ }, hostTimeout(180_000));
+
afterAll(async () => {
for (const other of extra) await other.close();
await run?.close();
@@ -166,8 +177,6 @@ suite("S4 pages, tabs and page state on real Chrome", () => {
});
it("closes popups past the tab limit", async () => {
- const limited = await startChrome("limit", { browser: { maxPages: 2 } });
- extra.push(limited);
const first = await limited.browser.waitForPage();
let closed = 0;
limited.browser.onPageClosed(() => closed++);
@@ -287,8 +296,6 @@ suite("S4 pages, tabs and page state on real Chrome", () => {
expect(pngSize(full.data)).toEqual({ width: full.width, height: full.height });
expect(full.height).toBeLessThanOrEqual(PICTURE_LIMITS.maxHeight);
expect(full.width * full.height).toBeLessThanOrEqual(PICTURE_LIMITS.maxPixels);
- const retina = await startChrome("retina", { launch: { screen: { width: 1512, height: 982, deviceScaleFactor: 2 } } });
- extra.push(retina);
const sharp = await retina.browser.waitForPage();
await sharp.navigate(serve("<p>retina</p>"));
expect(await sharp.devicePixelRatio()).toBe(2);
@@ -304,8 +311,6 @@ suite("S4 pages, tabs and page state on real Chrome", () => {
});
it("fits each headless window so its page is exactly the viewport asked for", async () => {
- const fitted = await startChrome("fit", { browser: { viewport: { width: 1366, height: 768 } } });
- extra.push(fitted);
const first = await fitted.browser.waitForPage();
await first.navigate(serve("<p>fitted</p>"));
expect(await first.evaluate("[innerWidth, innerHeight]")).toEqual([1366, 768]);
diff --git a/server/usage-trace/recorder.test.ts b/server/usage-trace/recorder.test.ts
index e5908b96f3..c878fbaad8 100644
--- a/server/usage-trace/recorder.test.ts
+++ b/server/usage-trace/recorder.test.ts
@@ -6,6 +6,7 @@ import { monitorEventLoopDelay } from "node:perf_hooks";
import { afterEach, describe, expect, it } from "vitest";
import type { RuntimeEvent } from "../../shared/runtime-events.ts";
import { json, readBody } from "../harness/http.ts";
+import { hostTimeout } from "../testing/host-timeout.ts";
import { createTraceRecorder } from "./recorder.ts";
import { daysBetween, flushSpans, readSpans } from "./spans.ts";
@@ -203,15 +204,24 @@ describe("trace recorder", () => {
if (index % 50 === 0) await new Promise((resolve) => setImmediate(resolve));
}
const end = performance.now();
+ const endCpu = process.threadCpuUsage();
observe(completed("busy", "t1", 20_100));
expect(recorder.settle("busy")).toMatchObject({ tools: 2_000 });
const settleMs = performance.now() - end;
+ const settleCpu = process.threadCpuUsage(endCpu);
+ const settleCpuMs = (settleCpu.user + settleCpu.system) / 1_000;
await flushSpans(dir);
delay.disable();
console.log(`trace recorder: 2,000 tool calls; ${(busyMs * 1000 / 4_002).toFixed(1)} µs per event (${busyMs.toFixed(1)} ms in all), ` +
- `turn end + booking ${settleMs.toFixed(1)} ms, event-loop delay p99 ${(delay.percentile(99) / 1e6).toFixed(1)} ms`);
+ `turn end + booking ${settleMs.toFixed(1)} ms (${settleCpuMs.toFixed(1)} ms on this thread's CPU), ` +
+ `event-loop delay p99 ${(delay.percentile(99) / 1e6).toFixed(1)} ms`);
expect(busyMs / 4_002).toBeLessThan(0.1);
- expect(settleMs).toBeLessThan(50);
+ // The work is held to 50 ms of this thread's CPU, which counts the booking and its garbage collection
+ // but not time the OS gives another process: a CI shard runs several files at once (OMB_VITEST_WORKERS)
+ // and their CPU is shared. The wall clock still catches a blocking wait, at the doubled bound every
+ // timeout has where the CPU is shared or slower (server/testing/host-timeout.ts).
+ expect(settleCpuMs).toBeLessThan(50);
+ expect(settleMs).toBeLessThan(hostTimeout(50));
const spans = (await readSpans(dir, daysBetween(T0, T0 + 30_000), new Set(["busy:t1"]))).get("busy:t1")!;
expect(spans.filter((span) => span.kind === "tool")).toHaveLength(2_000);
});