Skip to content

Clear agent-connect timeout when a session ends early - #1469

Merged
1egoman merged 2 commits into
mainfrom
fix/agent-timeout-leak
Oct 12, 2026
Merged

1egoman merged 2 commits into
mainfrom
fix/agent-timeout-leak

Conversation

@1egoman

@1egoman 1egoman commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

useAgentTimeoutIdStore kept the timer id in React state, so the cleanup in useAgent called a clearAgentTimeout captured in an earlier render where the timeout id was still null. Because of this, the timer was never cleared, and therefore if the session ended within the timeout window it could fire later and cause an unrelated /newly started session to fail.

To fix this, store the timer id in a ref so start/clear always see the current timer. This also makes both callbacks have stable stable references, as a nice side effect.

I have tested this locally and starting a session, then waiting a few seconds, then stopping, then starting again wil lwait the full 20s before throwing an error.

Fixes #1468

useAgentTimeoutIdStore kept the timer id in React state, so the cleanup in
useAgent called a clearAgentTimeout captured in an earlier render where the id
was still null. The timer was never cleared, and if the session ended within
the timeout window it could fire later and fail a newly started session.

Store the timer id in a ref so start/clear always see the current timer. This
also makes both callbacks stable.

Fixes #1468

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 74e7ea2

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

This PR includes changesets to release 6 packages
Name Type
@livekit/components-react Patch
@livekit/agents-ui Patch
@livekit/component-example-next Patch
@livekit/components-js-docs Patch
@livekit/component-docs-storybook Patch
@livekit/components-docs-gen 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

@vercel

vercel Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
components-js-storybook-5kld Ready Ready Preview Oct 11, 2026 7:56pm UTC

Request Review

Drop the effect harness and call the store's callbacks directly, using the
exported DEFAULT_AGENT_CONNECT_TIMEOUT_MILLISECONDS for the timeout.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
LiveKitRoom only 7.91 KB (0%)
LiveKitRoom with VideoConference 32.61 KB (0%)
All exports 44.55 KB (-0.06% 🔽)

@1egoman
1egoman merged commit 21c767b into main Oct 12, 2026
5 checks passed
@1egoman
1egoman deleted the fix/agent-timeout-leak branch October 12, 2026 18:37
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026

This branch was successfully deployed

1 active deployment
Preview — 74e7ea2a Deployed Oct 11, 2026 by vercel[bot]
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.

useAgent: the agent-connect timer leaks when a session ends early, and fails the next start()

2 participants