Skip to content

Projects don't inherit watch: false from vitest run, so they get half the workers in a terminal #11721

Closed

Description

@nstepien

Describe the bug

With test.projects, vitest run started from a terminal resolves every project with watch: true. Each project's maxWorkers then defaults to watch mode's half the cores instead of all cores but one, so test files run with about half the parallelism they get without projects, or when stdin isn't a TTY.

  • configDefaults.watch is !isCI && process.stdin.isTTY && !isAgent (defaults.ts).
  • vitest run sets watch: false in the CLI options, but watch isn't in PROJECT_CLI_OVERRIDES (resolveProjects.ts), so only the root config gets it. resolveTestConfig resolves each project from deepMerge({}, configDefaults, options) (resolveConfig.ts), so projects fall back to the default.
  • maxWorkers defaults from the project's own watch, with getDefaultMaxWorkers(resolved.watch) (resolveConfig.ts).
  • groupSpecs gives each group its projects' maxWorkers, and the pool runs the group with it (pool.ts, pool.ts). Browser mode's getThreadsCount reads project.config.maxWorkers too.

So the same command uses half the cores from a terminal, and all cores but one with a pipe as stdin, in CI, or from an agent. We ran into it while debugging browser-mode timeouts on Windows that only happened when an agent started the run: on our 32-core machine, the agent's runs got 31 workers, and runs from a terminal got 16 (Comcast/react-data-grid#4233).

Reproduction

package.json:

{
  "type": "module",
  "devDependencies": {
    "vitest": "5.0.5"
  }
}

vitest.config.js:

import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    reporters: ['default', './reporter.js'],
    // Without `projects`, both runs use all cores but one
    projects: [{ extends: true, test: { name: 'unit' } }]
  }
});

reporter.js:

import { availableParallelism } from 'node:os';

let running = 0;
let peak = 0;

export default class {
  onInit(vitest) {
    console.log(`stdin.isTTY: ${!!process.stdin.isTTY}, cores: ${availableParallelism()}`);
    console.log(`root config: watch ${vitest.config.watch}, maxWorkers ${vitest.config.maxWorkers}`);
    for (const project of vitest.projects) {
      console.log(`project "${project.name}": watch ${project.config.watch}, maxWorkers ${project.config.maxWorkers}`);
    }
  }

  onTestModuleStart() {
    peak = Math.max(peak, ++running);
  }

  onTestModuleEnd() {
    running--;
  }

  onTestRunEnd() {
    console.log(`at most ${peak} test files ran at once`);
  }
}

And 64 test files, test/file01.test.js to test/file64.test.js, that each take a second:

import { test } from 'vitest';

test('waits', () => new Promise((resolve) => setTimeout(resolve, 1000)));
  1. npm install
  2. Run npx vitest run from a terminal.
  3. Run echo | npx vitest run, with a pipe as stdin.

Output on a 32-core machine, without CI or agent environment variables:

# npx vitest run
stdin.isTTY: true, cores: 32
root config: watch false, maxWorkers 31
project "unit": watch true, maxWorkers 16
      Tests  64 passed (64)
   Duration  4.56s (tests 98%, import 1%)
at most 16 test files ran at once

# echo | npx vitest run
stdin.isTTY: false, cores: 32
root config: watch false, maxWorkers 31
project "unit": watch undefined, maxWorkers 31
      Tests  64 passed (64)
   Duration  3.43s (tests 98%, import 2%)
at most 31 test files ran at once

Without projects, the run from a terminal also gets watch: false and 31 workers. It's the same on main (867a5e4).

Expected behavior

Projects follow the run's watch, so vitest run defaults to all cores but one whatever stdin is. Since watch mode applies to the whole run, resolveTestConfig could take watch from the root config, as it already does for coverage (resolveConfig.ts).

System Info

System:
  OS: Windows 11 10.0.26300
  CPU: (32) x64 AMD Ryzen 9 9950X3D 16-Core Processor
  Memory: 42.61 GB / 63.58 GB
Binaries:
  Node: 26.12.1
  npm: 12.2.1
npmPackages:
  vitest: 5.0.5 => 5.0.5

Used Package Manager

npm

Validations

Activity

  1. added
    p3-minor-bug
    approved
    on Oct 25, 2026
  2. github-actions commented on Oct 25, 2026

    @github-actions

    This issue is approved, so the team accepts a pull request for it. To work on it, open a pull request against main and link this issue in its description with a closing keyword, for example Fixes #11721.

    The team accepts one pull request per issue: if another pull request for this issue is already open, a new one is closed automatically. See our pull request policy for more context.

  3. added a commit that references this issue on Oct 25, 2026
  4. locked and limited conversation to collaborators on Nov 10, 2026
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

    approvedp3-minor-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions