BlogDebuggingturno-browser

Flaky browser tests and what each one was really measuring

Several turno-browser tests that drive a real Chrome failed now and then on loaded CI runners. Most assumed something that Chrome or the runner does not promise, and two, the popup and parking tests, had caught a real bug.

6 min read

View sourceFeed

Most of turno-browser's test files start a real Chrome and call the tools the way an agent does. CI ran them on macOS and Ubuntu runners (a Windows job was added on 2026-11-22). On 2026-11-19, the day turno-browser 0.4.0 and 0.5.0 came out, five commits fixed browser tests that failed now and then on CI. Two of the commit messages place those failures on macOS runners.

Pointer moves folded into one event

The humanize test checks that, at the full level, the pointer travels a path before a click. The test page counts pointermove events and expects more than 10 before the press. On a loaded runner the count could come up short.

As the test now says in a comment, Chrome fires one pointermove per frame and folds the moves in between into it. A busy renderer can deliver a whole path as one event, so the count followed the frames, not the path. The page now adds the moves folded into each event:

packages/browser/test/humanize-chrome.test.tsTypeScript
  // Chrome fires one pointermove per frame and folds the moves in between into it, so a busy
  // renderer can turn a whole path into a single event: count the moves folded in too.
  addEventListener("pointermove", (e) => { log.moves += e.getCoalescedEvents?.().length || 1; /* ... */ save(); }, true);

The fix is pull request 105, commit 271002d.

A tick count that could not tell busy from throttled

The test for background tabs at full speed loads a page that runs a timer every 4 ms and keeps how many times it ran in each second. It opens a second tab, waits 4 seconds and goes back. The check was that two of the background seconds each had more than 3 ticks.

In the words of commit fda4abb (pull request 103), "A tick threshold could not tell a loaded macOS runner from a throttled tab". A busy CPU starves the timer chain too, and the test's comment puts a throttled tab at 1 to 10 ticks a second. Chrome throttles timers only once the page is hidden, and the page already recorded whether it ever saw itself hidden, which it never should, because focus emulation keeps it visible. The test now relies on that condition alone.

packages/browser/test/browser-tools.test.tsTypeScript
      expect(state).not.toContain("hidden");
      const seconds = (/seconds\\":\\"([\d,]+)/.exec(state)?.[1] ?? "").split(",").map(Number);
      expect(seconds.slice(-4, -1).reduce((a, n) => a + n, 0)).toBeGreaterThan(0); 

The ticks stay only to show that the timer chain kept running. The first fix asked for at least one tick in each background second; later the same day, commit d97dbec (pull request 114) asked for at least one over the whole period, because a runner can starve the chain for a whole second.

A tab still closing when the next call started

The popup test and the parking test failed now and then, and here the tests were right. The tab governor closes popups and parks unused tabs on its own. If it was closing a page when a tool call started, the call could fail with "Target page, context or browser has been closed", because building a result reads every tab.

Since 0.4.0 a call waits for that work before it runs:

packages/browser/src/governor.tsTypeScript
  /**
   * Resolves once nothing the governor started before the call is still in flight: a popup
   * check or a sweep may be closing a page right now, and upstream reads every tab (title,
   * console) to build a result, so a page closing under the call fails it with "Target page,
   * context or browser has been closed". Call after `beginCall`, which keeps new work from
   * starting.
   */
  async quiet(): Promise<void> {
    await Promise.all([...this.adopting, this.sweeping]);
  }

The message of commit 3bd7bc2 (pull request 100) ties this change to the popup and parking flakes, and the 0.4.0 changelog describes it for users.

The parking test still failed now and then, on its own timing. It slept 4 seconds, then 9, and read the tab list once, while the governor runs on a timer that a loaded runner can delay by seconds. Commit 40c5492 (pull request 122), late that day, makes it list the tabs every half second until the park or the close shows, for up to 30 seconds.

One flake had nothing to do with time. The sealed session test seals a payload with a cookie named sid and checked that the file did not contain sid. The ciphertext is base64, which can hold those three letters by chance. The check now looks for the name with its quotes:

packages/browser/test/sealed.test.tsTypeScript
    const text = await seal(PAYLOAD, PASS);
    expect(text).not.toContain("session-value-1234");
    // Quoted: the ciphertext is base64, which has no quotes but can hold "sid" by chance.
    expect(text).not.toContain('"sid"');

Time bounds that became conditions

The tab sharing test proved that two sessions navigate at once by timing them: a /slow page answered after 1.5 seconds, and both navigations had to finish within 10. Since d97dbec, /slow answers only when /b is requested, so the test passes only if the two navigations overlapped:

packages/browser/test/tab-sharing.test.tsTypeScript
    if (path === "/slow") {
      // /slow answers once /b is requested, which only happens if the two navigations run at
      // once; if they ran one after the other, it gives up after 20 seconds and overlapped stays
      // false. No wall-clock bound, so a slow CI runner cannot fail it.
      const timer = setTimeout(send, 20_000);
      releaseSlow = () => {
        clearTimeout(timer);
        releaseSlow = undefined;
        send();
      };
      return;
    }
    if (path === "/b" && releaseSlow) {
      overlapped = true;
      releaseSlow();
    }

The same commits loosened two bounds (4 to 15 seconds for a click, 5 to 9 seconds for a refused tab lock), gave the tab sharing servers a 15-second action timeout instead of upstream's 5, and made CI run two browser test files at a time. The comment in vitest.config.ts gives the reason: on a macOS runner with 3 cores, one Chrome per core starved them all.

Another change reached users. In 0.5.0 the steps before a human-like action, reading the field and aiming at the element, wait up to 3 seconds instead of 1. On a busy machine the shorter wait ran out, and the action fell back to a plain fill or click.

TestWhat was assumedWhat happensThe fix
Humanize at fullone event per pointer moveChrome folds moves between frames into one eventcounts the folded moves
Background tab at full speed3 ticks a second or fewer means throttleda busy CPU starves timers toorelies only on the page never seeing itself hidden
Popup and parkingthe tabs are settled when a call startsthe governor may be closing onethe call waits for the governor; parking polls
Sealed sessionciphertext never contains sidbase64 can hold it by chancelooks for "sid" with quotes
Tab sharingboth navigations finish within 10 secondsa slow runner can take longer/slow answers only once /b is requested

What is still not solved

Some checks still bound wall-clock time, among them the two that were only loosened: 15 seconds for a click on the agent's tab while another tab is in front, and 9 seconds for the refused tab lock. They still assume a runner no slower than that.

The 3-second wait is a limit too. On a machine busier than that, a human-like action still runs as a plain fill or click: the comment on that constant in human-input.ts says that past the wait, Playwright's own call runs.

The repository has no count of how often these tests failed before and after the fixes, so this post cannot say by how much CI got steadier.