Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ jobs:
--tests com.hermesandroid.relay.util.IssueReportAndDiagnosticsTest \
--tests com.hermesandroid.relay.data.AppLanguageTest \
--tests com.hermesandroid.relay.viewmodel.ChatStreamRecoveryTest \
--tests com.hermesandroid.relay.viewmodel.ChatViewModelGatewayInboundTurnTest \
--tests com.hermesandroid.relay.viewmodel.VoiceInboundCompletionTest \
--tests com.hermesandroid.relay.voice.VoiceViewModelBargeInTest \
--tests com.hermesandroid.relay.viewmodel.ChatViewModelRealtimeTurnTest \
--tests com.hermesandroid.relay.network.relay.RealtimeVoiceEventParsingTest \
--tests com.hermesandroid.relay.voice.VoiceCommandInterpreterTest \
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this

## [Unreleased]

### Fixed

- Android Standard Voice speaks live background completions in its active conversation after the original reply finishes. Stop and conversation changes discard pending speech. (#545)

## [Android 1.17.0] - 2026-09-13

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ class GatewayExternalFixtureInstrumentedTest {
private var gatewayScope: CoroutineScope? = null
private var gatewayClient: GatewayChatClient? = null
private var viewModel: ChatViewModel? = null
private var voiceViewModel: VoiceViewModel? = null
private var voicePlayer: com.hermesandroid.relay.audio.VoicePlayer? = null
private var voiceSfx: com.hermesandroid.relay.audio.VoiceSfxPlayer? = null

@After
fun tearDown() {
compose.runOnUiThread {
voiceViewModel?.exitVoiceMode()
voicePlayer?.release()
voiceSfx?.release()
}
viewModel?.updateGatewayClient(null)
gatewayClient?.shutdown()
gatewayScope?.cancel()
Expand Down Expand Up @@ -250,6 +258,80 @@ class GatewayExternalFixtureInstrumentedTest {
assertEquals("gateway", vm.streamingEndpoint)
}

@Test
fun unsolicitedVoiceCompletions_surviveActivityPauseWithoutHistorySpeech() {
val base = InstrumentationRegistry.getArguments().getString(ARG_FIXTURE_BASE_URL)
?.trim()?.trimEnd('/')
assumeTrue("Pass the unsolicited_voice_completions fixture URL", !base.isNullOrBlank())
requireNotNull(base)
val http = OkHttpClient.Builder().callTimeout(10, TimeUnit.SECONDS).build()
assertEquals("unsolicited_voice_completions", readFixtureJson(http, "$base/__fixture__/state")["scenario"]?.jsonString())
val dashboard = DashboardApiClient(base, http)
val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO).also { gatewayScope = it }
val gateway = GatewayChatClient(
initialDashboardClient = dashboard, okHttpClient = http,
callbackDispatcher = { Handler(Looper.getMainLooper()).post(it) }, scope = scope,
).also { gatewayClient = it }
val handler = ChatHandler().also { it.setSessionId(STORED_SESSION_ID) }
val spoken = java.util.concurrent.CopyOnWriteArrayList<String>()
lateinit var vm: ChatViewModel
compose.runOnUiThread {
val app = compose.activity.application
vm = ChatViewModel().also {
it.initialize(null, handler)
it.streamingEndpoint = "gateway"
it.setProfileMessageLoaderWithMode { profile, id, mode ->
dashboard.getSessionMessages(id, profile, mode)
}
it.updateGatewayClient(gateway)
viewModel = it
}
val audio = object : com.hermesandroid.relay.network.shared.VoiceAudioClient {
override val route = com.hermesandroid.relay.data.VoiceAudioRoute.Standard
override suspend fun transcribe(audioFile: java.io.File) = Result.success("")
override suspend fun synthesize(text: String): Result<java.io.File> {
spoken.add(text)
// A short silent WAV exercises the production play/drain path without a provider.
val pcm = ByteArray(3200)
val header = java.nio.ByteBuffer.allocate(44).order(java.nio.ByteOrder.LITTLE_ENDIAN)
.put("RIFF".toByteArray()).putInt(36 + pcm.size).put("WAVEfmt ".toByteArray())
.putInt(16).putShort(1).putShort(1).putInt(16000).putInt(32000)
.putShort(2).putShort(16).put("data".toByteArray()).putInt(pcm.size).array()
val file = java.io.File.createTempFile("fixture-voice", ".wav", app.cacheDir)
file.writeBytes(header + pcm)
return Result.success(file)
}
}
val player = com.hermesandroid.relay.audio.VoicePlayer(app).also { voicePlayer = it }
val sfx = com.hermesandroid.relay.audio.VoiceSfxPlayer(app).also { voiceSfx = it }
voiceViewModel = VoiceViewModel(app).also {
it.initialize(
voiceClient = com.hermesandroid.relay.network.relay.RelayVoiceClient(app, http, { null }, { null }),
voiceAudioClient = audio, chatViewModel = vm,
recorder = com.hermesandroid.relay.audio.VoiceRecorder(app, scope),
player = player, sfxPlayer = sfx,
)
it.enterVoiceMode()
}
}
compose.setContent {
val messages by vm.messages.collectAsStateWithLifecycle()
Text(messages.joinToString("\n") { it.content }, Modifier.testTag("voice-fixture-history"))
}
assertTrue(runBlocking { gateway.prewarmAwait(STORED_SESSION_ID) })
compose.runOnUiThread { vm.sendMessage("Start background work.") }
compose.waitUntil(10_000) { handler.messages.value.any { it.content == "Work started." } }
compose.activityRule.scenario.moveToState(androidx.lifecycle.Lifecycle.State.STARTED)
compose.waitUntil(15_000) { spoken.size == 3 }
compose.activityRule.scenario.moveToState(androidx.lifecycle.Lifecycle.State.RESUMED)
compose.runOnUiThread { voiceViewModel?.onAppResumed() }
compose.waitForIdle()
assertEquals(listOf("Process finished.", "Watch matched.", "Delegated work finished."), spoken.toList())
assertEquals(1, readFixtureJson(http, "$base/__fixture__/evidence")["entries"].let { it as JsonArray }.rpcCount("prompt.submit"))
assertTrue(handler.messages.value.any { it.content == "Delegated work finished." })
assertEquals("gateway", vm.streamingEndpoint)
}

private fun JsonArray.rpcCount(method: String): Int = count { element ->
val entry = element as? JsonObject ?: return@count false
entry["kind"]?.jsonString() == "rpc" && entry["method"]?.jsonString() == method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ class ChatViewModel : ViewModel() {

/** Callback to persist session ID — set by RelayApp */
var onSessionChanged: ((String?) -> Unit)? = null

/** Capture a voice-session receipt at live admission, never during history replay. */
internal var gatewayInboundSpeechReceiver: (() -> ((String) -> Unit)?)? = null
var onFreshDraftSelected: ((String?, SessionTransport) -> Unit)? = null

/**
Expand Down Expand Up @@ -3070,6 +3073,7 @@ class ChatViewModel : ViewModel() {
var boundHandle: ActiveTurnHandle? = null
var inputTokens: Int? = null
var outputTokens: Int? = null
var speechReceiver: ((String) -> Unit)? = null

fun ownsTranscriptSession(): Boolean =
chatHandler === handler && handler.currentSessionId.value == storedSessionId
Expand Down Expand Up @@ -3148,9 +3152,9 @@ class ChatViewModel : ViewModel() {
onTurnComplete = {
if (acceptsEvent()) handler.onTurnComplete(messageId)
},
// Server-initiated turns already take the bounded durable-history
// reconcile below on every completion.
onReconcileRequired = { },
// Recovery can settle a partial live bubble before durable history
// arrives. That history repairs Chat, but is not a speech receipt.
onReconcileRequired = { speechReceiver = null },
onComplete = {
val canWriteTranscript = acceptsEvent()
val expectedText = handler.messages.value
Expand All @@ -3168,7 +3172,9 @@ class ChatViewModel : ViewModel() {
} else {
finalizeTurnSideEffects(handler, messageId)
AppAnalytics.onStreamComplete(inputTokens, outputTokens)
speechReceiver?.invoke(expectedText.orEmpty())
}
speechReceiver = null
scheduleGatewayHistoryReconcile(
storedSessionId = storedSessionId,
expectedAssistantText = expectedText,
Expand Down Expand Up @@ -3271,6 +3277,9 @@ class ChatViewModel : ViewModel() {
baselineAssistantCount = handler.messages.value.count {
it.role == MessageRole.ASSISTANT && !it.clientOnly
}
if (queuedRecovery == null) {
speechReceiver = gatewayInboundSpeechReceiver?.invoke()
}
boundHandle = handle
accepted = true
activeStream = handle
Expand Down
Loading
Loading