{"record":{"id":"5969ce8c713955de","repo":"vitest-dev/vitest","slug":"test-specification-for-task-id-was-not-found","errorCode":null,"errorMessage":"Test specification for task ${id} was not found","messagePattern":"Test specification for task (.+?) was not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/core.ts","lineNumber":1284,"sourceCode":"      this.report('onWatcherRerun', files, trigger),\n      ...this._onUserTestsRerun.map(fn => fn(specifications)),\n    ])\n    const testResult = await this.runFiles(specifications, allTestsRun)\n\n    await this.report('onWatcherStart', this.state.getFiles(files))\n    return testResult\n  }\n\n  /** @internal */\n  async rerunTask(id: string): Promise<void> {\n    const task = this.state.idMap.get(id)\n    if (!task) {\n      throw new Error(`Task ${id} was not found`)\n    }\n\n    const reportedTask = this.state.getReportedEntityById(id)\n    if (!reportedTask) {\n      throw new Error(`Test specification for task ${id} was not found`)\n    }\n\n    const specifications = [reportedTask.toTestSpecification()]\n    await Promise.all([\n      this.report(\n        'onWatcherRerun',\n        [task.file.filepath],\n        'tasks' in task ? 'rerun suite' : 'rerun test',\n      ),\n      ...this._onUserTestsRerun.map(fn => fn(specifications)),\n    ])\n    await this.runFiles(specifications, false)\n    await this.report(\n      'onWatcherStart',\n      ['module' in reportedTask ? reportedTask.module.task : reportedTask.task],\n    )\n  }\n","sourceCodeStart":1266,"sourceCodeEnd":1302,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/core.ts#L1266-L1302","documentation":"After the task is found in idMap, getReportedEntityById(id) must return a reported entity convertible to a spec. If it returns null, the task exists internally but has no reported entity (e.g. reporting hasn't run, entities were cleared, or a mid-watch race). The message signals an inconsistency between idMap and reported entities.","triggerScenarios":"rerunTask(id) where state.idMap.get(id) is truthy but state.getReportedEntityById(id) returns null/undefined — typically during teardown, state clear, or before onInit/reporting has built reported entities.","commonSituations":"State cleared mid-watch; task registered before its reported entity; race during file invalidation; calling rerunTask before the initial report cycle completes.","solutions":["Ensure onInit/reporting has run so reported entities are built before rerunning.","Avoid calling rerunTask during teardown or invalidation windows.","Re-collect to rebuild reported entities, then rerun."],"exampleFix":"// before\nawait vitest.rerunTask(id)\n\n// after\nconst entity = vitest.state.getReportedEntityById(id)\nif (!entity) {\n  await vitest.collect()\n}\nif (vitest.state.getReportedEntityById(id)) {\n  await vitest.rerunTask(id)\n}","handlingStrategy":"validation","validationCode":"function hasReportedEntity(state, id) {\n  return state.getReportedEntityById(id) != null\n}\n// before: if (!hasReportedEntity(vitest.state, id)) await vitest.collect()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let onInit/reporting complete before issuing rerunTask calls.","Avoid rerunTask during teardown or file invalidation windows.","If the entity is missing, re-collect to rebuild reported entities."],"tags":["watcher","rerun","reported-entity"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}