Skip to content

test(scf-core): the suite OOMs before it can complete, so it can never be un-excluded #504

Closed

Description

@thinkclay

Found while repairing the scf-core suite (see the PR that fixes its load failures).

What happens

A full run of scf-core dies with a JS heap OOM — SIGABRT, not test failures:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Command was killed with SIGABRT (Aborted):
  vitest run --config packages/scf-core/vitest.config.ts

Reproduced at both --max-old-space-size=4096 and 8192. Zero assertions fail before it
dies; the process just runs out of heap partway through.

Why

vitest.config.ts uses pool: "threads" (line 255) with maxWorkers: 2. Threads share a
heap, so nothing is reclaimed between the 329 test files — memory accumulates across the
whole run. The comment on line 256 ("Cap workers to 2 to prevent OOM on 14-CPU machines")
shows this has been fought before; capping workers reduced the pressure without removing
the cause.

The suite got heavier recently, legitimately: three assessment-wizard files used to abort
on import and cost nothing, and now render real component trees. That accelerates the OOM
but did not create it.

Why it has stayed invisible

scf-core is excluded from every aggregate command, so nothing ever tries to run it whole:

  • package.json:12 — affected:test --exclude=…,scf-core
  • package.json:158 — test:unit --exclude=…,scf-core
  • scripts/prepush.sh:32 — TEST_EXCLUDES="…,scf-core,scaffald"

This is the blocker for dropping those exclusions. A suite that cannot complete cannot gate
merges, and un-excluding it as-is would trade an invisible problem for a permanently red
check — the same failure mode as the 80%-vs-37% coverage threshold removed in #492.

Suggested fix

Try pool: "forks" for this project. Each file gets a fresh process and its heap is
reclaimed on exit. Slower per file, but bounded. Was mid-verification when this was filed:

pnpm exec vitest run --config packages/scf-core/vitest.config.ts --pool=forks --maxWorkers=2

(Note --poolOptions.forks.maxForks is not a valid CLI flag in vitest 4 — it fails with
CACError: Unknown option. Set pool options in the config file, or use --maxWorkers.)

If forks alone is not enough, the next step is finding which file leaks — OrganizationForm.test.tsx
is already excluded in packages/scf-core/vitest.config.ts for an "infinite render loop → OOM
after 5 min", so there is precedent for a single file being the cause.

Acceptance

pnpm exec nx run scf-core:test completes and reports a result, then scf-core is removed
from the three exclusion lists above so the suite actually gates merges.

Gotcha for whoever picks this up

When the run aborts, the JSON reporter leaves the previous run's file behind at
tests/reports/coverage/test-results.json. Reading it after a crash gives a plausible-looking
but stale result (I was briefly fooled by a "56 tests, 0 failures" that belonged to an earlier
run). Delete the report before each run.

