Skip to content

ci: repeat a PR's changed Vitest browser, layout and story specs in the pinned container #4116

Closed

Description

@schlessera

Context

#4109/#4134 delivered a pre-merge gate that repeats the Bun test files a pull request adds or modifies under CPU load (bun scripts/test-determinism.ts, the hosted determinism job). It covers only files that bun test discovers under packages/ and tests/.

The browser, layout, endurance and story specs are outside it. They run in Vitest 4.1.11 inside the pinned browser container, through scripts/visual.mjs (test:browser, test:layout and test:endurance in package.json:20-23), in the post-merge browser, layout and endurance categories. A racy wait added to one of those specs still runs once, after merge, on the squash's main run.

Decided (maintainer, 2026-11-17): C, measure first. This issue is now a spike. Its deliverable is the measurement and a recommended A (keep post-merge) or B (add a pre-merge job); the ruling on pre-merge cost follows from it.

Scope

Measure, against the installed Vitest and the pinned browser container, and report on this issue:

  • Repetition. Whether a spec file can be rerun several times with fresh browser state, and by which mechanism (the repeats option in the installed type declarations, a CLI flag, or separate invocations). State what state carries over between repetitions for each.
  • Cost. Seconds for the first run and for each further repetition, for at least one representative *.visual.tsx, *.pointer.tsx, *.layout.tsx and *.stories.tsx file, separating container and browser start-up from the spec itself.
  • Load. Whether CPU burners outside the container slow the browser processes inside it, and what it takes to put the browser under load if they do not. Reproduce one known hosted-only race from a closed red-main incident if one is cheap to set up.
  • Demand. Over the 150 most recent merges, how many changed a spec, and the estimated job duration distribution at two and five repetitions from scripts/browser-shard-costs.json and the measured ratio.
  • Files. Which patterns count, and whether a changed spec helper should select its specs.

Out of scope

Acceptance criteria

  • A comment on this issue reports each measurement above with its method, the exact Vitest version and image identity, where it ran (this host or a hosted runner) and its limits.
  • The comment recommends A or B. For B it proposes a repetition count, a budget, the cadences it runs at and its expected effect on the merge lease.
  • Anything that could not be measured is named as unknown, not estimated silently.

Verification

  • The commands in the comment reproduce its numbers.

Contract impact

None. CI tooling only.

2026-11-17 triage at main d974052166f335cbf57b385fddc13875da1b98de: Verified delivered #4109/#4134 and the fresh-proof supersession. The existing A/B/C prompt still applies: a Vitest pre-merge extension needs its own ruling, and the recommendation to measure first is not approval.

2026-11-17: the maintainer chose C (measure first); the body now describes the spike.

