Skip to content

one-shot vitest failure on the first run after npm install — twice now, never on rerun #334

Closed

Description

@lex00

Twice (2026-08-30, both on merged main during merge verification): npm test fails exactly one test file on the FIRST run after npm install, then passes fully on every rerun — three consecutive greens after the first occurrence, immediate green after the second. Both times the failing file's identity was lost (default reporter, output truncated); occurrences were post-#319 (1 failed | 68 passed) and post-#333 (1 failed | 74 passed, 1419/1420 tests).

The install correlation is the lead: suspect something first-run — a vite/vitest cache rebuild race, an esbuild binary rebuild, or a port grabbed by a route test while another file's server is slow to release on cold import. To catch it: run the suite with a file reporter (npx vitest run > log 2>&1) right after a fresh npm install, repeatedly; the log names the file the terminal lost. CI has never shown it.

🤖 Claude Code — https://claude.ai/code/session_01Rfs1mLVWmwginHnDTg75sG

Activity

  1. lex00 commented on Aug 31, 2026

    @lex00
    ContributorAuthor

    Third occurrence (2026-08-30, after merging #339): 6 failed tests in 1 file on the first npm test after git pull — NO npm install this round, so the install correlation weakens. Refined pattern: first suite run after the working tree changes fails, immediate rerun green (exit 0, 1509/1509). Suspicion shifts to a vite/vitest transform-cache invalidation race on changed modules. Still never in CI. Same capture failure: the default reporter's output didn't survive the terminal buffer — next occurrence, run npx vitest run > log 2>&1 FIRST, not second.

    🤖 Claude Code — https://claude.ai/code/session_01Rfs1mLVWmwginHnDTg75sG

  2. lex00 commented on Sep 1, 2026

    @lex00
    ContributorAuthor

    Capture fixed at the harness level: just test now tees the reporter into vitest.log (gitignored), so the next occurrence names its file without anyone remembering to redirect first. AGENTS.md says to attach that log here.

    Two data points today, both first runs after a working-tree change (a new test file, then an edit to it), both fully green (76 files / 1518 tests). So 'first run after the tree changes' is not sufficient on its own; the three earlier occurrences all followed a git pull or npm install that touched many files at once, which still fits a transform-cache race on a large invalidation better than a per-file one.

    🤖 Claude Code — https://claude.ai/code/session_01SfqZdPzrxxkCJkHgzzMacq

  3. lex00 commented on Sep 1, 2026

    @lex00
    ContributorAuthor

    Fourth data point, this one on the ORIGINAL trigger: local node_modules had chant 0.52.2 (installed Aug 29, before the #336 floor bump), so npm ci replaced chant, chant-k8s-client and their trees — the largest invalidation yet — and the first just test straight after was green (77 files / 1534 tests, exit 0, log kept). So neither 'first run after a tree change' nor 'first run after install' reproduces on demand. What the three failures still share that these four greens don't: each followed a git pull that brought in NEW test files (post-#319, post-#333, post-#339 all added tests). Next lead: a brand-new test file's first transform, not a changed one's.

    🤖 Claude Code — https://claude.ai/code/session_01SfqZdPzrxxkCJkHgzzMacq

  4. lex00 commented on Sep 2, 2026

    @lex00
    ContributorAuthor

    Fifth data point, the strongest non-repro yet: a fully fresh clone + npm ci + first npx vitest run (2026-09-01, chant 0.54.0 floor) — green, 79 files / 1584 tests, log kept. That is the maximum possible invalidation (no prior vite/vitest cache, no prior node_modules, every test file "new" to the transform cache), so "a brand-new test file's first transform" alone can't be sufficient either — a fresh clone makes EVERY file's transform new and stays green.

    What the three failures still uniquely share: git pull into an EXISTING clone bringing new test files into a WARM vitest cache. Next lead narrowed accordingly: a stale-cache + new-file interaction, not cold-start.

    PR #351 makes the capture permanent: every run now writes .vitest-last.json, so the next occurrence names its file without anyone remembering to redirect.

  5. lex00 commented on Sep 10, 2026

    @lex00
    ContributorAuthor

    Another one, on PR #405's first CI run: src/carve-route.test.ts > finds the manifests in the project's carveout and publishes what they record timed out at 5008ms against the 5000ms default (it took 4694ms on #395's green run). Passed on gh run rerun --failed with nothing changed. Run: https://github.com/INTENTIUS/behold/actions/runs/34526528032. That test is a fixed-cost chant carve spawn, so it sits right at the timeout on a slow runner; a per-test timeout of 20s on it would stop it counting as a flake.

  6. lex00 commented on Sep 10, 2026

    @lex00
    ContributorAuthor

    Found the mechanism for the CI occurrence, and closed the class it belongs to, in 57f95aa on PR #405.

    Every route test over a choudoufu estate spawned a real chant for the estate's references whenever the terraform lexicon was resolvable — src/choudoufu-refs.ts's readEstateLexicon runs chant graph over a scratch project — three to four seconds a test on a laptop and 5.008 s on the runner against vitest's five-second default. The tests never asked for edges; the fake choudoufu answered the roster and the lexicon spawn rode along. createApp's test seam now switches that read off beside setChoudoufuRunner (a test that wants edges hands in a reader over a recorded lexicon IR), and the three affected files drop from seconds to milliseconds. The one remaining real spawn, carve status over a project in src/carve-route.test.ts, keeps its cost and the suite's budget is 20 s (vitest.config.ts), which still catches a hang.

    The three earlier occurrences lost their file names, so this cannot be proved to be the same class; it fits — each followed a pull that added test files, and a bigger suite is more spawns in parallel on a warm cache, which is exactly what pushes a fixed-cost spawn past a fixed budget. Closing on that; reopen if a first-run failure names a file that spawns nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions