vitest-dev/vitest · error · Error

task "${task.name}" did not complete: received "${result.sta

Error message

task "${task.name}" did not complete: received "${result.state}"

What it means

`toBenchResult` (`default-provider.ts:49`) converts a tinybench task into a `BenchResult`, but only completed tasks are serializable. It throws when `task.result.state !== 'completed'` — e.g. `'cancelled'` or `'failed'` states that slipped past the error-aggregation step. This is a defensive guard ensuring the reporter never sees half-finished statistics.

Source

Thrown at packages/vitest/src/runtime/benchmark/default-provider.ts:49

      const errors = tinybench.tasks
        .filter(task => task.result.state === 'errored')
        .map(task => (task.result as { error: unknown }).error)
      if (errors.length === 1) {
        throw errors[0]
      }
      if (errors.length > 1) {
        throw new AggregateError(errors, 'Some benchmarks failed')
      }

      return tinybench.tasks.map(toBenchResult)
    },
  }
}

function toBenchResult(task: TinybenchTask): BenchResult {
  const result = task.result
  if (result.state !== 'completed') {
    throw new Error(`task "${task.name}" did not complete: received "${result.state}"`)
  }
  return {
    ...result,
    name: task.name,
  }
}

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Ensure benchmarks aren't aborted mid-run — check for test timeouts shorter than benchmark duration.
  2. If using a custom provider, only return tasks whose `result.state === 'completed'`.
  3. Increase the test timeout or reduce benchmark iterations so the run finishes.
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the benchmark can finish: timeouts must exceed expected runtime.
// Pass a generous timeout and don't abort the signal mid-run.
test('bench', async ({ bench }) => {
  bench('x', () => work())
}, 60_000 /* generous timeout */)

Try / catch

try {
  await reg.run()
} catch (e) {
  if (e instanceof Error && /did not complete/.test(e.message)) {
    // increase timeout / reduce iterations / avoid aborting the signal
  }
  throw e
}

Prevention

When it happens

Trigger: A benchmark aborted via the test context's `AbortSignal` (state becomes cancelled); a custom provider returning tasks in a non-completed state; tinybench returning an unexpected state.

Common situations: Test timeout aborting the benchmark run; manual cancellation; a misbehaving custom BenchmarkProvider.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/979df4d19d874923.json. Report an issue: GitHub.