Skip to content

Reuse private Git fixture topology to reduce refresh and branch-test setup - #7687

Merged
ymichael merged 4 commits into
mainfrom
bb/flake-git-fetch-fixtures
Nov 17, 2026
Merged

ymichael merged 4 commits into
mainfrom
bb/flake-git-fetch-fixtures

Conversation

@ymichael

@ymichael ymichael commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Remote-refresh and default-branch tests rebuilt the same real Git repository and bare-remote history for every case. Native Windows phase measurements put about 90% of the measured scenario time in fixture setup, which contributes to their sensitivity to busy runners.

What changed

Build the initial real Git topology once, then copy a private working repository and private bare remotes for each case. Remote URLs stay relative to that case's directory; there are no clone alternates or links back to the template. Apply the same private-copy pattern to the six default-branch cases. Preserve all fetch, prune, authentication, divergence, and ref assertions. No production changes, retries, timeout changes, or new CI jobs.

CI also exposed a cold-import race in the server-move functional suite. Prepare its real dialog module during collection so its existing DOM assertions do not race module transformation. This adds two lines to one test file and preserves the real loader and every assertion.

How you verified

  • Native Windows default-branch ABBA: per-case setup 394–414 ms before versus 58–65 ms after; whole divergence case 982–1,107 ms versus 692–698 ms. One-time template initialization took 1,135 ms and is shared across six cases. The same divergence mutation fails before and after.
  • Same-runner Windows ABBA comparison: setup 1,007–1,118 ms before versus 627–671 ms after; whole scenarios 1,132–1,256 ms before versus 763–804 ms after. One-time template creation took 242 ms.
  • Removing production pruning fails the same three assertions before and after the fixture change.
  • Full package: 48 tests pass with seed 8821; focused seed 7674: 9 pass. Turbo lint/typecheck pass.

The historical timeout was not reproduced in that measurement; this demonstrates reduced setup work, not a proven explanation for every timeout.

  • Server-move cold import: a temporary 1,500 ms delay reproduces the exact missing-dialog failure before; all 11 component tests pass with the same delay after. The diagnostic delay is removed. Clean component, state, and split-loader suites: 50 tests pass; app lint/typecheck pass.

AGENT GENERATED

