Repository navigation
Description
Where
core/cloudtts/src/main/kotlin/xyz/libravault/core/cloudtts/CloudTtsEngine.kt, introduced in #468 (speak/speakChunk/stop).
What's broken
speak(text) only tracks the coroutine for the first chunk:
speakJob = scope.launch {
val chunks = splitIntoChunks(text)
speakChunk(chunks, 0)
}speakChunk is non-suspending once it reaches playback — it calls cloudTtsProvider.synthesize() (suspend), then playback.play(audioBytes, onCompletion = { scope.launch { speakChunk(chunks, index + 1) } }, ...). playback.play itself doesn't suspend; it kicks off MediaPlayer and returns immediately. So the coroutine assigned to speakJob completes as soon as the first chunk starts playing — well before the utterance is actually done.
Every subsequent chunk (index >= 1) is driven by a new, untracked scope.launch { speakChunk(chunks, index + 1) } fired from the onCompletion/onError callback of the previous chunk's playback. Nothing stores a reference to these jobs. stop() and speak() both only do speakJob?.cancel() (and fallbackForwardingJob?.cancel()), which cannot reach these later, untracked coroutines — they are siblings under the shared singleton scope (CoroutineScope(Dispatchers.Default) from TtsModule), not children of speakJob.
scope is a @Singleton bound for the app's whole process lifetime (TtsModule.provideTtsCoroutineScope), and CloudTtsEngine/MediaPlayerCloudPlayback are themselves @Singleton — so a leaked chunk-continuation coroutine isn't cleaned up by anything short of process death.
Concrete failure scenario
- User is on a long chapter (>
MAX_CHUNK_CHARS= 3900 chars, sospeak()splits it into 2+ chunks) with Cloud TTS active. - Chunk 0 finishes playing.
onCompletionfiresscope.launch { speakChunk(chunks, 1) }(call it Job B) — untracked. - Job B suspends inside
cloudTtsProvider.synthesize()awaiting the vendor's HTTP response for chunk 1. - User presses Stop (or
TtsEngineProvider.switchEngineswaps to a differentTtsEngineType, which also callsoldEngine.stop()). stop()runs:speakJob?.cancel()is a no-op (that job already finished in step 2),playback.stop()stops the already-finished chunk-0 player, state is set toIDLE,_stopEventfires. Job B keeps running.- Chunk 1's HTTP response arrives later; Job B resumes and calls
playback.play(audioBytes, ...), which starts a newMediaPlayerand begins audio output — after the engine reported itself stopped/idle, possibly after the user switched to a different TTS engine or left the screen entirely.
Net effect: audio can resume playing after the user stopped it (or switched engines), and a paid, user-supplied-API-key HTTP call that should have been aborted on stop() fires anyway.
Why it wasn't caught
CloudTtsEngineTest only exercises texts like "hello"/"hello world" — always under MAX_CHUNK_CHARS, so every test stays on speakChunk(chunks, 0), the one path that is tracked by speakJob. There's no test with multi-chunk input, so the untracked-continuation path is never exercised. AGENTS.md calls for boundary-case coverage for new code paths; the chunk-boundary path is exactly the gap.
Suggested fix direction
Track the whole chunk chain as a single cancellable unit — e.g. make speakChunk recurse via a suspending call awaited from inside the original speakJob coroutine (using a CompletableDeferred/suspendCancellableCoroutine to bridge playback.play's callback back into suspend land) instead of firing a fresh top-level scope.launch from onCompletion. That way speakJob?.cancel() in stop()/speak() cancels the entire remaining chain, not just whichever chunk happens to be first.
Filed per principal-review-agent policy: this is a CONFIRMED-severity finding from PR #468's review, tracked here regardless of whether it's fixed inline in that PR or as a follow-up.
Activity
libravault-xyz commentedon Aug 23, 2026
Automated pipeline health check: Flagging an anomaly — doesn't match this routine's 5 known failure patterns, and no comment has been posted on this issue yet.
This issue's author is
github-actions[bot](CONTRIBUTORassociation) — the same profile that tripsdev-agent.yml's author-association trust gate on #388/#408/#409/#433/#437/#441 (see #453, fixed via #454, merged 2026-08-23T08:19:21). But unlike that batch, which each got askippedconclusion run within seconds of filing, this issue has received zerodev-agent.ymlruns at all as of this check (filed 2026-08-23T14:14:34;gh run list --workflow=dev-agent.yml -e issuesshows nothing newer than 12:51:42). Since #454 already merged, the expectation post-fix is askippedrun plus an explanatory comment — neither happened here.Possible causes, unconfirmed: (a) a one-off dropped webhook delivery for this specific
issues: openedevent (GitHub doesn't guarantee delivery — same class of gap #455 already documents forlabeledevents), or (b) something about #454's fix not covering this exact trigger path. Not enough evidence to pick one, and not self-healing either way — recommend a human check whether theissues: openedwebhook actually reached Actions for this issue, and applystatus:triage/status:ready-for-devmanually viaworkflow_dispatchif not.Generated by Claude Code
libravault-xyz commentedon Aug 23, 2026
Automated pipeline health check — update: The anomaly flagged above (zero
dev-agent.ymlruns for this issue) is no longer isolated. Two moregithub-actions[bot]-authored issues filed since have the same signature: #475 (filed 17:20:53Z) and #479 (filed 18:34:41Z) — both still carry no status label and zero comments, same as this one.Confirmed via the full
issues-event run history fordev-agent.yml: the last such run was at 2026-08-23T12:51:42Z ("Verify AwsSigV4Signer..."). Nothing has fired since, across three separateissues:openedevents spanning 14:14Z–18:34Z. Before that cutoff,issues-triggered runs were firing normally and frequently (6 in the preceding ~4.5h, allgithub-actions[bot]-authored, all correctly processed).Ruled out: no commit has touched
.github/workflows/dev-agent.ymlsince #454 merged at 08:19:19Z, well before the 12:51:42Z cutoff — so this isn't a regression from that fix's own code. That leaves a GitHub-side webhook delivery gap forissues:openedon this repo as the likelier cause, but three consecutive misses over 6+ hours (after correctly firing 6/6 times earlier the same day) is past what I'd chalk up to ordinary one-off delivery loss.Still not self-healing: none of the three affected issues carry a status label to toggle, and I'm not authorized to invent a
workflow_dispatchtriage/scope decision for a new pattern. Recommend a human check whether GitHub Actions is actually receivingissues:openedwebhook deliveries for this repo (repo Settings → Webhooks → Recent Deliveries, or GitHub's status page), and manuallyworkflow_dispatchtriage for #469/#475/#479 if not. Worth filing as its own tracked issue if confirmed — doesn't match any of the 5 known patterns this routine watches for.Generated by Claude Code