Skip to content

Cut Git subprocess and copy work in Windows-flaky Git tests - #8073

Merged
ymichael merged 2 commits into
mainfrom
bb/fix-windows-git-test-flakes-thr_2dtcq32rm8
Nov 24, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/fix-windows-git-test-flakes-thr_2dtcq32rm8

Conversation

@ymichael

@ymichael ymichael commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

All of group A failed the same way: Windows test shards timed out on real Git subprocess tests. None of these tests or their code changed on main since their last failures (latest: main 9f3a35d930, 11-23). Each failure was a flake: other attempts on the same SHA or main passed. Passing Windows runs take 0.4–2 s per test, and failures need a 15–25x slowdown. Neighbouring tests in the same file ran 11–16 s in the same minute. So the cause is CPU/IO starvation on the 8-vCPU runner, which runs several vitest packages at once (turbo --concurrency). It is not a hang. On an idle Windows 11 VM, a git spawn costs about 60 ms, copying a .git tree about 50 ms, and a local git fetch 250–400 ms (it starts sh.exe, upload-pack, rev-list and maintenance --auto). Whether a test fails depends on how much of that work it does in one budget. Root cause per test:

  • workspace-git-fetch › fetches and prunes only origin (interactive: true/false), skips … none named origin (16 + 1 failures): every case copied the repo plus one bare remote per remote, so 4 .git trees for the two "only origin" cases. The case with 2 copies never failed. git fetch also started git maintenance run --auto.
  • workspace-git › keeps the standard patch format under … (9 failures): every case copied the template twice and ran 8 patch reads plus git config spawns. Half of that rebuilt the same unconfigured baseline each time.
  • workspace-git › readDefaultBranchRefs (5 test failures, plus 1 beforeAll timeout at 10 s): the beforeAll used 5 git processes, and the ahead/diverged cases ran git commit (plus its maintenance child). Production compareBranchOids then ran merge-base --is-ancestor twice.
  • plugins/git workspace-status-cache › reuses committed comparisons across readers while refreshing edits and moved refs (7 failures): one test made 7 sequential status reads, 79 git processes in one 15 s budget, and it ran first in the file. The other status-cache failure in the evidence (11-16, "cancels an over-budget squash command", an assertion error) came before Stabilize desktop, Git, and parser CI tests #7680, which fixed that race, and it hasn't recurred. It is left alone.
  • github-pr-status › reads a known PR by URL only on the branch it was found on (2 failures at the package's default 5 s): two sequential views calls, each starting a fake gh (cmd.exe → node.exe) one after the other, plus 8 git processes.

What changed

  • workspace-git-fetch.test.ts: all remotes point at the one read-only template remote. Fetching never writes to the remote, so a wrong fetch of alpha/zeta still adds fresh and prunes stale, and the test still catches it. The template turns off maintenance.auto. Each case now copies one repo instead of up to four.
  • workspace-git.test.ts patch-format cases: the baseline is computed once in beforeAll. Each case writes its settings to a GIT_CONFIG_GLOBAL file, the user's own config level, and reads the shared template's 4 patches in parallel. No repo copies and no git config spawns. Baseline and cases both use a hermetic global file. With bb's display overrides removed, all 9 cases still fail.
  • workspace-git.test.ts readDefaultBranchRefs: the template is git init --template= plus one git fast-import, which writes main, origin/main, and the local and remote tip commits. Each relation case applies its moves with one update-ref --stdin. The behind/ahead/diverged cases share one table and keep their names.
  • workspace-git.ts compareBranchOids: one git merge-base <local> <origin> replaces the two --is-ancestor checks. If the merge base is local, local is behind; if it is origin, local is ahead; otherwise, or with no common ancestor (exit 1), they have diverged; any other exit is unknown. This is exact, because when A is an ancestor of B the merge-base set is {A}. It saves one git process for every ahead or diverged default-branch read and branch-ref resolution in production. The now-unused isAncestorRef is removed.
  • workspace-status-cache.test.ts: the kitchen-sink test becomes "reuses a committed comparison across readers while refreshing worktree edits" and "recomputes the comparison when HEAD or the base branch moves", with the same assertions. The feature branch is built with fast-import, and the template turns off maintenance.auto. The largest single test drops from 79 to 50 git processes.
  • github-pr-status/host.test.ts: both known-URL reads go into one views call, as the client batches them. They share one batched gh process and their git reads run concurrently. The test asserts there is exactly one resource(url: selection, on p0, and that the other read is a headRefName lookup.
  • github-pr-status/vitest.config.ts: testTimeout: 15_000, the budget the git, github, docs and workflows plugins already use. This is the one budget raised, because the work is inherently slow on the slowest runner. Every test in host.test.ts starts real git plus a Node fake gh through cmd.exe, and plugins-2 shares its runner with the environment plugins' 60 s-budget tests. On this PR's first Windows run, single-view neighbours took 1.6–2.1 s, the single-gh git-host tests up to 2.7 s, and the batched known-PR test 4.6 s. The 5 s vitest default is not enough headroom for any of them.

No retries or CI settings changed.

How you verified

  • pnpm exec turbo run test typecheck lint --filter=bb-environment-provider-host --filter=bb-plugin-bb--git --filter=bb-plugin-bb--github-pr-status: 74 + 293 + 182 tests pass; typecheck and lint are clean (the git plugin's 9 lint warnings are existing ones in ui/diff).
  • Mutation checks, each restored afterwards: removing MACHINE_READ_GIT_CONFIG's display entries fails all 9 patch-format cases; fetching --all fails both "only origin" cases; swapping the behind/ahead result fails the relation table; always reusing the known URL fails the PR test.
  • Git processes per test, counted with a git PATH shim (top-level spawns only): patch-format case 10 → 4; "user Git settings" describe 100 → 57; status-cache test 79 → 41 / 50 after the split; PR test 2 gh processes → 1. Fetch cases drop 3 directory copies and a maintenance child; spawn counts are otherwise unchanged.
  • Local A/B, origin/main against this branch on one macOS host at load average about 140 from other workloads, 6 alternating rounds of the 4 files, 0 failures on either side. Summed per round: patch-format 4454 → 827 ms, fetch cases 1638 → 1060 ms, default-branch relations 1006 → 780 ms. The status-cache split totals 1956 → 2244 ms, but its slowest test p90 goes 2587 → 1350 ms. PR test p90 784 → 553 ms.
  • Windows 11 ARM64 VM (6 vCPU, Defender on), the four test files bundled from origin/main and from this branch, one vitest process per variant, 5 alternating rounds. Four rounds (base 1 and 5, new 4 and 5) were whole-VM stalls in which every file in both variants slowed down together and hooks timed out. Over the six clean rounds, 0 failures on either side. Summed per round: patch-format 22.4 → 4.4 s, fetch cases 6.5 → 3.4 s, default-branch relations 3.6 → 3.1 s, known-PR test 2.7 → 1.8 s. The old status-cache test took a 12.3 s median on the idle VM (82 % of its 15 s budget); the two split tests take 6.0 s and 4.6 s.
  • Windows CI on this PR: every row green on the first attempt with no reruns. In packages-other, none of the changed environment-provider-host tests passed vitest's 300 ms slow-test threshold. This shard ran only the affected packages, so it was less loaded than a full main run.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 23, 2026 15:45
The remote-refresh, patch-format, default-branch, status-cache, and
known-PR tests timed out on loaded Windows runners because each did more
real Git process and fixture-copy work than its budget allowed under
contention. Share one read-only remote, read user display settings from
a global config file instead of a copied repository, build default-branch
fixtures with one fast-import, split the status-cache test, and batch the
two known-PR reads into one views call. Compare default-branch refs with
one merge-base instead of two ancestry checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gs use

Every host test starts real Git and a Node fake gh through cmd.exe; on the
plugins-2 Windows shard single-view neighbours take up to 2.7s and the
known-PR test took 4.6s against vitest's 5s default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 7d1b463 into main Nov 24, 2026
50 checks passed
@ymichael
ymichael deleted the bb/fix-windows-git-test-flakes-thr_2dtcq32rm8 branch November 24, 2026 04:54
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