Skip to content

fix(avatar): handle clear-buffer RPC failures#2045

Open
smorimoto wants to merge 4 commits into
livekit:mainfrom
smorimoto:fix/avatar-clear-buffer-rpc-failures
Open

fix(avatar): handle clear-buffer RPC failures#2045
smorimoto wants to merge 4 commits into
livekit:mainfrom
smorimoto:fix/avatar-clear-buffer-rpc-failures

Conversation

@smorimoto

Copy link
Copy Markdown
Contributor

Problem

DataStreamAudioOutput.clearBuffer() starts LocalParticipant.performRpc() and discards the returned promise. If the remote avatar participant disconnects while interruption clean-up is running, the RPC can reject with Failed to send, producing a process-level unhandled rejection even though the session can continue.

Solution

Treat the clear-buffer RPC as intentionally fire-and-forget and attach a rejection handler. Failed calls are reported through the existing logger with the destination identity, whilst the synchronous clearBuffer(): void contract remains unchanged.

This keeps interruption clean-up non-blocking and avoids changing callers for an RPC whose recipient may already be unavailable. A focussed regression test covers the rejected RPC path, and a patch changeset records the fix.

Verification

  • pnpm test -- agents/src/voice/avatar/datastream_io.test.ts
  • pnpm exec eslint -f unix agents/src/voice/avatar/datastream_io.ts agents/src/voice/avatar/datastream_io.test.ts
  • pnpm exec prettier --check agents/src/voice/avatar/datastream_io.ts agents/src/voice/avatar/datastream_io.test.ts .changeset/catch-avatar-clear-buffer-rpc.md
  • pnpm --filter @livekit/agents typecheck
  • pnpm build:agents

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9d162b4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 37 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-azure Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

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

@smorimoto
smorimoto marked this pull request as ready for review July 16, 2026 08:49
@smorimoto
smorimoto requested a review from a team as a code owner July 16, 2026 08:49

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@toubatbrian toubatbrian 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.

The regression test currently uses room as unknown as Room, which violates this repository's explicit no-typecast rule.

Please replace it with a real typed Room fixture and mock only the required fields. I verified that this test-only change preserves rejected clear-buffer RPC coverage and passes the focused test, formatting, lint, agents typecheck, and build:agents.

@smorimoto
smorimoto requested a review from toubatbrian July 17, 2026 02:39
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Preserve the clear call's segment boundary so delayed failures do not finish newer audio. Cover the failure behaviour with typed Room tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c913adfea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread agents/src/voice/avatar/datastream_io.ts Outdated
Keep the three distinct regression behaviours while removing duplicate assertions and a single-use helper.
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.

2 participants