Skip to content

Fix Windows package test and smoke flakes from slow runners and test races - #8079

Merged
ymichael merged 2 commits into
mainfrom
bb/fix-windows-package-test-and-smoke-flakes-thr_78y5udaykn
Nov 24, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/fix-windows-package-test-and-smoke-flakes-thr_78y5udaykn

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Each of these tests failed on CI in the past week, then passed on a rerun of the same SHA, or failed on main with no relevant change. I checked every failing job log and traced the cause. Most are the same class as #7745: real work charged against a fixed deadline on a loaded Windows runner. In each case the expensive step was not what the test is about.

Test CI evidence Root cause
process-utils workload-priority.test.ts › lowers a running process so the processes it starts later inherit the priority (Windows, 5 s) 5 timeouts at 5.0 s, 4 of them after #7745, one on main (job); passing runs 2.8–4.9 s #7745 stopped the grandchild from booting Node at low priority. The child still does. The test lowered the child right after spawn, so its whole Node bootstrap ran at below-normal priority. It then needed a second lowered wake-up ("done") to kill the grandchild and exit. On a saturated Windows runner a below-normal thread can wait about 4 s for the anti-starvation boost, once for each burst.
agent-runtime runtime.process-lifecycle.test.ts › does not wait for stalled replacement initialization during full shutdown (Windows) Timed out after 1000ms waiting for the replacement bridge to begin initialization, twice (job) The setup step polled for a marker file with the helper's 1 s budget. That window covers retiring one Node bridge and spawning another. The sibling test that does exactly that took 2.8 s in the same failing job.
local-open-targets workspace-open-targets.test.ts › discovers and opens JetBrains Toolbox applications through bundled executables (Windows, 5 s) 5.05 s and 5.08 s (job); passing runs 0.49 s and 1.07 s The macOS listing walked the JetBrains Toolbox tree once for every JetBrains product (8), one readdir at a time: 54 readdirs in this test. In the same failing job, fs ops cost about 100 ms each (the TextMate test, about 8 fs ops, took 805 ms). The cost is in the product: every "Open in" listing on a Mac with Toolbox walks the tree 8 times.
thread-view tool-call-parsing-performance.test.ts › bounds intent parsing work after a script's disqualifying write (Windows) expected 4.80 to be less than 4.77 on main (job), plus 2 more The / 8 bound sits on the healthy ratio. Both commands pay the same O(n) cost to build, hash and cache the command string, so a correct early exit is only 6.5–8× cheaper on Windows (10–12× on an M-series Mac). The regression the test guards, scanning on after the write, gives a ratio of about 1.
desktop server-moved.test.ts › closes the watcher and polls after a watch error (Linux) expected "vi.fn()" to be called once (job) A race in the test's manual scheduler. The first flush() starts the initial lock read. If that read is still in flight when the second flush() fires the poll, the poll only marks a recheck. The in-flight read then sees no lock and schedules a debounced check on the manual scheduler, which the test never flushed again.
Windows app smoke on main: bb plugin list failed with 1 / bb-app SDK status failed with 1, with no output (run, run) Both after "daemon join" waitForProcessExit resolved on 'exit', which Node fires before the child's stdio is drained. The SDK step is a node -e script, and one that exits 1 always writes a stack trace to stderr, yet both failure messages were empty. Why the commands exited 1 is still unknown. This change makes the next occurrence show it.

Looked at and left alone:

  • tool-call-parsing-performance › scans long quoted thread messages in chunks: all 4 failures were on SHAs without Stabilize desktop, Git, and parser CI tests #7680, which moved these benchmarks to thread CPU time. No failure since.
  • plugin-sdk vendor-plugin-roots.test.ts (Windows, 5 s, 3 failures): a victim of runner saturation, not of its own work. The resolver does 14–39 fs ops per test, none redundant. In the failing jobs every test in the file slowed from 5–100 ms to 2–6 s during one window, while shared-declaration-emit (9–16 s), runtime-entries (5–16 s) and api-index (5.7 s) were running too. In the last 19 main runs it reached 50% of its limit once. A larger timeout would only move the deadline. The real fix is Windows-shard oversubscription (unbounded VITEST_MAX_WORKERS × turbo concurrency on 8 vCPUs), which belongs in its own change.
  • scripts ci-performance.test.mjs › ENOTEMPTY removing the fixture's .git (Linux, once): I found no concurrent writer. Each git commit does leave a detached git maintenance run --auto behind. An strace (git 2.56) shows it only unlinks objects/maintenance.lock, and it creates nothing in .git after commit returns. 750 Linux iterations of the exact fixture sequence, under CPU contention, produced no failure. A retry would only hide whatever caused it.

What changed

  • packages/process-utils/test/workload-priority.test.ts: the child prints ready after booting at normal priority, and only then is it lowered. The lowered work is now one wake-up and one spawn, the minimum the claim needs. The test reads the grandchild's priority, and stop() tears down the tree at normal priority (taskkill /T, or the process group). The child no longer has to be scheduled again to exit. The test gets a 15 s budget. That one wake-up can still wait about 4 s for Windows' anti-starvation boost on a saturated runner, and the inherent worst case of about 4 s + about 1 s bootstrap + taskkill is above 5 s.
  • packages/agent-runtime/src/runtime.process-lifecycle.test.ts: the stalled bridge writes a line to stderr when it receives initialize, and the test awaits it through the manager's onStderr. There is no polling budget. The real assertion is unchanged: shutdown completes within 1 s instead of waiting for the bridge's 3 s stall.
  • packages/local-open-targets/src/index.ts: the Toolbox apps tree is walked once per runtime, and each JetBrains adapter matches its prefixes against the collected bundles. Traversal order, depth limit and the executable check are unchanged, so results are the same. The daemon builds a new runtime for every request (apps/host-daemon/src/local-api.ts), so the walk is never stale across requests. In this test: 54 readdirs down to 12, 6 for the listing and 6 for the open.
  • packages/thread-view/test/tool-call-parsing-performance.test.ts: the bound is readOnly / 3. It sits between the healthy ratio (6.5–12×) and the regressed ratio (about 1×), with more than 2× margin on each side.
  • apps/desktop/test/server-moved.test.ts: the waitFor flushes the manual scheduler on each attempt, so a recheck that the in-flight initial read schedules also runs.
  • packages/bb-app/scripts/smoke-tarball.mjs: runCommand and the bridge model/list step wait for 'close' (new waitForProcessOutput), after the process has exited and its stdio has closed, so a failing command's stdout and stderr reach the error. The forked plugin-host worker keeps waitForProcessExit ('exit'). Node never emits 'close' once the parent disconnects the IPC channel, which I checked with a minimal fork/disconnect script, and the first local smoke run with 'close' everywhere hung at that step.

No wire, CLI or doc changes.

How you verified

All local numbers are from an M-series Mac. Other agents' suites were running on the same machine, with load averages of 100–700.

Test Before (origin/main) After
workload-priority, with the lowered child also put in macOS background QoS (taskpolicy -b -p) and 32 CPU burners, to model Windows' strict below-normal scheduling Spawn to grandchild pid: 13.5–25.1 s, then another 1.7–11.2 s to exit (5 s limit) Ready 26–102 ms at normal priority, lowered burst 48–913 ms, stop() about 105 ms (16 timed runs). macOS background QoS can starve a process indefinitely, which Windows does not: in a 50-run batch under this model a few runs still waited 30 s or more for that one burst.
workload-priority, unmodified, 30 repeats 30/30 30/30, about 160 ms per run instead of 65 ms, because stop() polls the process group at normal priority. No leaked grandchildren afterwards.
runtime.process-lifecycle stalled-replacement test, with a preload that delays every child Node start by 1 s to model Windows spawn cost Fails with the CI error, Timed out after 1000ms waiting for the replacement bridge to begin initialization 20/20
Same test, unmodified, 30 repeats with 48 CPU burners, and with background QoS passes passes
JetBrains Toolbox test, fs calls counted by wrapping fs/promises 54 readdirs (46 listing + 8 open) 12 readdirs (6 + 6). 100/100 repeats pass.
Parser bound, 40 repeats — 40/40. Injected regression (keep scanning after the write, same result): expected 57.0 to be less than 18.5, still caught.
server-moved watch-error test, with the first lock read delayed by 200 ms Fails with the CI error, expected "vi.fn()" to be called once with arguments Passes, and 500/500 unmodified. With schedulePoll() removed from the watch-error fallback it still fails.
Smoke waitForProcessExit Can't reproduce the lost output on macOS or Linux (Node's 'exit'-before-stdio ordering shows up on Windows IOCP). Local turbo run smoke:tarball --filter=bb-app: every step passes, including full stack, daemon join and plugin host worker

pnpm exec turbo run lint typecheck --filter=@bb/process-utils --filter=@bb/thread-view --filter=@bb/agent-runtime --filter=@bb/local-open-targets --filter=@bb/desktop --filter=bb-app passes. pnpm exec turbo run test for the same packages passes except process-utils process-tree.test.ts › finds and kills processes whose cwd is inside a directory. That file is untouched and also fails alone on this machine, which had about 1,020 processes running at the time.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 23, 2026 16:05
…races

- workload-priority: lower the child only after it reports ready, so its
  Node bootstrap runs at normal priority; tear down with stop().
- runtime.process-lifecycle: await the stalled bridge's stderr signal
  instead of polling a marker file with a 1 s budget.
- local-open-targets: walk the JetBrains Toolbox tree once per runtime
  instead of once per JetBrains product.
- tool-call-parsing-performance: bound the early-exit ratio at 3x, between
  the healthy 6.5-12x and the regressed ~1x.
- server-moved: flush the manual scheduler inside waitFor so a recheck
  scheduled by the in-flight initial read runs.
- smoke-tarball: wait for 'close' before reading a failed command's output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-test-and-smoke-flakes-thr_78y5udaykn

# Conflicts:
#	packages/process-utils/test/workload-priority.test.ts
@ymichael
ymichael merged commit 22a9366 into main Nov 24, 2026
52 checks passed
@ymichael
ymichael deleted the bb/fix-windows-package-test-and-smoke-flakes-thr_78y5udaykn branch November 24, 2026 05:02
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