Skip to content

Fix seeded ordering, network, and timing test flakes - #4963

Merged
ymichael merged 2 commits into
mainfrom
bb/investigate-and-fix-recent-test-flakes-thr_98y6kafg7n
Oct 5, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/investigate-and-fix-recent-test-flakes-thr_98y6kafg7n

Conversation

@ymichael

@ymichael ymichael commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Recent CI failures had several independent causes: seeded shuffling consumed nondeterministic file-discovery order; Miniflare's rate limiter reset at minute boundaries during a 61-request test; worker startup and D1 migrations ran inside tests with a 5-second deadline; two marketplace image tests fetched GitHub avatars; and exhaustive provider-fixture validation exceeded its default 5-second deadline. Investigation covered 159 main-branch CI runs from October 2–5 and same-commit retries. Follow-up investigation also found that successful replays retained a shutdown timeout which later mutated their returned result into a false failure. Examples: seeded ordering failure, rate-limit failure, and image/provider timeout failures.

What changed

  • Canonicalize specifications before seeded shuffling, retaining isolated-first ordering and unchanged unshuffled behavior. Extend the existing regression to vary discovery order.
  • Freeze the disposable gateway worker's clock and assert exactly 60 successful requests followed by a refusal. Apply the existing 30-second integration budget to the worker suite, including startup and migrations.
  • Supply deterministic remote asset responses to image tests while retaining real loopback HTTP fallback and PNG rendering checks.
  • Give the exhaustive provider-fixture validation a 30-second deadline; the observed CI run took 9.085 seconds.
  • Cancel the replay shutdown deadline after a child exits. The old timeout kept running after success and later mutated completed replay results into false shutdown failures.

No product or wire changes. A separate Windows provider replay initialization timeout remains unresolved and is not claimed as fixed here.

How you verified

  • Demonstrated the seeded-order regression failing before the fix and passing afterward.
  • Reproduced the actual Miniflare limiter accepting all 61 requests across a minute boundary; a frozen worker clock produced the expected refusal.
  • Stalled external fetches to reproduce both image tests' 5-second failures; the same controlled setup passed all seven image tests after the fix in 738 ms.
  • Turbo test/typecheck checks passed for @bb/scripts, @bb/ai-gateway, @bb/web, and @bb/provider-parity: 466 tests total (198 scripts, 35 gateway, 174 web, 59 provider parity).
  • Extended the replay lifecycle regression: a successful result changed to a shutdown failure after its deadline on the old code; it remains successful after the fix. Full protocol and parity suites passed (299 + 59 tests), along with lint and typechecks.
  • Formatting, git diff --check, and independent final diff review passed. Ten diagnostic runs on native Windows passed all 59 parity tests each. The instrumented comparison captured 280 successful initializations: cold baseline median 24.9s / max 29.1s, warm baseline median 2.1s / max 4.4s. Limiting concurrent replays reduced startup time but increased suite duration from 29.5–51.1s to 116–119s; that experiment was not retained. The original 60-second initialization timeout remains unreproduced and unresolved. Temporary diagnostic changes were kept off this PR.

AGENT GENERATED

@ymichael
ymichael merged commit c40e76f into main Oct 5, 2026
59 of 61 checks passed
@ymichael
ymichael deleted the bb/investigate-and-fix-recent-test-flakes-thr_98y6kafg7n branch October 5, 2026 23:51
ymichael added a commit that referenced this pull request Oct 6, 2026
…4976)

## Human comments

## What was wrong

Recent CI failures came from independent lifecycle and readiness races,
shared test state, and live registry resolution. A review of 900 recent
CI runs classified 213 distinct failing test names; broad shuffled runs
then exposed additional icon-generation and app teardown/order failures.
A refresh of newer main runs found three more failures from the
generated-bundle checker race fixed here. This follows #4963.

Evidence includes [host/ACP
failures](https://github.com/get-bb/bb/actions/runs/37389341709),
[browser
ownership](https://github.com/get-bb/bb/actions/runs/37389714139),
[Claude
permissions](https://github.com/get-bb/bb/actions/runs/37388331904), [Pi
PID reuse](https://github.com/get-bb/bb/actions/runs/37285422900),
[server move](https://github.com/get-bb/bb/actions/runs/37374976858),
[environment
cleanup](https://github.com/get-bb/bb/actions/runs/37095834703), and
[registry
resolution](https://github.com/get-bb/bb/actions/runs/37386279602).

## What changed

- Host plugin shutdown now shares one directory-cleanup promise instead
of deleting the same directory concurrently.
- ACP and browser child fixtures publish usable readiness after signal
handlers are installed. Pi fixtures use actual child handles rather than
probing retired, potentially reused PIDs.
- Claude permission tests wait for the expected request; server
retirement and environment cleanup tests await lifecycle completion;
Tasks tests wait until form submission is enabled.
- The server-move fixture retains its listening socket until the child
accepts ownership, removing the free-port selection race.
- The integration harness stops plugins and closes WebSockets during
shutdown, matching production.
- External scaffolds install the packed SDK offline using locked local
dependencies.
- PWA generation skips unchanged assets and publishes changed files
atomically, preventing concurrent checks from reading truncated icons.
- The provider-literal checker excludes generated Wrangler and SDK
runtime-test bundles while continuing to scan adjacent source files. A
[native Windows
reproduction](https://github.com/get-bb/bb/actions/runs/37395770823)
identified `apps/demo-server/.wrangler/tmp/dev-*/worker.js` as the extra
provider-reference source.
- The filesystem-watcher test awaits actual change events under its
existing test watchdog and propagates errors received after readiness.
- The cold-loading toast test runs in its own isolated environment.
Palette tests complete Radix's scheduled focus cleanup before disposing
jsdom.
- Replay initialization is limited to four simultaneous workers;
initialized replays retain their existing concurrency. Queue slots
release on initialization, timeout, exit, signal, and spawn failure.

No wire, public API, or user-facing configuration changes.

## How you verified

Controlled before/after failures cover duplicate directory cleanup,
readiness publication, stale PID probes, delayed permission delivery,
retirement/cleanup scheduling, occupied ports, disabled form submission,
open WebSocket shutdown, concurrent icon checking, shuffled toast
startup, unfinished focus cleanup, delayed native filesystem events, and
generated bundles appearing in the source scan. The replay regression
launches eight real workers, checks the initialization bound, then
verifies all eight can replay concurrently; failure cases verify queued
work completes and children exit.

- First repository shuffle (seed 61973) passed 14,512 tests outside the
app; its icon precheck and subsequent app failures produced the fixes
above.
- Focused verification passes: six replay-helper regressions, all 59
recorded parity cases, 616 host source tests, all 74 integration tests,
all 41 Tasks manage tests, and 17 affected app tests. Changed-package
lint/typechecks pass.
- [Native Windows shutdown
verification](https://github.com/get-bb/bb/actions/runs/37394517960)
passes the formerly failing live-WebSocket regression and three
environment-isolation repetitions.
- [Windows startup
measurements](https://github.com/get-bb/bb/actions/runs/37393953100):
limiting startup to four reduced maximum cold initialization from 15.8s
to 2.8s and suite duration from 44.1s to 27.3s, while keeping peak live
replays at 16. The original 60-second initialization timeout did not
reproduce; this is a measured contention mitigation, not a proven
diagnosis of that exact failure.
- Second repository shuffle (seed 82317): 19,886 tests passed, including
all 5,370 app tests; one watcher readiness failure led to the final
event-wait fix. The complete watcher suite then passed (56 tests), and
the scripts suite passed all 201 tests with the artifact exclusions.
- CI at 2712483 passed 30 checks; its sole failure was the
generated-bundle checker race fixed in f4e976b.
- Final repository-wide shuffle (seed 90071) passes: **19,889 tests
across 92 package suites; all 106 Turbo tasks passed**, with no
unhandled errors.
- [Native Windows scanner
after-proof](https://github.com/get-bb/bb/actions/runs/37396098532)
passes 15 demo tests and the source scan with exactly 14 references
across six allowlisted source files.
- [Linux/Windows CI at
f4e976b](https://github.com/get-bb/bb/actions/runs/37396210581) is
green: **all 31 non-skipped checks passed** (three intentionally
skipped).

Diff scope: four production/tooling files (+392/-317, mostly
replay-helper try/finally indentation) and 23 tests/support files
(+745/-230).

> AGENT GENERATED
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