Skip to content

fix: use err.name check for AbortError instead of instanceof Error#1867

Open
tsushanth wants to merge 1 commit into
livekit:mainfrom
tsushanth:fix/abort-error-domexception-guard
Open

fix: use err.name check for AbortError instead of instanceof Error#1867
tsushanth wants to merge 1 commit into
livekit:mainfrom
tsushanth:fix/abort-error-domexception-guard

Conversation

@tsushanth

Copy link
Copy Markdown
Contributor

Fixes #1712

DOMException, which is what AbortSignal/AbortController throws, is not instanceof Error in Node.js or Bun. As a result, guards written as:

if (err instanceof Error && err.name === 'AbortError')

never match a real abort. The instanceof Error condition is already false for DOMException, so the abort falls through to the error-level logger — producing the spurious DOMException constant table in logs on every normal turn teardown.

The .name property is not exclusive to Error subclasses; any thrown value can carry it. Dropping instanceof Error and using an optional-chaining cast:

if ((err as { name?: string })?.name === 'AbortError')

matches both Error subclasses and DOMException uniformly across runtimes, which is the same approach the Web Platform (and Node's own AbortSignal docs) recommends.

Six occurrences fixed across the agents package and the Google, ElevenLabs, and OpenAI plugins.

DOMException (thrown by AbortSignal/AbortController) is not instanceof
Error in Node and Bun, so guards of the form:

  if (err instanceof Error && err.name === 'AbortError')

never match. The instanceof check is redundant for the name property
since any thrown value can carry it. Replace all six occurrences across
agents and plugins with:

  if ((err as { name?: string })?.name === 'AbortError')

This silences the spurious error-level log noise on normal turn and
session teardown that triggered livekit#1712.
@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3d04163

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review


// Handle timeout errors
if (error instanceof Error && error.name === 'AbortError') {
if ((error as { name?: string })?.name === 'AbortError') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Incomplete transformation — several locations still use the old pattern

The PR changes 8 locations but leaves several others untouched that have the same instanceof Error && ... === 'AbortError' pattern:

  • agents/src/inference/tts.ts:883 and :895
  • agents/src/stream/deferred_stream.ts:34
  • plugins/elevenlabs/src/tts.ts:920
  • plugins/inworld/src/tts.ts:455

These remaining locations could hit the same DOMException-not-instanceof-Error issue. The deferred_stream.ts:34 case has a valid reason to keep instanceof Error since it accesses e.message afterward, but the others (inference/tts.ts, elevenlabs/tts.ts:920, inworld/tts.ts) appear to just return/ignore the error and would benefit from the same fix.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EOU detection AbortError logged at error level - abort guard misses DOMException (instanceof Error + "This" vs "The")

1 participant