{"id":"2c50a41ab2cc777a","repo":"vitest-dev/vitest","slug":"cannot-set-concurrency-id-because-there-are-no-val","errorCode":null,"errorMessage":"Cannot set concurrency id because there are no valid free ids.","messagePattern":"Cannot set concurrency id because there are no valid free ids\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/pools/pool.ts","lineNumber":278,"sourceCode":"    if (customPool != null && customPool.name === task.worker) {\n      return new PoolRunner(options, customPool.createPoolWorker(options))\n    }\n\n    throw new Error(`Runner ${task.worker} is not supported. Test files: ${formatFiles(task)}.`)\n  }\n\n  private getConcurrencyId() {\n    let concurrencyId: number | undefined\n\n    this.workerIds.forEach((state, id) => {\n      if (state && concurrencyId == null) {\n        concurrencyId = id\n        this.workerIds.set(id, false)\n      }\n    })\n\n    if (concurrencyId == null) {\n      throw new Error('Cannot set concurrency id because there are no valid free ids.')\n    }\n\n    return concurrencyId\n  }\n\n  private freeWorkerId(id: number) {\n    this.workerIds.set(id, true)\n  }\n}\n\nfunction withResolvers() {\n  let resolve = () => {}\n  let reject = (_error: unknown) => {}\n\n  const promise = new Promise<void>((res, rej) => {\n    resolve = res\n    reject = rej\n  })","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/pools/pool.ts#L260-L296","documentation":"Internal assertion in Pool.getConcurrencyId: it scans the workerIds map for the first free id but finds none. workerIds is initialized in setMaxWorkers to exactly maxWorkers entries (1..maxWorkers), so having no free id while scheduling a new task means more tasks were started in parallel than maxWorkers allows — an invariant violation in the scheduler.","triggerScenarios":"schedule() starts a task and calls getConcurrencyId() at packages/vitest/src/node/pools/pool.ts:267-278, but every id in workerIds is already marked used. This implies the activeTasks count exceeded maxWorkers or workerIds was not sized correctly via setMaxWorkers.","commonSituations":"An internal scheduling bug where activeTasks.length guard at pool.ts:68 is bypassed; maxWorkers set to 0 by a config edge case; a regression in id freeing (freeWorkerId).","solutions":["Report as a Vitest bug with reproduction; this is a scheduler invariant, not a config error.","Verify maxWorkers is a positive integer (>=1) in config to rule out a 0-sizing edge case.","Retry with a different pool ('threads' vs 'forks') to see if the bug is pool-specific.","Avoid mixing isolate:false runner reuse if it correlates with the failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure maxWorkers is a positive integer to avoid 0-sizing the id map\nfunction validateMaxWorkers(maxWorkers) {\n  if (maxWorkers != null && (!Number.isInteger(maxWorkers) || maxWorkers < 1)) {\n    throw new Error(`maxWorkers must be a positive integer, got ${maxWorkers}`)\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vitest.start()\n} catch (e) {\n  if (e.message === 'Cannot set concurrency id because there are no valid free ids.') {\n    console.error('Pool scheduler invariant violated — report as a Vitest bug.')\n  }\n  throw e\n}","preventionTips":["Keep maxWorkers a positive integer (>=1) in config.","Pin stable Vitest versions; report persistent scheduler bugs with reproduction.","Try an alternate pool (threads vs forks) to isolate pool-specific regressions."],"tags":["pool","internal-bug","scheduling","concurrency","assertion"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}