Skip to content

Pre-push gate fails intermittently: perf assertions measured under coverage instrumentation #1975

Closed

Description

@malibio

Symptom

bun run test:coverage (which the pre-push gate runs via test:all) fails intermittently on an otherwise idle machine, with a different test failing each run. Observed across unmodified main, a feature branch, and that branch's parent commit — so it is not tied to any change.

Failures seen:

Test Assertion Observed
architecture-benchmarks bulk structural ops < 25ms 25.17ms, 25.97ms, 26.31ms
mcp-integration avgUpdateTime > 0 0
navigation-service (2 tests) Maximum call stack size exceeded
core-plugins viewer lazy-load timeout at 5000ms

Each passes in isolation, which is what made it easy to dismiss as machine load.

Root cause (measured, for the first two)

Not parallelism. vitest.config.ts sets pool: 'forks' with singleFork: true and sequence.concurrent: false — every file runs sequentially in one process.

The trigger is V8 coverage instrumentation, which the gate runs and plain bun run test does not. Same benchmark, same machine, back to back:

uninstrumented (bun run test):        13.32ms
instrumented (test:coverage):         22.56ms    ~1.7x
budget:                               25ms

A 25ms budget leaves ~10% headroom over instrumented execution, so ordinary run-to-run variance crosses it. These are mis-specified assertions, not flaky ones — they assert uninstrumented performance in an instrumented run.

avgUpdateTime > 0 is the same class of defect: a performance.now() delta over an in-memory update legitimately measures exactly 0 when the work fits inside the clock's resolution. It asserts that the timer ticked, not that the store recorded anything.

Fixed in this issue's PR

  • test:coverage sets NODESPACE_TEST_COVERAGE=1, forwarded to forked workers via env in vitest.config.ts (a shell-level var does not otherwise reach test code — verified).
  • Perf budgets scale by a documented factor under coverage, so an uninstrumented run keeps the tight bound that makes the test worth having.
  • Architecture targets split from measurement budgets (ARCHITECTURE_TARGETS vs PERF_THRESHOLDS), so a measurement allowance can never silently weaken a committed target. The existing validates all performance targets are achievable test now checks the un-relaxed numbers.
  • Both avgUpdateTime > 0 sites (mcp-integration, shared-node-store) assert non-negative and finite instead.

Result: 3 consecutive clean test:coverage runs (4309 tests), where previously roughly every other run failed.

Still open — navigation-service stack overflow

Not fixed, and not explained. Maximum call stack size exceeded in two navigation-service tests, under coverage in a full run only.

The obvious suspect is ruled out: resolveNavigationAncestor is a bounded while loop with an explicit visited cycle guard, not recursion. It cannot overflow on its own. So the stack is being exhausted by something else in the shared single-fork process, and navigation-service is only where it surfaces.

Worth a separate investigation rather than a guess. Reproduce with a full bun run test:coverage; it does not reproduce for that file alone, with or without --coverage.

Related

scripts/test-gate.ts documents the same class of problem for the Rust suite (#1610), where --test-threads=2 still reproduced and only =1 resolved it.

Activity

  1. added
    bug
    on Aug 4, 2026
  2. malibio commented on Aug 5, 2026

    @malibio
    CollaboratorAuthor

    Follow-up scoping from PR #1976 review — the sweep for sibling instances found more than the two fixed, and the distinction that matters is which files the gate actually runs.

    FIXED in #1976: architecture-benchmarks (perf budgets now scale under coverage), and both avgUpdateTime > 0 sites (mcp-integration, shared-node-store).

    NOT fixed, still latent:

    • src/tests/patterns/performance.test.ts uses 0.01ms / 0.05ms budgets — roughly 1000x tighter than the 25ms budget that actually broke.
    • Two integration/ sites use 10ms budgets (textnode-contentprocessor, multi-tab-reactivity).

    The asymmetry: src/tests/performance/** is excluded from the gate's run (vitest.config.ts), but patterns/ and integration/ are NOT. So the remaining un-scaled budgets live in exactly the files that can block a push. They pass today, but they are measured under the same V8 instrumentation (~1.7x on the benchmarks we measured) with far less headroom than the one that failed.

    Deliberately not mechanically applying the same budget() helper to them: each budget should be calibrated against its own measured instrumented cost, otherwise we are just moving arbitrary numbers around. That is its own piece of work.

    Also noted and deliberately not fixed: the 'lookup' threshold is vacuous — 0.0004ms measured against a 1ms budget, i.e. 2500x headroom before #1976 doubled it. Pre-existing, unrelated to the coverage issue, and fixing it is a calibration question rather than a correctness one.

    The navigation-service stack overflow remains open and unexplained.

  3. malibio commented on Aug 5, 2026

    @malibio
    CollaboratorAuthor

    Third follow-up from PR #1976 review — a semantic question left open deliberately.

    updateNode's finally records timing for an update that threw AFTER the optimistic update applied. Verified pre-existing: main's finally calls recordMetric unconditionally, so failed updates have always been timed. PR #1976 strictly narrows the recorded set (skipped updates no longer count), so it is not a regression — but it does leave a tension with that PR's own stated principle, 'only time work that happened'.

    The open question is genuinely semantic, not mechanical: does a half-applied update belong in the mean?

    Arguments for counting it: the optimistic update DID apply and updateCount WAS incremented before the throw. Excluding it would break the 'exactly one recordMetric per updateCount increment' invariant that #1976 established, and would leave updateCount counting a sample the average excludes — reintroducing the two-populations problem that PR just fixed, in mirror image.

    Arguments against: failing paths are plausibly slower than succeeding ones, so including them skews the mean upward, and the metric is nominally about update performance rather than failure performance.

    Whichever way it goes, the fix is one line (didUpdate = false in the catch) plus a decision about what updateCount is counting — attempts, applications, or successes. That third definition is the actual missing piece: today updateCount means 'optimistic update applied', which is neither 'attempted' nor 'succeeded'.

    Not fixed in #1976 because it is a judgment call rather than a defect, and that PR had already expanded from test assertions into production code once.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions