Skip to content

Conversation

@KrishnaShuk
Copy link
Contributor

Description

This PR adds robust resource cleanup to the OpenAI STT and TTS plugins. It follows the AbortController pattern established in PR #849 to ensure that any in-flight network requests to the OpenAI API are properly cancelled when an agent session is terminated.

This prevents hanging processes and improves the overall stability of the framework.

Changes Made

  • plugins/openai/src/stt.ts:
    • Added a private AbortController to the STT class.
    • Implemented the close() method to trigger the abort controller.
    • Passed the abortController.signal to the OpenAI client's transcriptions.create API call, making it cancellable.

Pre-Review Checklist

  • Build passes: All builds (lint, typecheck, tests) pass locally
  • AI-generated code reviewed: Removed unnecessary comments and ensured code quality
  • Changes explained: All changes are properly documented and justified above
  • Scope appropriate: All changes relate to the PR title, or explanations provided for why they're included
  • Video demo: A small video demo showing changes works as expected and did not break any existing functionality using Agent Playground (if applicable)

Testing

  • Automated tests added/updated (if applicable)
  • All tests pass
  • Make sure both restaurant_agent.ts and realtime_agent.ts work properly (for major changes)

Note to reviewers: Please ensure the pre-review checklist is completed before starting your review.

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: d12378a

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

This PR includes changesets to release 1 package
Name Type
@livekit/agents-plugin-openai 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

@KrishnaShuk KrishnaShuk changed the title feat(openai): implement close() cleanup for STT and TTS feat(openai): implement close() cleanup for STT Dec 1, 2025
@KrishnaShuk KrishnaShuk force-pushed the fix/resources-cleanup-openai branch from af9e5f3 to e26df42 Compare December 1, 2025 13:39
@KrishnaShuk KrishnaShuk force-pushed the fix/resources-cleanup-openai branch from e26df42 to 5292105 Compare December 1, 2025 13:46
@davidzhao davidzhao requested a review from toubatbrian December 1, 2025 16:22
Copy link
Contributor

@toubatbrian toubatbrian left a comment

Choose a reason for hiding this comment

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

Looks good! Can you add a changeset?

@KrishnaShuk
Copy link
Contributor Author

Thanks! for the review @toubatbrian. I've just added the changeset.

On that note, I've noticed that other plugins (like ElevenLabs, Google, and Cartesia) are also missing this robust close() cleanup logic.
To continue improving the framework's stability, I'd be happy to create a central tracking issue to list them all and then submit a series of small, focused PRs to implement this same AbortController pattern for each one.

Lmk if that sounds like a good plan.

@toubatbrian toubatbrian merged commit 0fd3f70 into livekit:main Dec 2, 2025
5 checks passed
@github-actions github-actions bot mentioned this pull request Dec 2, 2025
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