@ymichael ymichael changed the title Reuse private Git fixture topology to reduce refresh-test setup cost Reuse private Git fixture topology to reduce refresh and branch-test setup Nov 17, 2026
@ymichael
ymichael merged commit 491e60c into main Nov 17, 2026
50 checks passed
@ymichael
ymichael deleted the bb/flake-git-fetch-fixtures branch November 17, 2026 18:01
ymichael added a commit that referenced this pull request Nov 18, 2026
…ime limit (#7745)

## Human comments

## What was wrong

Most CI flakes logged this week came from one class: a test charges real
work (Git or Node subprocesses, cold transforms, or thousands of
instrumented queries) against a fixed per-test limit. On a slow, usually
Windows, runner that work occasionally overruns the limit. Each item
below was verified from the failing job log, then measured locally. The
cause was rarely what the test is about.

| Item | CI evidence | Cause found |
|---|---|---|
| `packages/db` `resolved-item-pruning-resume.test.ts` › seed 1 (15 s) |
File took 64 s
([job](https://github.com/get-bb/bb/actions/runs/44168611379/job/134341637967));
32–64 s in passing `main` runs; seed 1 failed twice | Two causes. (1)
The query-plan test guard costs ~1.1 s per seed of ~1.7 s: on every
`prepare` (Drizzle re-prepares each query) it captures a 40-frame stack
in CI's `BB_QUERY_PLAN_EXECUTED` mode and re-resolves every frame.
Without the guard, 16.6k prepares cost 124 ms. (2) 400-step runs grow
superlinearly. |
| `apps/server` `timeline-in-turn-window.test.ts:1140` (15 s) | Linux,
file 41.8 s
([job](https://github.com/get-bb/bb/actions/runs/44170437386/job/134347996736))
| The verification helper loaded 1,750 content-deferred rows one by one
(1,764 paged walks) to collect call ids those rows already carry. Only 7
delegation expansions were needed. |
| `apps/server` `plugin-update.test.ts` › nested git plugin (Windows, 15
s) |
[job](https://github.com/get-bb/bb/actions/runs/44170437386/job/134347996617)
| Production runs `npm install` on every git plugin materialization,
even when the plugin declares nothing npm would install. The test pays a
cold npm boot three times (170–270 ms locally, seconds on Windows).
Users pay it on every git plugin install and update. |
| `environment-provider-host` `workspace-git-fetch.test.ts:194`
(Windows, 15 s) | [job
1](https://github.com/get-bb/bb/actions/runs/44170437386/job/134347996813),
[job
2](https://github.com/get-bb/bb/actions/runs/44166034127/job/134332437148)
| Each case ran 9 Git commands (`remote add`/`fetch`/`push` per remote),
and local transports spawn more helpers, before the one fetch under
test. Every ref in the topology points at the same commit. |
| `environment-provider-host` `workspace-git.test.ts:215` `beforeAll`
(Windows, 10 s hook) |
[job](https://github.com/get-bb/bb/actions/runs/44163251565/job/134322720725)
| 9 Git spawns, including 2 `git config` calls per repo and a `fetch`
right after a `push -u` that had already updated `origin/main`. |
| `process-utils` `vcs-process-admission.test.ts:59` (Windows, 20 s) |
4.5 s / 8.1 s / 21.3 s (failed) on Windows
([job](https://github.com/get-bb/bb/actions/runs/44170133473/job/134346992616))
| Each timeout case started `git` → `sh` → a 30 s Node grandchild that
inherited stdout/stderr. If the Windows tree kill (`taskkill /T`, 2 s
cap) is slow under load, `execPortableFile` keeps waiting on pipes the
grandchild still holds. |
| `process-utils` `workload-priority.test.ts:38` (Windows, 5 s) | 0.45 s
/ 5.2 s / 7.1 s (failed)
([job](https://github.com/get-bb/bb/actions/runs/44152213676/job/134283643727))
| The child is lowered to below-normal priority, then must cold-boot a
second Node process only to print that priority. A starved low-priority
Node boot is the slow step. |
| `logger` `logger.test.ts:215` and `:243` (Windows, 15 s) |
[job](https://github.com/get-bb/bb/actions/runs/44168611379/job/134341637638)
| Each test spawns `node --import tsx`, which transforms `@bb/logger`
and `@bb/config` TypeScript, again inside pino's worker thread (it
inherits `--import tsx`). |
| `@bb/web` `oauth.test.ts:1137` (Windows, 5 s) | 5,048 ms; the
21-refresh sibling took 1,125 ms
([job](https://github.com/get-bb/bb/actions/runs/44156219534/job/134297803640))
| 72 sequential hourly refreshes, about 54 ms each on Windows PGlite, to
prove a 24 h retention bound. Locally they take 2 ms each. |
| macOS Package Smoke, first server start | Full stack timed out after
62.6 s
([job](https://github.com/get-bb/bb/actions/runs/44166147875/job/134333018710));
passing runs take 3.3–6.8 s | **Not a slow start; a hang.** The server
printed `Starting server` and never answered `/health`. The smoke
printed only stdout, so the log cannot show why. |
| `timeline-in-turn-window.test.ts:1357` | **Not found.** No failure at
that line in the last 60 CI runs. On `main` it falls inside the
image-generation test, which takes 65 ms locally. | — |

## What changed

**Fixes, at the cause:**
- **Query-plan test guard** (`packages/db/src/query-plan-guard.ts`):
memoizes located stack frames in nested maps keyed by script, line and
function, instead of re-parsing every frame on every `prepare`. The
audit dedupe key no longer concatenates the full SQL text on every
execution; it uses caller → SQL → plan-signature maps. Findings and the
executed-function report are unchanged. This benefits every `@bb/db` and
`@bb/server` test.
- **Pruning property test:** 16 seeds × 200 steps instead of 8 × 400, so
the same 3,200 steps are split into shorter runs. Every seed still
exercises 2–8 suffix-delete-and-compare cycles (81 in total).
- **Git plugin dependencies**
(`apps/server/src/services/plugins/git-plugin-dependencies.ts`): skip
`npm install` when `package.json` declares no `dependencies` or
`peerDependencies`. With `--omit=dev --omit=optional`, those are all npm
would install. `.npmrc`/`.yarnrc` are still removed. Tests pin the skip
(no `package-lock.json` written) and that a peer-only plugin still runs
npm.
- **Timeline helper:** `buildTimelineTurnSummaryDetails(…,
"keep-deferred")` expands delegations but leaves content deferred. The
two call-id-only tests use it; the 5 content-asserting callers still
load.
- **`workspace-git-fetch`:** `beforeAll` builds one final-state bare
remote. Each case copies it and writes the remote config and tracking
refs as files, so the only Git work per test is the fetch under test.
- **`workspace-git`:** test identity and the remote are written into
`.git/config` directly, as `@bb/test-helpers`' `initRepo` already does,
and the redundant post-push `fetch` is dropped. `beforeAll` goes from 9
Git spawns to 5, the clone helper from 6 to 4, and every repo the file
builds saves 2.
- **`vcs-process-admission`:** the timeout case's delayed command is
`exec sleep 30 </dev/null >/dev/null 2>&1`. That is no Node boot, and
the command can't hold the root's pipes after the root is killed. The
assertions (rejected with `killed: true, signal: SIGTERM`, then six
recoveries) are unchanged.
- **`workload-priority`:** the lowered child spawns the grandchild and
reports its PID. The test reads `getPriority(grandchild)` directly,
since Windows and POSIX fix the inherited priority at process creation.
The grandchild never has to boot Node at low priority.
- **`logger`:** `beforeAll` bundles `@bb/logger` once with esbuild's
in-process API, keeping `pino`/`pino-pretty`/`pino-roll` external; the
server ships it bundled too. The subprocess runs plain `node -e` with no
tsx, in the main thread or the transport worker. Adds `esbuild` as a
logger devDependency.
- **`oauth`:** the retention test refreshes every
`OAUTH_ROTATED_REFRESH_RETENTION_MS / 6` (4 h) over the same 72 h. That
is 18 refreshes instead of 72, and the bound is derived from the
constant instead of the literal 26. The reuse test spans the same 20 h
in 4 steps instead of 20. A temporary break in production pruning still
fails it.
- **Package smoke:** on timeout it appends the tail of every log in the
data directory's `logs/`, so the next hang shows what the server was
doing.

**Class policy:**
- **Reporter:** `vitest.test-durations.ts`, added by
`defineWorkspaceTestConfig` when `BB_TEST_DURATIONS_DIR` is set. It
records every test that used ≥25% of its effective timeout
(`testCase.options.timeout`, else the project's `testTimeout`).
- **CI:** the Linux tests, Windows tests and Windows foundation jobs set
the variable and upload the records with their `test-timings-*`
artifacts. Foundation gains an upload step.
- **Nightly report:** a new `CI Health` step downloads those artifacts
from the last 20 `main` push runs. `scripts/report-test-headroom.mjs`
(pure logic in `scripts/lib/test-headroom.mjs`, tested in
`packages/scripts/test/test-headroom.test.mjs`) lists, per platform,
every test that reached ≥50% of its timeout. Each row shows its worst
duration, the number of runs near the limit and the number of failed
runs. The list goes to the step summary and
`.ci-health/test-headroom.md`.
- **Docs:** `docs/ci-performance.md` gains "Tests near their time
limit".

## How you verified

Local numbers are on macOS (M-series), from interleaved before/after
runs. Other agents were running suites on the same machine, so CPU time
is shown where wall time was noisy.

| Test | Before | After |
|---|---|---|
| `resolved-item-pruning-resume` slowest test | 1,680 ms | 510 ms |
| `resolved-item-pruning-resume` file, CPU in CI's guard mode (3 rounds)
| 15.3–16.8 s | 12.9–14.3 s |
| `resolved-item-pruning-resume` file, test time (guard + split) |
10.1–13.6 s | 6.4 s |
| two-seed profile, guard frames in CI mode | 4,540 ms | 2,767 ms |
| `timeline` › delegated byte-budget slices | 1,542–1,651 ms | 106–115
ms |
| `timeline` › finished turn over byte budget | 1,069–1,123 ms | 77–78
ms |
| `timeline` file, test time | 4.2–4.4 s | 1.8 s |
| `plugin-update` › nested git plugin | 1,491–1,675 ms | 1,040–1,333 ms
|
| `plugin-update` file, test time (npm skipped for every git fixture) |
11.9–12.7 s | 7.5–9.6 s |
| `workspace-git-fetch` › prunes only origin (×2) | 414–549 ms | 111–147
ms |
| `workspace-git-fetch` › only remote / several remotes | 184–213 /
277–284 ms | 94–113 / 71–106 ms |
| `workspace-git` file, test time | 3.7–4.6 s | 3.3–4.0 s |
| `logger` › worker mode / plain file | 619–629 / 503–507 ms | 379–398 /
365–379 ms |
| `oauth` › bounded refresh rows / reuse in window | 143 / 65 ms | 49 /
29 ms |
| `workload-priority` › lowers a running process | 51–54 ms | 27–29 ms |
| `vcs-process-admission` › releases admission | 228–232 ms | 226–257 ms
|

`vcs-process-admission` shows no local difference because POSIX group
kills are immediate; its fix targets the Windows pipe hold.

**Windows CI, file durations.** "Before" is every sample in the failing
jobs and recent logs above; "after" is this PR's full-matrix [run
44212664696](https://github.com/get-bb/bb/actions/runs/44212664696).
This is one after sample, so the per-test check below is the stronger
evidence.

| File | Before | After |
|---|---|---|
| `vcs-process-admission` | 4.5 s, 8.1 s, 21.3 s (failed) | 1.5 s |
| `workload-priority` | 0.45 s, 5.2 s, 7.1 s (failed) | 0.19 s |
| `oauth` | 9.4–18.3 s (one failed) | 5.6 s |
| `logger` | 6.1–6.8 s, 34.2 s (failed) | 5.5 s |
| `workspace-git-fetch` | 21–47 s (two failed) | 20.8 s |
| `workspace-git` | 28–51 s | 29.0 s |
| `plugin-update` | 78.6 s (failed) | 52.3 s |
| `timeline-in-turn-window` (Linux) | 41.8 s (failed) | 5.4 s |

**Per-test check from the new reporter.** In that full run, across all
30 Linux and Windows test shards (37 record files, 87 tests at ≥25% of
their timeout), **no test from any file fixed here reached even 25% of
its timeout on any platform.**

The report over that one run already lists 7 tests at ≥50% of their
timeout. Several deliberately wait out a real timeout, for example
`disk-usage` › kills every running du when the timeout elapses (62%),
`desktop-browser-broker-client` › timed out broker (61–62%),
`actions-api` › bounds recovery for timeout (55–56%), and
`host-toolchain` › kills a shell that ignores SIGTERM (60%). They are
the next work list, not part of this PR.

- `@bb/db` full suite passes. Also passing: process-utils, logger, web,
environment-provider-host and scripts full suites, and the touched
`@bb/server` files (147 tests).
- `typecheck`, `lint` and `lint:type-aware` pass for the 8 changed
packages; root `lint:type-aware` passes; `actionlint` passes.
- **Reporter end to end:** locally, `BB_TEST_DURATIONS_DIR=/tmp/tdur
turbo run test --filter=@bb/db -- … --testTimeout=1000` writes one JSONL
record per qualifying test, with the resolved timeout. In CI, all 30
`test-timings-*` artifacts of run 44212664696, including
`windows-foundation`, contain records; `report-test-headroom.mjs` over
them produced the table above.
- **oauth mutation check:** with production pruning disabled, the
18-refresh test fails.

## Past fixes on these files

- `workspace-git-fetch` / `workspace-git`: #7687 (shared fixture
topology), #7145 (SSH wrapper independent of the fetch deadline).
- `query-plan-guard.ts`: #7323 (structured call sites), #7711 (no
reparsing of audit frames), #7535.
- `plugin-update.test.ts`: #7685 (shared native plugin startup), #7688
(open: proposes 60 s for native loading).
- `timeline-in-turn-window.test.ts`: #7541, #5261.
- `vcs-process-admission.test.ts`: #5630.
- `smoke-tarball.mjs`: #7202.

## Decisions for review

- **Git plugins with no runtime or peer dependencies no longer run `npm
install`** on install or update. It's faster, and no `package-lock.json`
or `node_modules` is created in that plugin's directory. Plugins that
declare dependencies are unchanged.
- **The policy reports; it does not block.** A per-PR duration budget
would itself fail on slow runners, the flake class this fixes. So
durations are recorded in every CI test job and aggregated nightly
across 20 `main` runs, which is a stable signal. The two numbers are
policy constants, not per-test budgets:
- 25% of timeout is the threshold for recording a test, which keeps
artifacts small;
  - 50% is the threshold for listing it.

Turbo cache hits replay results without running, so they add no records.
Hook timeouts (as in `workspace-git` `beforeAll`) are not covered:
Vitest does not expose hook durations to reporters.
- **The pruning property test now explores shorter histories** (200
steps) across twice as many seeds.
- **Not fixed: the macOS smoke hang.** The cause is unknown; the change
is the diagnostic that will name it.
- **Out of scope, noted:** on Windows, `stopWindowsProcessTree` caps
`taskkill /T` at 2 s, and a tree it fails to kill keeps inherited pipes
open. The `vcs-process-admission` fix stops the test from depending on
that, but the production behaviour under load deserves its own issue.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant