Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Retry a stalled Chromium launch in browser test fixtures

Claudeff8f2a3a675c
diff --git a/client/src/test/README.md b/client/src/test/README.md
index e8212cd3da..89bea1442f 100644
--- a/client/src/test/README.md
+++ b/client/src/test/README.md
@@ -10,7 +10,7 @@ a new one.
| --- | --- |
| `actWarnings.js` | React act(...) warning diagnostics — records the test active when a warning was observed, without claiming to identify where asynchronous work began. |
| `ariaRefAssertions.js` | Asserts a rendered tree's `aria-controls`/`aria-labelledby` IDREFs all resolve to a real element. |
-| `browserFixture.js` | `startBrowserFixture` — phase-bounded Vite + Chromium + warmup startup for `*.browser.test.js`, naming the stalled phase and closing everything it started. |
+| `browserFixture.js` | `startBrowserFixture` — phase-bounded Vite + Chromium + warmup startup for `*.browser.test.js` (a stalled Chromium launch is retried once with a fresh process), naming the stalled phase and closing everything it started. |
| `classNameScan.js` | Shared string-literal scanner (comment-stripping + literal walk) for the class-string convention guards. |
| `dndKeyboardDrag.js` | Drives a real `@dnd-kit` keyboard drag under happy-dom, stubbing the layout happy-dom can't provide. |
| `downloadPreflightConfirm.js` | `clickStartDownload` — waits for the confirm button to be enabled (built on `enabledBarrier.js`) before clicking, then settles. |
diff --git a/client/src/test/browserFixture.js b/client/src/test/browserFixture.js
index 399341a8aa..c1f3bb74b2 100644
--- a/client/src/test/browserFixture.js
+++ b/client/src/test/browserFixture.js
@@ -24,6 +24,18 @@
* to what the fixture renders: `entries` names the real source files and
* `include` the bare imports of the virtual fixture module (which the scanner
* cannot see; leaving them to runtime discovery forces a re-optimize + reload).
+ *
+ * The Chromium launch is the other phase that stalls on CI (#10635), and only
+ * there: locally it takes 0.6–1.7s even with a cold page cache and every core
+ * busy, while on a GitHub runner two first launches timed out together at 15s
+ * with Vite already up in under 100ms. The DB-suite launcher caught the same
+ * stall in the act (#9641): Chrome alive in uninterruptible sleep, waiting on
+ * page faults, under heavy I/O pressure. That points to a runner whose disk
+ * stalls, not a launch that needs more CPU, so the launch gets two attempts: a
+ * first one killed at half the phase, and a fresh process for the rest. The
+ * pages the first attempt did read stay in the kernel's cache, so a slow disk
+ * loses no progress, and a child that wedged is replaced rather than waited
+ * on. Vite's budget pays for it: it starts in well under 2s even under load.
*/
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
@@ -32,14 +44,16 @@ import { join } from 'node:path';
export const BROWSER_FIXTURE_STARTUP_MS = 60000;
export const BROWSER_FIXTURE_PHASE_MS = Object.freeze({
- vite: 10000,
- chromium: 15000,
+ vite: 5000,
+ chromium: 24000,
warmup: 25000,
cleanup: 5000,
});
const PHASE_NAMES = { vite: 'Vite server start', chromium: 'Chromium launch', warmup: 'first page warmup' };
+const timeoutError = ms => Object.assign(new Error(`timed out after ${ms}ms`), { name: 'TimeoutError' });
+
const withDeadline = (promise, ms, onTimeout) => {
let timer;
const deadline = new Promise((_, reject) => {
@@ -85,14 +99,37 @@ export async function startBrowserFixture({
if (errors.length) throw new Error(errors.join('; '));
};
let phase;
+ // Appended to the phase's timing or timeout once its work had to retry.
+ let retried = '';
const runPhase = async (key, work) => {
phase = key;
const started = Date.now();
- const value = await withDeadline(Promise.resolve().then(work), phaseMs[key],
- () => new Error(`timed out after ${phaseMs[key]}ms`));
- completed.push(`${PHASE_NAMES[key]} ${Date.now() - started}ms`);
+ const value = await withDeadline(Promise.resolve().then(work), phaseMs[key], () => {
+ const error = timeoutError(phaseMs[key]);
+ error.message += retried;
+ return error;
+ });
+ completed.push(`${PHASE_NAMES[key]} ${Date.now() - started}ms${retried}`);
+ retried = '';
return value;
};
+ // One Chromium process. A browser that arrives after its attempt was
+ // abandoned is closed at once; one that arrives in time joins `own`, which
+ // closes it at once if the fixture has failed meanwhile.
+ const launchOnce = (timeout) => {
+ let abandoned = false;
+ const launching = chromium.launch({
+ headless: true,
+ timeout,
+ ...launchOptions,
+ env: { ...process.env, ...launchOptions.env, TMPDIR: temp, TMP: temp, TEMP: temp },
+ }).then((launched) => {
+ if (abandoned) launched.close().catch(() => {});
+ else own(() => launched.close());
+ return launched;
+ });
+ return { launching, abandon: () => { abandoned = true; } };
+ };
try {
const server = await runPhase('vite', async () => {
@@ -112,16 +149,20 @@ export async function startBrowserFixture({
});
const origin = server.resolvedUrls.local[0];
const browser = await runPhase('chromium', async () => {
- // Playwright's own launch timeout kills the child it spawned; the phase
- // deadline above is the backstop if that kill itself hangs.
- const launched = await chromium.launch({
- headless: true,
- timeout: phaseMs.chromium,
- ...launchOptions,
- env: { ...process.env, ...launchOptions.env, TMPDIR: temp, TMP: temp, TEMP: temp },
- });
- own(() => launched.close());
- return launched;
+ // Playwright's own launch timeout kills the child it spawned; each
+ // deadline here is the backstop if that kill itself hangs. Only a
+ // timeout earns the retry: a launch that fails outright (missing
+ // executable, crash) fails the same way twice.
+ const firstMs = Math.floor(phaseMs.chromium / 2);
+ const first = launchOnce(firstMs);
+ try {
+ return await withDeadline(first.launching, firstMs, () => timeoutError(firstMs));
+ } catch (error) {
+ if (error.name !== 'TimeoutError') throw error;
+ first.abandon();
+ retried = ` (retried after a first attempt timed out after ${firstMs}ms)`;
+ }
+ return launchOnce(phaseMs.chromium - firstMs).launching;
});
if (warmup) {
await runPhase('warmup', async () => {
@@ -133,6 +174,9 @@ export async function startBrowserFixture({
}
});
}
+ // Passing runs record their phase timings too, so CI logs show how close
+ // each budget runs before one of them fails.
+ console.log(`🧪 ${name} browser fixture ready (${completed.join(', ')})`);
return { origin, browser, server, temp, close: closeOwned };
} catch (error) {
failed = true;
diff --git a/client/src/test/browserFixture.test.js b/client/src/test/browserFixture.test.js
index 8c0aa48b2e..bbe0490e7b 100644
--- a/client/src/test/browserFixture.test.js
+++ b/client/src/test/browserFixture.test.js
@@ -14,24 +14,58 @@ const fakeVite = () => {
const fakeBrowser = (page) => ({ close: vi.fn(async () => {}), newPage: vi.fn(async () => page) });
describe('startBrowserFixture', () => {
- it('names a stalled Chromium launch, closes Vite, and closes a browser that arrives late', async () => {
+ it('retries a stalled Chromium launch once, then names the phase and closes every browser that arrives late', async () => {
const { server, createServer } = fakeVite();
- const late = fakeBrowser();
- let arrive;
- const chromium = { launch: vi.fn(() => new Promise(resolve => { arrive = () => resolve(late); })) };
+ const late = [fakeBrowser(), fakeBrowser()];
+ const arrive = [];
+ const chromium = { launch: vi.fn(() => new Promise(resolve => {
+ const browser = late[arrive.length];
+ arrive.push(() => resolve(browser));
+ })) };
let temp;
const viteConfig = vi.fn(dir => { temp = dir; return SCOPED; });
const error = await startBrowserFixture({ name: 'example', createServer, viteConfig, chromium, phaseMs: PHASE_MS })
.catch(caught => caught);
- expect(error.message).toMatch(/^example startup failed during Chromium launch: timed out after 50ms \(completed: Vite server start \d+ms; cleaned up\)$/);
+ expect(error.message).toMatch(/^example startup failed during Chromium launch: timed out after 50ms \(retried after a first attempt timed out after 25ms\) \(completed: Vite server start \d+ms; cleaned up\)$/);
expect(server.close).toHaveBeenCalledTimes(1);
expect(existsSync(temp)).toBe(false);
- expect(chromium.launch.mock.calls[0][0]).toMatchObject({ timeout: 50, env: { TMPDIR: temp } });
+ // Each attempt is a fresh process whose own launch timeout kills it.
+ expect(chromium.launch.mock.calls.map(([options]) => options.timeout)).toEqual([25, 25]);
+ expect(chromium.launch.mock.calls[1][0]).toMatchObject({ env: { TMPDIR: temp } });
+
+ arrive[1]();
+ arrive[0]();
+ await vi.waitFor(() => {
+ expect(late[0].close).toHaveBeenCalledTimes(1);
+ expect(late[1].close).toHaveBeenCalledTimes(1);
+ });
+ });
+ it('uses the retried launch and closes the first one when it arrives late', async () => {
+ const { server, createServer } = fakeVite();
+ const stalled = fakeBrowser();
+ const retried = fakeBrowser();
+ let arrive;
+ const chromium = { launch: vi.fn()
+ .mockReturnValueOnce(new Promise(resolve => { arrive = () => resolve(stalled); }))
+ .mockResolvedValueOnce(retried) };
+ const log = vi.spyOn(console, 'log').mockImplementation(() => {});
+
+ const fixture = await startBrowserFixture({ name: 'example', createServer, viteConfig: () => SCOPED, chromium,
+ phaseMs: PHASE_MS });
+
+ expect(fixture.browser).toBe(retried);
+ expect(log).toHaveBeenCalledWith(expect.stringMatching(/Chromium launch \d+ms \(retried after a first attempt timed out after 25ms\)/));
+ log.mockRestore();
arrive();
- await vi.waitFor(() => expect(late.close).toHaveBeenCalledTimes(1));
+ await vi.waitFor(() => expect(stalled.close).toHaveBeenCalledTimes(1));
+
+ await fixture.close();
+ expect(retried.close).toHaveBeenCalledTimes(1);
+ expect(server.close).toHaveBeenCalledTimes(1);
+ expect(existsSync(fixture.temp)).toBe(false);
});
it('names a stalled Vite start and never listens on a server that arrives late', async () => {