{"record":{"id":"8758b46771599e50","repo":"vitest-dev/vitest","slug":"task-instance-was-not-found-for-runnertask-type","errorCode":null,"errorMessage":"Task instance was not found for ${runnerTask.type} \"${runnerTask.name}\"","messagePattern":"Task instance was not found for (.+?) \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/reporters/reported-tasks.ts","lineNumber":779,"sourceCode":"   */\n  readonly workerId: number\n}\n\nfunction storeTask(\n  project: TestProject,\n  runnerTask: RunnerTask,\n  reportedTask: TestCase | TestSuite | TestModule,\n): void {\n  project.vitest.state.reportedTasksMap.set(runnerTask, reportedTask)\n}\n\nfunction getReportedTask(\n  project: TestProject,\n  runnerTask: RunnerTask,\n): TestCase | TestSuite | TestModule {\n  const reportedTask = project.vitest.state.getReportedEntity(runnerTask)\n  if (!reportedTask) {\n    throw new Error(\n      `Task instance was not found for ${runnerTask.type} \"${runnerTask.name}\"`,\n    )\n  }\n  return reportedTask\n}\n\nfunction getSuiteState(task: RunnerTestSuite | RunnerTestFile): TestSuiteState {\n  const mode = task.mode\n  const state = task.result?.state\n  if (mode === 'skip' || mode === 'todo' || state === 'skip' || state === 'todo') {\n    return 'skipped'\n  }\n  if (state == null || state === 'run' || state === 'only') {\n    return 'pending'\n  }\n  if (state === 'fail') {\n    return 'failed'\n  }","sourceCodeStart":761,"sourceCodeEnd":797,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/reporters/reported-tasks.ts#L761-L797","documentation":"Internal invariant in `getReportedTask`: a `RunnerTask` handed to the reporter layer must previously have been registered in `vitest.state.reportedTasksMap` via `storeTask`. A lookup miss means the task reached a reporter/callback without being stored first — a Vitest-internal state desync, not a user configuration problem.","triggerScenarios":"A reporter or plugin iterating runner tasks receives a `RunnerTask` whose type/name was never passed through `storeTask`; typically arises from custom reporters/hooks that bypass the normal task lifecycle, or from a version mismatch between `vitest` and `@vitest/runner`/reporter packages.","commonSituations":"Third-party reporter plugins reading raw runner tasks; concurrent/sharded runs hitting a race; mixed `@vitest/*` package versions after a partial upgrade.","solutions":["Align all `@vitest/*` packages to the same version (`pnpm update -r @vitest/*@vitest/*`).","Disable custom reporters/plugins one by one to isolate which one touches the task lifecycle.","If it reproduces with stock Vitest, file an issue with the task `type`, `name`, and a minimal reproduction."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In a custom reporter: guard task lookups so a missing reported entity doesn't kill the run.\nfunction safeReportedTask(project, runnerTask) {\n  try {\n    return project.vitest.state.getReportedEntity(runnerTask)\n  } catch {\n    return null\n  }\n}","preventionTips":["Keep all `@vitest/*` packages on the same released version.","Prefer the public reporter event payloads over reaching into `vitest.state` for raw runner tasks.","If you build a custom reporter, register every task through the documented lifecycle before reading it."],"tags":["internal","reporter","state"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}