Activity

  1. added
    type: chore
    area: ci
    on Nov 17, 2026
  2. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Decision needed (triage, 2026-11-17). Should a PR's changed Vitest browser, layout, endurance and story specs be repeated before merge?

    Under the hybrid ruling, those categories run only after merge. Any pre-merge repetition is a new pre-merge browser cost, so it needs a ruling first.

    • A. No. Keep them post-merge only. Close this issue with a documented no, and add a sentence to the hybrid ruling saying a racy wait in a changed spec is caught by the squash's main run. Cost: such a wait still reaches main once.
    • B. Yes, unconditionally. A pre-merge job repeats the changed specs in the pinned container whenever a PR changes one, on its own budget weighted by scripts/browser-shard-costs.json. Cost: a new pre-merge browser job on every PR that touches a spec.
    • C. Measure first, then rule A or B. A bounded investigation answers the factual questions in Scope against the installed Vitest: what repeats does to browser state, the cost per repetition in the container, and whether runner load reaches the browser processes. The ruling then follows from the evidence.

    Recommendation (not approval): C. Those questions are facts an agent can measure, and the ruling on pre-merge cost is better made with the cost known. If C is chosen, the issue becomes a spike whose deliverable is the measurement plus a recommended A/B.

    Completion evidence: a **Decision (maintainer, <date>):** comment choosing A, B or C. Acceptance criteria then follow from that choice.

  3. added
    priority: p2
    needs: decision
    on Nov 17, 2026
  4. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-11-17): C, measure first. This issue becomes a spike: measure repetition, cost, load and demand against the installed Vitest and the pinned container, report here, and recommend A or B. The ruling on a pre-merge browser job follows from that evidence. Nothing merges from the spike.

  5. added
    type: spike
    agent-ready
    and removed
    type: chore
    needs: decision
    on Nov 17, 2026
  6. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Spike report: repeating changed Vitest browser, layout and story specs before merge

    Recommendation: B, in a bounded form. Add a pre-merge job that repeats a pull request's changed specs in the pinned container, with CPU burners running inside the container. Details and the proposed bounds are under Recommendation. What stays unknown is under Unknown.

    What was measured, and where

    • Vitest 4.1.11 (vitest, @vitest/browser, @vitest/browser-playwright and @vitest/runner all at 4.1.11 in node_modules), Playwright 1.63.0.
    • Image mcr.microsoft.com/playwright@sha256:eff16c30e6f3f4af0a03fa4b706120d5e9b0891c344a27d64559aff5900a4a27 (diagramProducerImageIdentity, scripts/diagram-export-producer.mjs:11, asserted by tests/browser-image-pin.test.ts). Node v24.20.0 inside it.
    • Tree: main at e2a233e7e. The repetition probe in section 1 ran one commit earlier, at 49b6e7c48.
    • Hosted: ubuntu-24.04, 4 vCPUs, 15.7 GB, runs 44049769708 and 44051630821. Both come from the unmerged branch spike/4116-browser-repeat-measure, whose own workflow ran on pushes to that branch only. Each number below from these runs is one run.
    • Local: a shared 16-thread development host with rootless Docker and cgroup v2. The container and the burners were pinned to four of its slower cores (taskset in the container, CPUAffinity outside), so Node saw four CPUs. Other work ran on the remaining cores at the same time. Local seconds are not runner seconds; the hosted run is the reference for cost.
    • Nothing merges. Every script is on the measurement branch under scripts/measure-4116/.

    1. Repetition: what each mechanism reruns and what carries over

    Method: a throwaway probe spec in the visual project (and a copy matched by the three rail-* projects) counted its own invocations in module scope, on globalThis, on the orchestrator page (window.parent), in localStorage, sessionStorage, a cookie, IndexedDB and leftover DOM, and reported performance.timeOrigin and the Vitest session id. It ran in the pinned container under each mechanism. Source read: runTest in node_modules/@vitest/runner/dist/chunk-artifact.js and TestOptions in node_modules/@vitest/runner/dist/tasks.d-*.d.ts.

    Mechanism Fresh for each repetition Carries over
    repeats, the option in the type declarations Only beforeEach/afterEach and test-scoped fixtures. Everything else: the same document (identical timeOrigin), module state, globalThis, leftover DOM, all storage, beforeAll state.
    A further pass in the same Vitest process (rerunTestSpecifications() from vitest/node) The tester iframe: a new document, the module evaluated again, globalThis, DOM, beforeAll. The browser process, its context and orchestrator page; cookies, localStorage, sessionStorage, IndexedDB; Node-side state of the browser commands; the Vite server.
    Separate vitest run invocations in one container Everything in the browser and in Node. Disk only: the Vite dependency cache in packages/ui-kit/node_modules/.vite, the mounted temp directory, __screenshots__.
    Separate containers (scripts/visual.mjs once per repetition) As above, plus the container's own filesystem. The mounted repository and temp directory.
    • repeats is a per-test option only. The runner copies it from the test's own options (repeats: options.repeats), with no config fallback, where retry has one (options.retry ?? runner.config.retry). The CLI has --retry and no repeat flag. Repeating unedited specs with it would need a source transform.
    • repeats loops each test by itself: test A runs n times, then test B. The file never reruns as a unit. repeats: 2 gave three runs and the reporter counted one test. A repetition that fails leaves the test failed and the remaining repetitions still run; the report says (repeat x3) but not which repetition failed.
    • Naming the same file twice on the command line runs it once.
    • A further in-process pass has the isolation two consecutive files already have today. Two probe files in one ordinary run shared exactly the same things (storage, cookies, the orchestrator page) and nothing else.
    • One project per repetition was not built, because it needs a config change. The three rail-* projects show how it would behave: each had its own browser session and storage, and they ran at the same time, so the repetitions would compete with each other for CPU.

    2. Cost

    Method: scripts/measure-4116/rerun.mjs starts Vitest once through vitest/node, runs the spec, then reruns it in the same process, printing the wall time of each step. One container per spec, no load, --browser.fileParallelism=false as in scripts/visual.mjs. Hosted run 44049769708, seconds:

    Spec (project) Vitest and Vite start First pass of which the spec Each further pass Recorded weight
    contact-card-fact-keys.visual.tsx (visual) 3.3 4.9 3.1 3.1 6.1
    dictation-notice.pointer.tsx (rail-fine) 3.3 13.3 10.4 10.8 23.0
    handoff-sheet.layout.tsx (ui-react-layout) 3.4 6.8 3.8 4.2 3.6
    SearchResultCard.stories.tsx (storybook) 3.4 4.6 1.7 1.6 2.5
    • A further pass costs the spec's own time. The first pass adds 1.8 to 3.0 s for the browser launch and the first transform.
    • Job start-up on the runner, before any spec: set-up, checkout, Bun and install 16 s; workspace build 94 s; image pull 17 s; font check 0.5 s; container start and exit 0.1 s. About 2 minutes 15 seconds, of which the build is 70%.
    • A separate scripts/visual.mjs invocation of the visual spec took 14.9 s cold and 13.4 s with a warm dependency cache, for a spec of 3.1 s: about 10 s of overhead per separate invocation.
    • A separate vitest run in one container was not timed as a loop. From the table it costs the start (3.3 s) plus the first-pass extra (1.8 to 3.0 s), so 5 to 6.5 s per repetition more than an in-process pass.
    • The recorded weights overstate an isolated pass for the browser category (0.5 to 0.65 of the weight for the three specs above), because the suite runs up to thirteen projects at once. The layout spec took 1.2 times its weight; that weight comes from an older measurement run.
    • Local, four pinned cores: start 5.3 to 5.6 s; first pass 4.7, 14.3, 7.4 and 4.5 s; further passes 3.4, 11.4, 4.9 and 1.9 s, in the table's order.

    3. Load

    CPU burners outside the container reach the browser only weakly on a hosted runner. Burners inside the container compete with it thread for thread.

    • Why. On the runner the job's step processes are in the cgroup /system.slice/hosted-compute-agent.service and the container is in /system.slice/docker-<id>.scope. Both have cpu.weight 100 under a parent with the CPU controller enabled (Docker's systemd cgroup driver, cgroup v2). The kernel therefore divides CPU between the two groups, not between threads: however many burners run outside, the container keeps half the CPUs.
    • Measured on the runner with a fixed CPU loop inside the container and four burners: a single thread ran 1.04 times slower with the burners outside and 1.29 times slower with them inside. Four threads ran about twice slower either way.

    Further passes of the four specs, hosted run 44049769708, seconds and ratio to no load:

    Spec No load Four burners inside the container Four burners outside (the job's processes)
    contact-card-fact-keys.visual.tsx 3.1 4.0 (1.27) 4.0 (1.27)
    dictation-notice.pointer.tsx 10.8 14.8 (1.37) 13.4 (1.25)
    handoff-sheet.layout.tsx 4.2 7.6 (1.79) 5.8 (1.37)
    SearchResultCard.stories.tsx 1.6 2.7 (1.70) 2.1 (1.30)
    • Browser specs slow down far less than Bun tests. The Bun gate's first hosted run had a ratio of about 3.2. These specs wait on timers and frames more than they compute.
    • Locally the same split holds. With the container and all four burners as two sibling cgroups, the single-thread loop ran 1.04 times slower; with the burners inside, 1.27 to 1.35 times. Placing each outside burner in its own cgroup cut the container to one fifth of the CPU, which shows that the hierarchy, not the burner count, sets the load.

    A known hosted-only race. #3953 was a red main in layout: composer-image-originals.offline.tsx read a chip's status once and could catch preparing preview…. #3954 fixed it with one expect.poll. A copy of the current spec with that one line reverted (measure-3953-race.offline.tsx on the measurement branch) was repeated in one Vitest process:

    Condition Hosted runner, run 44051630821 Local, four pinned cores
    No load 0 of 8 passes failed 0 of 14
    Four burners inside the container 9 of 16 8 of 22
    Four burners outside the container 2 of 8 (as the job's own processes) 1 of 14 (in one sibling cgroup)
    • Load made a race that never fired without it fire in about half the passes on the runner, and burners inside the container did so about twice as often as burners outside.
    • At the hosted rates, two repetitions with burners inside would catch this race about four times in five (1 − 0.44²) and five repetitions almost always (0.98). With burners outside: 44% and 76%.
    • Each failure had the incident's own signature: expected 'Image · 558 B · preparing preview…' to match /^Image · .+ · not shown inline$/.

    4. Demand

    Method: git log --first-parent -150 on main at e2a233e7e (2026-11-09 to 2026-11-17), then for each commit the added, modified or renamed files that match the patterns in section 5 (scripts/measure-4116/demand-collect.py).

    • 38 of the 150 merges changed a spec (25%, about 4.5 a day). Four more changed only a helper under the spec directories.
    • Files per such merge: median 2. 15 changed one file, 27 changed three or fewer, one changed 89.
    • By kind (merges touching at least one): .offline.tsx 18, .stories.tsx 15, .visual.tsx 11, .layout.tsx 8, .pointer.tsx 7, .endurance.tsx 0.

    Estimated job duration (scripts/measure-4116/demand-estimate.py):

    • Pass cost of a merge is the sum of the recorded weights in scripts/browser-shard-costs.json for every project/file pair its changed specs run in, from vitest list --filesOnly (a pointer spec counts three times, a story twice). The weights are taken at face value, which section 2 shows is high for the browser category and about right for layout.
    • Job seconds = 140 (the measured start-up, rounded up) + 5 for each project started + pass cost × repetitions × load ratio.
    • Limit: 138 of the 334 project/file pairs involved have no recorded weight (41%); they are estimated at their project's median. The weights file is behind the tree, and the gap is not harmless: conversation.offline.tsx and conversation-contextual.offline.tsx have no weight, are estimated at 3.4 s, and took 105 and 120 s under load locally. The table understates selections that contain such files.
    Median 75th percentile 90th percentile Largest Over 10 min Over 15 min
    Pass cost, weighted seconds 13 70 390 1,993
    Two repetitions, no burners 3.0 min 4.9 min 16 min 70 min 4 of 38 4 of 38
    Five repetitions, no burners 3.6 min 8.5 min 35 min 169 min 6 of 38 5 of 38
    Two repetitions, burners inside (ratio 1.8) 3.3 min 6.9 min 26 min 123 min 6 of 38 4 of 38
    Five repetitions, burners inside (ratio 1.8) 4.4 min 13 min 61 min 302 min 10 of 38 6 of 38
    • Most selections are small and a few are very large. 28 of 38 have a pass cost of 60 weighted seconds or less; 5 exceed 150 (178, 390, 444, 450 and 1,993). Without a bound, those five would run 13 to 123 minutes at two repetitions.

    What the job could have prevented in the same window. 14 red-main incidents were opened between 2026-11-09 and 2026-11-17. Seven were in browser or layout. One of those was infrastructure (#3757, the container socket closed before any test ran). The other six were cleared by test-only changes (#3774, #3819, #3953, #3993, #4098, #4125).

    5. Files

    • Patterns that count (every spec the Vitest projects in packages/ui-kit/vitest.config.ts include):
      • packages/ui-kit/tests/visual/**/*.visual.tsx
      • packages/ui-react/tests/browser/**/*.pointer.tsx, *.layout.tsx, *.offline.tsx and *.endurance.tsx
      • packages/ui-kit/stories/**/*.stories.tsx
    • .offline.tsx was missing from the issue's title and is the most often changed kind. It runs in ui-react-layout.
    • A spec runs once per project that includes it. The file selection must expand to project/file pairs: three rail-* projects for a pointer spec, two themes for a story, Chromium and WebKit for diagrams-*.layout.tsx.
    • The one .endurance.tsx file should stay out. It is real-time media proof with its own job and no recorded weight, and no merge in the window changed it.
    • A changed helper should not select its specs, at least at first. Method: a static walk of relative imports from each spec (scripts/measure-4116/demand-helpers.py). 21 merges changed a non-spec file under the spec directories; in 15 of them the rule would add no spec, and at most 5. The benefit is small, and the planner has no per-spec import map today: scripts/browser-input-closure.ts resolves inputs per category.
      • The most imported helper, offline/fault-network.ts, reaches 27 specs; a change to it would select all of them.
      • Server-side browser commands are imported by the Vitest config, not by specs, so no import walk attributes them to a spec.

    Recommendation

    B: add the job, bounded so that it cannot set the merge lease.

    The evidence for it:

    • Half of the red-main incidents in the window were in these categories (7 of 14), and six of the seven were cleared by changing only a test.
    • A repetition is cheap: the spec's own seconds, after about 2 minutes 15 seconds of start-up. The median selection finishes in 3 to 4.5 minutes.
    • The one known race tried failed in 9 of 16 hosted passes under load inside the container and in none of 8 without load.
    • Under the hybrid split a changed spec first runs on a runner after it merges, unless draft heavy feedback is requested. ci: main red at 05bf0d6a02fb: browser #4098 reached main that way.

    The evidence against, which the bounds answer: 5 of the 38 selections are too heavy to repeat inside any reasonable time, and burners outside the container do about half as much.

    Proposed shape:

    • Mechanism: further passes of the changed project/file pairs in one container. Either in-process passes or a loop of vitest run works. In-process passes are 5 to 6.5 s cheaper per repetition and keep the isolation consecutive files have today; they need VITEST=true set before Vitest starts, or the Storybook plugin registers no story. Separate invocations give a new browser each time and need no new API. Not repeats: it reruns single tests inside one page with all state kept, so a spec that is not idempotent in its own document would fail for a reason that is not a race.
    • Load: one burner per CPU, started inside the container. Burners beside the container, as the Bun gate starts them, slowed these specs 1.25 to 1.37 times against 1.27 to 1.79 times inside, and reproduced the ci: main red at 96ba8a7c8636: layout #3953 race half as often.
    • Repetitions: five at the draft and feedback cadences, two at ready confirmation, the same counts as the Bun gate, reduced uniformly to no fewer than two when the budget requires.
    • Budget: 300 weighted seconds (pass cost × repetitions) from scripts/browser-shard-costs.json. At a load ratio of 1.8 that is about 9 minutes of passes and about 12 minutes for the job.
    • Cadences: every pull-request cadence that selects it, like determinism: draft, ready feedback and ready confirmation, plus draft heavy feedback. Never on main, where each spec already runs once.
    • Expected effect on the merge lease: none. In three recent ready confirmations (runs 44046614212, 44026069516 and 44029231245) the slowest job was a unit partition at 879, 965 and 981 seconds. A job capped near 12 minutes ends before it. Without the over-budget rule, those 5 selections would hold the lease for 13 minutes to 2 hours.
    • Before building it, refresh scripts/browser-shard-costs.json (scripts/refresh-browser-costs.ts): a budget cannot bound files that have no weight.

    If the maintainer prefers A, the sentence for the hybrid ruling is: a racy wait in a changed browser, layout or story spec is caught by a later main run, often many merges after the one that introduced it (2 to 146 in this window).

    Unknown

    • How often a green spec fails under burners inside the container. A local sample found none: 31 project/file pairs from the fourteen most recent spec-changing merges passed two passes each, and four more passed one, with four burners inside the container (66 passes). That is one host and about a tenth of the specs; the rate across all of them, and on the runner, was not measured.
    • Whether repetition under load would have caught the other five incidents (ci: main red at ea33e087d061: layout #3774, ci: main red at 4e6492bd34f2: browser #3819, ci: main red at c82e30ae46cb: layout #3993, ci: main red at 05bf0d6a02fb: browser #4098, ci: main red at 141c2437a02c: browser #4125). Only ci: main red at 96ba8a7c8636: layout #3953 was tried.
    • Run-to-run variance on the runner. Each hosted cost number is one run of three passes, and the race rates rest on 8 to 16 passes.
    • Runner minutes over a pull request's life. The job would run at every push that selects it; pushes per pull request were not counted.
    • The cost of a vitest run loop, which is derived from the in-process laps, not timed.
    • WebKit and the diagrams-* projects. No diagram spec was repeated; their native artifact preparation adds start-up that this spike did not time.
    • Several changed specs from different projects in one invocation. Each measurement ran one spec in one project. Projects run concurrently, so a mixed selection should take less wall time than the summed weights, by an amount not measured.
    • Memory. Peak memory was not recorded. No run failed for lack of it.
    • Whether the runner's cgroup layout is stable. It was read once, on one runner image.

    Reproduce

    git fetch origin spike/4116-browser-repeat-measure && git checkout a651d6c29   # scripts/measure-4116/, the probes, the reverted-fix spec
    bun install --frozen-lockfile && bun run build --jobs=2
    
    # Sections 2 and 3, hosted: the logs of the two runs linked above carry every figure (lines FACT, LAP, BENCH, STAMP).
    #   scripts/measure-4116/hosted.sh       cost and load (commit b95f0b5a9 ran it on push)
    #   scripts/measure-4116/hosted-race.sh  the #3953 race under each burner placement (commit b7570825f ran it on push)
    # The branch head has no push trigger any more; restore it from those commits to run again.
    
    # Inside the pinned image, mounted as scripts/visual.mjs mounts it, cwd packages/ui-kit:
    node ../../scripts/measure-4116/rerun.mjs 3 --project=visual contact-card-fact-keys.visual      # one spec, three passes
    node ../../scripts/measure-4116/rerun.mjs 3 --project=visual zz-repeat-probe                    # section 1, in-process passes
    VITE_PROBE_REPEATS=2 node ../../scripts/visual.mjs --inside --project=visual --filter=zz-repeat-probe   # section 1, `repeats`
    node ../../scripts/visual.mjs --inside --project=visual --filter=zz-repeat-fail                 # section 1, a failing repetition
    node ../../scripts/measure-4116/rerun.mjs 8 --project=ui-react-layout measure-3953-race         # section 3, the race
    
    # Sections 4 and 5
    python3 scripts/measure-4116/demand-collect.py e2a233e7e commits.json
    (cd packages/ui-kit && VITEST=true node ../../node_modules/vitest/vitest.mjs list --filesOnly --json=../../files.json)
    python3 scripts/measure-4116/demand-estimate.py . commits.json files.json 1.0 1.8 140 5 --rows   # 1.0 in place of 1.8 for no burners
    python3 scripts/measure-4116/demand-helpers.py commits.json

    The local load experiment is scripts/measure-4116/local.sh; it needs a systemd user slice and four free cores, and its header says how to set them up. The measurement branch is not a pull request and nothing on it merges; it can be deleted after the ruling.

  7. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-11-17): B, add the pre-merge repetition job as the spike report proposes, with one change. A selection too heavy for one job is split across runners by reviewed weight, as #4117 does for the Bun gate; it is not skipped.

    What it implies:

    • Five repetitions at draft, ready feedback and draft heavy feedback, two at ready confirmation, inside a 300 weighted-second budget, with one CPU burner per CPU inside the container.
    • The browser weights are refreshed first.
    • Accepted with it: the hosted false-failure rate under load is still unmeasured (no failure in 66 local passes).

    The spike's deliverable is complete, so this issue closes. The work continues in the two issues linked below.

    Follow-up issues: #4162 (weights refresh, first) and #4163 (the job).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: cipriority: p2type: spike

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions