vercel/ai · error · DOMException

The operation was aborted.

Error message

The operation was aborted.

What it means

Before invoking a host tool (or during a race against an abort signal) in code-mode, the code checks the AbortSignal and throws if it has already fired. The thrown reason is the signal's reason if present, otherwise an 'The operation was aborted.' error. This is the standard cancellation mechanism for tool invocations.

Source

Thrown at packages/code-mode/src/tool-invocation.ts:259

  const onAbort = () => {
    rejectOnAbort(abortReason(abortSignal));
  };

  abortSignal.addEventListener('abort', onAbort, { once: true });
  if (abortSignal.aborted) {
    onAbort();
  }

  try {
    return await Promise.race([operation, aborted]);
  } finally {
    abortSignal.removeEventListener('abort', onAbort);
  }
}

function throwIfAborted(abortSignal: AbortSignal | undefined): void {
  if (abortSignal?.aborted) {
    throw abortReason(abortSignal);
  }
}

function abortReason(abortSignal: AbortSignal): unknown {
  return (
    abortSignal.reason ??
    new DOMException('The operation was aborted.', 'AbortError')
  );
}

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Check and respect abortSignal.reason to distinguish custom abort causes.
  2. Catch and handle the abort error in the calling code and clean up (this is expected cancellation, not a bug).
  3. If aborts are unintended, audit the AbortController wiring/timeouts passed to the tool invocation.
  4. Pass a properly-scoped AbortSignal (e.g. request-scoped) instead of a long-lived already-aborted signal.

Example fix

// before
const result = await invokeHostTool(tool, args); // throws on abort
// after
try {
  const result = await invokeHostTool(tool, args, { abortSignal });
} catch (e) {
  if (abortSignal.aborted) return; // handle cancellation gracefully
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (abortSignal?.aborted) {
  // skip invocation entirely or return a cancellation result early
}

Type guard

function isAbortError(e: unknown): boolean {
  return e instanceof Error && e.name === 'AbortError';
}

Try / catch

try {
  await invokeHostTool(tool, args, { abortSignal });
} catch (e) {
  if (isAbortError(e) || abortSignal?.aborted) return; // expected cancellation
  throw e;
}

Prevention

When it happens

Trigger: AbortSignal.abort() called (e.g. via AbortController.abort(), timeout, or user cancellation) before or during invokeHostTool / raceAgainstAbort in a code-mode tool invocation.

Common situations: Request cancellations from clients disconnecting; tool invocation timeouts; explicit abort of long-running host tool calls; race conditions where abort fires before the tool starts.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/0f3030d3dc5971f9. Report an issue: GitHub.