Skip to content
Latchkey

Test Sharding "CI_NODE_INDEX" Misconfig - Tests Skipped or Duplicated

Tests are split across parallel CI machines by shard index/total, but the env vars (CI_NODE_INDEX/CI_NODE_TOTAL, or --shard=i/n) are wrong. Shards overlap, skip files, or one node runs the whole suite.

What this error means

A shard runs zero tests ("No tests found" on a high index), runs the entire suite (total defaulted to 1), or coverage/results look duplicated. Off-by-one indexing (0-based vs 1-based) is the usual culprit.

CI log
# Playwright shards are 1-based: --shard=index/total
$ npx playwright test --shard=0/4
Error: Shard index must be bigger than 0.

# or a shard quietly runs everything because CI_NODE_TOTAL was unset

Common causes

Off-by-one or unset shard index/total

Mixing 0-based and 1-based indexing, or leaving CI_NODE_TOTAL/--shard total unset, makes a shard empty or makes every node run the full suite.

Index not unique per parallel job

The matrix did not inject a distinct index per machine, so multiple shards run the same slice and others are never run.

How to fix it

Pass a correct, unique shard per job

.github/workflows/ci.yml
# Playwright (1-based)
strategy:
  matrix:
    shard: [1, 2, 3, 4]
steps:
  - run: npx playwright test --shard=${{ matrix.shard }}/4

Map CI env vars to the runner's scheme

  1. Confirm whether your runner is 0-based (CI_NODE_INDEX often 0..N-1) or 1-based.
  2. Set both index and total explicitly per parallel job.
  3. Merge per-shard reports/coverage afterward so nothing is double-counted.

How to prevent it

  • Derive shard index and total from the matrix, not hardcoded values.
  • Document the indexing scheme (0- vs 1-based) for your runner.
  • Add a check that the union of shards covers every test file.

Frequently asked questions

What causes "Sharding env misconfig"?
Mixing 0-based and 1-based indexing, or leaving CI_NODE_TOTAL/--shard total unset, makes a shard empty or makes every node run the full suite.
How do I fix Sharding env misconfig?
Pass a correct, unique shard per job

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card