Skip to content

VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.

fix(android): finish failure receipts before processing worker updates

debpalash829552e6a144
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48447f460..5d24fa76a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,8 @@ metadata and the backend fallback mirror it.
### Fixed
+- Android dubbing errors remain visible when worker updates arrive while their receipt is being saved (#3031)
+
- iOS reserves storage across simultaneous model downloads and keeps saved speech paired with the submitted text (#2969)
- TestFlight builds prepare the on-device inference runtimes before archiving the iPhone app (#2969)
diff --git a/docs/mobile.md b/docs/mobile.md
index fced0cbea..62f515575 100644
--- a/docs/mobile.md
+++ b/docs/mobile.md
@@ -171,3 +171,9 @@ to production automatically.
`APP_STORE_CONNECT_KEY_ID`, `APP_STORE_CONNECT_ISSUER_ID`,
`APP_STORE_CONNECT_API_KEY` and `APPLE_TEAM_ID`.
+
+## Dubbing errors
+
+Android keeps a failed computer dubbing job visible while you stay on the Dub
+screen. Worker updates do not dismiss the error, and reopening the screen does
+not repeat an error already shown.
diff --git a/mobile/android/features/src/main/kotlin/com/voicestudio/mobile/features/dub/DubFailureReceipts.kt b/mobile/android/features/src/main/kotlin/com/voicestudio/mobile/features/dub/DubFailureReceipts.kt
new file mode 100644
index 000000000..c9b9a1517
--- /dev/null
+++ b/mobile/android/features/src/main/kotlin/com/voicestudio/mobile/features/dub/DubFailureReceipts.kt
@@ -0,0 +1,30 @@
+package com.voicestudio.mobile.features.dub
+
+import java.util.UUID
+import kotlinx.coroutines.CancellationException
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.collect
+
+internal suspend fun collectDubFailureReceipts(
+ failures: Flow<Set<UUID>>,
+ consume: suspend (UUID) -> Boolean,
+ display: (UUID) -> Unit,
+ report: (Exception) -> Unit,
+) {
+ val handled = mutableSetOf<UUID>()
+ // Finish persisting and displaying each receipt before observing the next worker snapshot.
+ failures.collect { ids ->
+ for (id in ids) if (id !in handled) {
+ try {
+ if (consume(id)) display(id)
+ } catch (cancelled: CancellationException) {
+ throw cancelled
+ } catch (error: Exception) {
+ // A failed receipt write must never hide the actual job error.
+ display(id)
+ report(error)
+ }
+ handled += id
+ }
+ }
+}
diff --git a/mobile/android/features/src/main/kotlin/com/voicestudio/mobile/features/dub/DubScreen.kt b/mobile/android/features/src/main/kotlin/com/voicestudio/mobile/features/dub/DubScreen.kt
index 413f63cf5..a256e6b75 100644
--- a/mobile/android/features/src/main/kotlin/com/voicestudio/mobile/features/dub/DubScreen.kt
+++ b/mobile/android/features/src/main/kotlin/com/voicestudio/mobile/features/dub/DubScreen.kt
@@ -38,17 +38,13 @@ import java.io.File
val works by workFlow.collectAsState(emptyList())
val scope=rememberCoroutineScope()
var visibleFailures by remember(host) {mutableStateOf(emptySet<java.util.UUID>())}
- LaunchedEffect(works) {
- for(info in works) if(info.state == WorkInfo.State.FAILED && info.id !in visibleFailures) {
- try {
- if(vm.store.consumeDubFailure(info.id)) visibleFailures = visibleFailures + info.id
- } catch(cancelled: CancellationException) {throw cancelled}
- catch(error: Exception) {
- // A failed receipt write must never hide the actual job error.
- visibleFailures = visibleFailures + info.id
- vm.fail(error)
- }
- }
+ LaunchedEffect(host) {
+ collectDubFailureReceipts(
+ snapshotFlow { works.filter { it.state == WorkInfo.State.FAILED }.map { it.id }.toSet() },
+ consume = { vm.store.consumeDubFailure(it) },
+ display = { visibleFailures = visibleFailures + it },
+ report = vm::fail,
+ )
}
var link by rememberSaveable {mutableStateOf("")}
var filePath by rememberSaveable {mutableStateOf<String?>(null)}
diff --git a/mobile/android/features/src/test/kotlin/com/voicestudio/mobile/features/dub/DubFailureReceiptsTest.kt b/mobile/android/features/src/test/kotlin/com/voicestudio/mobile/features/dub/DubFailureReceiptsTest.kt
new file mode 100644
index 000000000..753046f59
--- /dev/null
+++ b/mobile/android/features/src/test/kotlin/com/voicestudio/mobile/features/dub/DubFailureReceiptsTest.kt
@@ -0,0 +1,44 @@
+package com.voicestudio.mobile.features.dub
+
+import java.util.UUID
+import kotlinx.coroutines.CompletableDeferred
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Assert.*
+import org.junit.Test
+
+@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+class DubFailureReceiptsTest {
+ @Test fun workerUpdatesCannotHideAnErrorWhoseReceiptWasJustPersisted() = runTest {
+ val first = UUID.randomUUID()
+ val second = UUID.randomUUID()
+ val failures = MutableStateFlow(emptySet<UUID>())
+ val persisted = mutableSetOf<UUID>()
+ val visible = mutableListOf<UUID>()
+ val receiptReturn = CompletableDeferred<Unit>()
+ backgroundScope.launch {
+ collectDubFailureReceipts(failures, consume = { id ->
+ val unseen = persisted.add(id)
+ // DataStore can commit before its suspended caller resumes.
+ if (id == first && unseen) receiptReturn.await()
+ unseen
+ }, display = { visible += it }, report = { throw it })
+ }
+ failures.value = setOf(first)
+ runCurrent()
+ assertEquals(setOf(first), persisted)
+ assertTrue(visible.isEmpty())
+ failures.value = setOf(first, second)
+ runCurrent()
+ receiptReturn.complete(Unit)
+ runCurrent()
+ assertEquals(listOf(first, second), visible)
+ failures.value = setOf(second)
+ runCurrent()
+ failures.value = setOf(first, second)
+ runCurrent()
+ assertEquals("Redisplayed worker snapshots must not repeat a receipt", listOf(first, second), visible)
+ }
+}