Skip to content

fix(kotlin): gate synthesizeStream on ensureServicesReady before the voice lookup - #612

Merged
shubhammalhotra28 merged 1 commit into
RunanywhereAI:mainfrom
ayaangazali:bugfix/kotlin-tts-stream-services-ready
Aug 2, 2026
Merged

fix(kotlin): gate synthesizeStream on ensureServicesReady before the voice lookup#612
shubhammalhotra28 merged 1 commit into
RunanywhereAI:mainfrom
ayaangazali:bugfix/kotlin-tts-stream-services-ready

Conversation

@ayaangazali

@ayaangazali ayaangazali commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

What

RunAnywhere.synthesizeStream(...) checks isInitialized and then goes straight to the model lifecycle to find a loaded speech synthesis voice, without waiting for phase 2 initialisation.

If a caller starts streaming before phase 2 finishes, currentModel(...) reports found = false and the Flow closes without emitting a single output, so a voice that is actually loaded looks to the caller like no voice at all.

One line: call ensureServicesReady() before the lifecycle query.

Why

Every sibling on this path already gates on it, so the streaming variant is the odd one out:

  • synthesize(...) (same file) calls ensureServicesReady() immediately before the identical currentModel(MODEL_CATEGORY_SPEECH_SYNTHESIS) query.
  • transcribeStream(...) in RunAnywhereSTT.kt calls it before its own lifecycle query.
  • Swift's synthesizeStream awaits ensureServicesReady() before reading loadedModelSnapshot(category: .speechSynthesis).

The call is left unwrapped to match transcribeStream in this SDK. I deliberately did not copy Swift's do/catch that finishes the stream silently on a phase 2 failure, since swallowing that error would leave the caller with an empty stream and no way to tell why.

Testing

From sdk/runanywhere-kotlin (JDK 17):

  • ./gradlew :compileDebugKotlin :ktlintMainSourceSetCheck -Prunanywhere.useLocalNatives=false — BUILD SUCCESSFUL.

Scoped to the root module because :modules:runanywhere-core-onnx:downloadJniLibs cannot fetch native libs on this machine. No test added: this is a one-line ordering fix on a path whose behaviour is validated end to end through the example apps.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved text-to-speech streaming reliability by ensuring required services are ready before voice selection and playback begin.

Copilot AI review requested due to automatic review settings August 1, 2026 07:00

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2bcfe3e6-3ded-4db5-91a6-25ea52383e85

📥 Commits

Reviewing files that changed from the base of the PR and between 1965930 and 29215c0.

📒 Files selected for processing (1)
  • sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/TTS/RunAnywhereTTS.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/TTS/RunAnywhereTTS.kt

📝 Walkthrough

Walkthrough

The TTS synthesizeStream path now waits for Phase 2 service initialization before it queries the loaded voice and starts native streaming.

Changes

TTS readiness

Layer / File(s) Summary
Gate TTS streaming on service readiness
sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/TTS/RunAnywhereTTS.kt
synthesizeStream now calls ensureServicesReady() before the lifecycle voice query and native streaming start.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related PRs

  • RunanywhereAI/runanywhere-sdks#572: Both changes modify RunAnywhereTTS.synthesizeStream; this PR adds readiness gating, while #572 changes cancellation and error handling.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Kotlin streaming fix and the readiness check added before the voice lookup.
Description check ✅ Passed The description clearly explains the bug, fix rationale, validation command, scope, and test limitation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

kotlin-android failed on the known flaky timing test, not on this change:

HandleStreamAdapterTest > cancel to native latency is bounded FAILED
    java.lang.AssertionError at HandleStreamAdapterTest.kt:310
98 tests completed, 1 failed

That test asserts a 250 ms wall-clock budget for coroutine cancellation to propagate across five consumers on Dispatchers.Default, which is inherently sensitive on a shared runner.

The clearest evidence that neither diff causes it: the exact same test failed in the same way on #611, which changes only TypeScript and contains no Kotlin at all. It also failed once on #608 (a Dart-only change) and then passed on an identical re-run. kotlin-android is green on main.

Re-triggering with an unchanged diff rather than pushing a fix for it.

…voice lookup

synthesizeStream() queried the model lifecycle for a loaded speech
synthesis voice without first waiting for phase 2 initialisation. If a
caller starts streaming before phase 2 finishes, currentModel reports
found = false and the Flow closes without emitting, so a voice that is
actually present looks like no voice at all.

Every sibling already gates on this: synthesize() calls
ensureServicesReady() before the same lifecycle query, transcribeStream()
calls it before its own, and Swift's synthesizeStream awaits it before
reading loadedModelSnapshot. Add the missing call.

Signed-off-by: ayaangazali <ayaangazali.work@gmail.com>
@ayaangazali
ayaangazali force-pushed the bugfix/kotlin-tts-stream-services-ready branch from 1965930 to 29215c0 Compare August 1, 2026 07:53
@shubhammalhotra28

Copy link
Copy Markdown
Contributor

thanks for the fix @ayaangazali

@shubhammalhotra28
shubhammalhotra28 merged commit 2f292f0 into RunanywhereAI:main Aug 2, 2026
26 checks passed
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.

3 participants