eduos-vitest-load-sensitive-test-flake-derace
The solution document is written to /workspace/solution.md (332 lines). Since the EduOS repo itself is not present in this environment (only /workspace/problem.json), I produced a self-contained, directly-applicable fix document rather than editing repo files.
Root-cause analysis — separates the two conflated mechanisms:
- Mechanism A (real ordering bugs): assertions read outside the waitFor poll → setInterval spy read 0 >= 1; document.activeElement read before ErrorState's focus useEffect committed (fail at 103ms).
- Mechanism B (environment/budget): vitest's 5s default vs. genuinely CPU/timer-bound work (proxy-role WebCrypto 10.4s isolated; dashboard cold-start ~5.4s loaded).
- Why not retry: it masks deterministic races and real regressions fleet-wide.
The exact fix (§2), matching commit fa6516e7:
1. Fold every async-dependent assertion inside the same waitFor (window unclosable) — before/after code for both race tests.
2. Widen the console.error spy window until all async sibling flows settle before judging/restoring the spy.
3. Per-test 20_000 timeouts only for the two crypto/timer tests, with a row-cited justification table (failure, isolated duration, headroom).
4. Verify vitest.config.ts has no global retry and no global timeout bump.
Verification (§4) — concrete commands and acceptance criteria: 68/68 isolated ×2, 1585/1585 full suite ×2, no-retry grep, repro under nproc CPU saturation, plus --no-file-parallelism/--sequence.shuffle cross-checks and a "prefer fake timers for synthetic delays" note.
Diagnostic recipe and an anti-pattern table round it out for reuse.
One caveat worth flagging: the file/test paths appear as <path/to/...> placeholders because the actual repo isn't mounted here. If you point me at the web root (or mount the repo), I can substitute the real paths and run the verification commands to confirm green.
# Evidence - Problem class: eduos-vitest-load-sensitive-test-flake-derace - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-22T09:06:57.095Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "EduOS web suite (vitest 5, jsdom, per-file isolation): four tests pass in isolation 4x but fail once each under full-suite parallel load. Mechanisms diagnosed: (a) assertion read racing an async state commit (setInterval spy read AFTER a waitFor window closes - 0>=1 failure; focus assertion one-shot read before ErrorState focus useEffect commits - fail at 103ms); (b) timer-driven test chains exceeding the vitest-default 5s per-test timeout under CPU starvation (proxy-role ~35MB WebCrypto test died at 5s while passing alone in 10.4s; dashboard cold-start died ~5.4s wall). Fix shape that landed (commit fa6516e7): read raciness INSIDE waitFor polls (contract unchanged, window unclosable); widen the observed window to settle ALL async sibling flows before closing a spy-on-console-error window; per-test timeout bumps (20s) ONLY for crypto/timer-bound tests with row-cited justification; NO global test.retry in vitest.config.ts (masks real failures fleet-wide). Result: 4 files 68/68 isolated x2, full web suite 1585/1585 x2 runs, 0 failed.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "eduos-vitest-load-sensitive-test-flake-derace", "provider": "openrouter", "solved_at": "2026-09-22T09:06:57.098Z", "version": ""}