Skip to content

Add enabled gate to useVoiceAgent#1478

Merged
whoiskatrin merged 2 commits into
mainfrom
fix-1474-usevoiceagent-enabled
May 8, 2026
Merged

Add enabled gate to useVoiceAgent#1478
whoiskatrin merged 2 commits into
mainfrom
fix-1474-usevoiceagent-enabled

Conversation

@whoiskatrin
Copy link
Copy Markdown
Contributor

@whoiskatrin whoiskatrin commented May 7, 2026

Summary

Fixes #1474 by adding an enabled lifecycle gate to useVoiceAgent.

Apps that need to wait for async connection prerequisites, such as a Turnstile-backed capability token, can now keep the hook mounted without constructing or connecting a VoiceClient until those prerequisites are ready.

What changed

  • Adds enabled?: boolean to UseVoiceAgentOptions, defaulting to true for backwards compatibility.
  • Keeps useVoiceAgent in the idle/disconnected state while disabled.
  • Avoids constructing or connecting VoiceClient when enabled === false.
  • Connects with the current options when enabled flips from false to true.
  • Disconnects and resets state when enabled flips from true to false.
  • Makes hook action callbacks safe no-ops while disabled.
  • Ensures the initial disabled mount and first enable do not fire onReconnect.
  • Documents the new option and records the lifecycle decision in the voice design notes.
  • Adds a changeset for @cloudflare/voice.

Architecture note

The gate lives at the React hook seam rather than in VoiceClient or a new transport adapter. This keeps auth/bootstrap readiness local to the React lifecycle module, and avoids forcing users to encode “do not connect yet” with dormant VoiceTransport adapters.

Tests

  • npm --workspace @cloudflare/voice run build
  • npm --workspace @cloudflare/voice run test:react
  • npm run check

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

🦋 Changeset detected

Latest commit: f446414

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/voice Minor

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1478

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1478

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1478

hono-agents

npm i https://pkg.pr.new/hono-agents@1478

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1478

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1478

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1478

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1478

commit: f446414

@sort2f
Copy link
Copy Markdown

sort2f commented May 7, 2026

Thanks, this is exactly the lifecycle gate I need. Hope it gets merged/released soon!

@whoiskatrin whoiskatrin marked this pull request as ready for review May 8, 2026 08:11
Copy link
Copy Markdown
Contributor

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

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 potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

Copy link
Copy Markdown

@aron-cf aron-cf 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 👍

@whoiskatrin whoiskatrin merged commit 2c7d91b into main May 8, 2026
4 checks passed
@whoiskatrin whoiskatrin deleted the fix-1474-usevoiceagent-enabled branch May 8, 2026 10:25
@github-actions github-actions Bot mentioned this pull request May 8, 2026
threepointone added a commit that referenced this pull request May 11, 2026
* fix(voice): harden Workers AI STT turn handling

Follow up on PR #1458 by preserving Flux turn transcripts across lifecycle events and using model-detected speech start for low-latency barge-in.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(chat): harden stream resume negotiation close races

Follow-up to PR #1463: route stream-resume negotiation sends through close-safe helpers so WebSocket close races do not crash resume handling in think and ai-chat.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(voice): parse raw NDJSON text streams

Follow-up to PR #1462: make the voice text stream parser honor its documented NDJSON support while preserving SSE parsing for AI text streams.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(agents): defer recovered agent-tool finish hooks (#1476)

Co-authored-by: Cursor <cursoragent@cursor.com>

* test(voice): cover useVoiceAgent enabled lifecycle (#1478)

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai-chat): close resumed streams on disconnect (#1487)

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(voice): invalidate playback on client interrupt (#1458)

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(voice): invalidate playback when ending calls (#1458)

Co-authored-by: Cursor <cursoragent@cursor.com>

* Run deferred finish hooks after successful startup

Ensure recovered agent-tool finish hooks are only executed after a successful user onStart. Await _runDeferredAgentToolFinishHooks inside the onStart flow so deferred finishes are skipped when startup fails. Add a test and helper (reconcileCompletedChildWithFailedStartupForTest) to verify finish hooks are not run on failed startup and to cover lifecycle ordering and event emission.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Add enabled option to @cloudflare/voice useVoiceAgent

3 participants