Activity

  1. added
    bug
    agent-ready
    on Jul 30, 2026
  2. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    pool: 'forks' fixes it. Confirmed — the suite completes for the first time:

    pnpm exec vitest run --config packages/scf-core/vitest.config.ts --pool=forks --maxWorkers=2
    
    921 tests | 829 passed | 31 failed | 58 skipped
    333 files | 17 failed files
    

    A real result instead of a SIGABRT. Rolling the config change into the scf-core repair PR, so
    the "suite can complete" half of this issue is handled there.

    What this issue should now track: the 31 remaining failures

    They are genuine assertion failures, not infrastructure. Top clusters:

    File Failing
    features/discover/components/__tests__/UserProfilePanel.test.tsx 18
    features/discover/components/__tests__/MapSearchInput.test.tsx 7
    features/office/teams/components/__tests__/TeamForm.test.tsx 4
    features/riasec-assessment/RIASECAssessmentWidget.test.tsx 1
    features/occupation-assessment/OccupationAssessmentWidget.test.tsx 1

    MapSearchInput is worth a closer look: it passed when run in a small group during the
    repair work and fails in the full run, which points at cross-file state leakage rather than a
    broken assertion. Forks isolate per file, so this is more likely shared module-level state or
    an unreset mock than pool behaviour.

    Un-exclusion still blocked, and that is deliberate

    scf-core stays in the exclusion lists (package.json:12, package.json:158,
    scripts/prepush.sh:32) until these 31 are green. Removing them now would make every merge
    red — the failure mode #492 removed with the 80%-vs-37% coverage threshold. The suite being
    runnable is the prerequisite; being green is what earns the gate.

    Note on cost

    Forks are slower than threads — a full run is several minutes. That is fine for a suite that
    previously could not finish at all, but it is an argument for keeping scf-core on
    nx affected rather than running it whole on every push once it is un-excluded.

  3. thinkclay commented on Aug 12, 2026

    @thinkclay
    ContributorAuthor

    Confirmed still reproducing on main as of 2026-08-12, with a sharper diagnosis than the original report.

    I briefly claimed this was stale and un-excluded scf-core in #604. That was wrong — I had grepped a background task's output file for the OOM string and got nothing, because that file held only my own echo lines while vitest's stderr went elsewhere. Reverted in #606.

    What actually happens

    FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed
    [13047] 883859 ms: Mark-Compact 4049.8 (4129.2) -> 4034.1 (4129.0) MB
    
    heap files assertions report success exit
    --max-old-space-size=4096 142 957 passed, 0 failed true 1
    --max-old-space-size=8192 143 978 passed, 0 failed true 1

    Three things worth pulling out:

    1. Every test passes. The JSON report says success: true in both runs. Nothing is failing; the process is dying.
    2. It is the parent, not the workers. pool: 'forks' is already in packages/scf-core/vitest.config.ts and each worker's heap goes away when it exits. What grows is the main process.
    3. A bigger ceiling does not fix it. 8GB gets further and then dies anyway — and it dies sooner in relative terms once more files collect successfully, which is what happens after the collection failures fix(test): revert the scf-core un-exclude — the suite still cannot exit clean (#504, #593) #606 repaired.

    So the tractable target is whatever the parent retains per file across 143 files. Candidates worth measuring, in rough order of suspicion: the json reporter accumulating every assertion result (reporters: [..., ['json', { outputFile: ... }]] in the root config), the v8 coverage map merge, and the transform cache for the module graph.

    Until that is fixed, scf-core cannot be in test:unit or affected:test, which keeps #593 open.

  4. thinkclay commented on Aug 12, 2026

    @thinkclay
    ContributorAuthor

    Bisected this today. Three hypotheses ruled out, and there is now a deterministic 7-minute reproducer instead of a 15-minute one.

    Reproducer

    NODE_OPTIONS=--max-old-space-size=4096 npx vitest run \
      --config packages/scf-core/vitest.config.ts --reporter=dot --shard=3/12

    Reproduced on every attempt. Neighbouring shards are clean, which makes A/B testing a fix cheap:

    shard files result wall clock
    1/6 24 clean 7.4s
    2/6 24 OOM 461s
    3/12 12 OOM 452s
    4/12 12 clean 3.5s

    Ruled out

    Not the json reporter. --reporter=dot with no json output still OOMs. (It does give clean numbers: 139 passed | 3 skipped of 143 files, 978 assertions.)

    Not a single heavy file. The obvious suspects in the failing shard — OccupationAssessmentWidget, OccupationAssessmentWizard, RIASECAssessmentWidget, RIASECAssessmentWizard — each pass alone, fast. So does no-duplicate-vi-mock, which walks the tree.

    Not raw file count. 24 files pass in 7s; a different 12 files OOM after 452s.

    The strongest signal

    Duration  452.54s (transform 332ms, setup 3.6s, import 3.9s, tests 4.68s, environment 10.2s)
    

    Tests execute in 4.68 seconds. The other ~440 are the parent process mark-compacting against the 4GB ceiling — it is thrashing, not working. Combined with pool: 'forks' already isolating each file's own heap, that points at what the parent retains per file: the Vite module graph / transform cache for these particular dependency trees (react-native-web, charts, svg), not anything the tests themselves allocate.

    Raising the ceiling does not help — at 8192 it gets further and dies anyway, and dies sooner in relative terms once more files collect successfully.

    The 12 files in the failing shard: vitest list --config packages/scf-core/vitest.config.ts --shard=3/12.

    Keeps #593 blocked.

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

    DXagent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions