{"record":{"id":"aab2ae3d2836edc9","repo":"mastra-ai/mastra","slug":"aborterror","errorCode":"AbortError","errorMessage":"Aborted","messagePattern":"Aborted","errorType":"exception","errorClass":"DOMException","httpStatus":null,"severity":"info","filePath":"packages/core/src/datasets/experiment/index.ts","lineNumber":497,"sourceCode":"  try {\n    if (beforeAll) {\n      // Runs inside the execution try/catch so a failing setup produces the\n      // same `failed` summary shape as any other run-level failure, with every\n      // item counted as skipped.\n      await beforeAll(hookArgs);\n    }\n\n    const pMap = (await import('p-map')).default;\n\n    await pMap(\n      items.map((item, idx) => ({ item, idx })),\n      async ({ item, idx }) => {\n        if (eventDispatcher?.failure) return;\n\n        try {\n          // Check for cancellation\n          if (executionSignal?.aborted) {\n            throw new DOMException('Aborted', 'AbortError');\n          }\n\n          const itemStartedAt = new Date();\n          const metadataSnapshot = item.metadata === undefined ? undefined : structuredClone(item.metadata);\n          const cloneMetadataSnapshot = () =>\n            metadataSnapshot === undefined ? undefined : structuredClone(metadataSnapshot);\n          const itemWithMetadataSnapshot = (): ExperimentItem => ({\n            ...item,\n            metadata: cloneMetadataSnapshot(),\n          });\n          let itemScorers: MastraScorer<any, any, any, any>[];\n          let itemStepScorers = {} as ReturnType<typeof resolveStepScorers>;\n          let scorerConfigError: ExecutionResult['error'] = null;\n\n          if (hasRunLevelScorers) {\n            itemScorers = runLevelScorers;\n            itemStepScorers = runLevelStepScorers;\n          } else if (item.scorerIds !== undefined) {","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/experiment/index.ts#L479-L515","documentation":"runExperiment throws a DOMException('Aborted','AbortError') when the caller-supplied executionSignal is aborted. This is the library's cooperative cancellation mechanism: before executing each dataset item, it checks executionSignal.aborted and raises AbortError so an in-flight experiment run can be stopped by the caller. It surfaces as a rejected promise from runExperiment and its wrappers (executeRun, startExperiment, startExperimentAsync).","triggerScenarios":"Calling startExperiment/executeRun with an AbortController signal and calling controller.abort() while the run loop is between item executions; aborting while items are queued in the concurrency pool before each item's try block runs.","commonSituations":"A user cancels an experiment run from the UI or CLI; a host times out a long-running evaluation and aborts the signal; a server shutdown handler aborts in-flight experiment runs during deployment.","solutions":["Treat AbortError as an expected control-flow outcome, not a bug: catch it and mark the experiment run as cancelled/partial rather than failed.","If aborts are unexpected, audit what holds a reference to the AbortController and remove stray abort() calls or short timeouts.","Ensure per-item results already completed are persisted; runExperiment only checks the signal between items, so completed items remain valid.","If you need mid-item cancellation, pass a per-item signal (execFn receives itemSignal) and handle AbortError inside the executor."],"exampleFix":"// before\nawait mastra.getExperiment(experimentId).start({ signal: controller.signal });\n// after\ntry {\n  await mastra.getExperiment(experimentId).start({ signal: controller.signal });\n} catch (err) {\n  if (err instanceof DOMException && err.name === 'AbortError') {\n    logger.info('Experiment run cancelled by caller');\n    return;\n  }\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"if (controller.signal.aborted) { /* don't start the run at all */ return; }","typeGuard":"function isAbortError(e: unknown): e is DOMException {\n  return e instanceof DOMException && e.name === 'AbortError' || (e instanceof Error && e.name === 'AbortError');\n}","tryCatchPattern":"try {\n  await experiment.start({ signal: controller.signal });\n} catch (err) {\n  if (isAbortError(err)) return markRunCancelled(runId);\n  throw err;\n}","preventionTips":["Create a dedicated AbortController per run and never share one across unrelated tasks.","Check signal.aborted before initiating a run.","Treat AbortError as cancellation semantics in your error taxonomy, distinct from failures.","Listen to the signal's 'abort' event to update UI state immediately."],"tags":["cancellation","abort","async"],"backgroundTag":"abort-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}