fix(mobile): clarify legacy voice settings runtime error (#5751)

* fix(mobile): clarify legacy voice settings runtime error

* test(mobile): cover actual legacy speech method miss

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Wolfgang Schoenberger <221313372+wolfiesch@users.noreply.github.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Wolfie
2026-06-18 22:05:08 -07:00
committed by GitHub
co-authored by Orca Wolfgang Schoenberger Jinwoo-H
parent 8c4e99ed2f
commit f19390a8a2
2 changed files with 71 additions and 0 deletions
@@ -18,6 +18,10 @@ function ok(result: unknown): RpcSuccess {
function fail(message: string): RpcFailure {
return { id: 'r', ok: false, error: { code: 'x', message }, _meta: { runtimeId: 'rt' } }
}
function malformedFailure(error: { code?: string; message?: string }): RpcResponse {
return { id: 'r', ok: false, error, _meta: { runtimeId: 'rt' } } as unknown as RpcResponse
}
function clientWith(responses: RpcResponse[]): Pick<RpcClient, 'sendRequest'> & {
calls: Array<{ method: string; params: unknown }>
} {
@@ -84,6 +88,56 @@ describe('rpc wrappers', () => {
const client = clientWith([fail('disconnected')])
await expect(fetchDictationSetup(client)).rejects.toThrow('disconnected')
})
it('maps legacy desktop denials to update guidance', async () => {
const client = clientWith([
{
id: 'r',
ok: false,
error: {
code: 'forbidden',
message: "Method 'speech.models.list' is not available to mobile clients"
},
_meta: { runtimeId: 'rt' }
}
])
await expect(fetchDictationSetup(client)).rejects.toThrow(
'Update the paired desktop Orca app to use mobile voice settings.'
)
})
it('maps legacy desktop method-not-found failures to update guidance', async () => {
const client = clientWith([
malformedFailure({
code: 'method_not_found',
message: 'Unknown method: speech.models.list'
})
])
await expect(fetchDictationSetup(client)).rejects.toThrow(
'Update the paired desktop Orca app to use mobile voice settings.'
)
})
it('keeps unrelated speech model failures specific', async () => {
const client = clientWith([
malformedFailure({
code: 'internal_error',
message: 'speech.models.list failed unexpectedly'
})
])
await expect(fetchDictationSetup(client)).rejects.toThrow(
'speech.models.list failed unexpectedly'
)
})
it('falls back when runtime failures omit a message', async () => {
const client = clientWith([malformedFailure({ code: 'internal_error' })])
await expect(fetchDictationSetup(client)).rejects.toThrow('Failed to load dictation models')
})
})
describe('state helpers', () => {
@@ -9,6 +9,20 @@ export type MobileSpeechModel = RuntimeSpeechSetupState['models'][number]
// configured. Mapping them lets the mic entry point open the setup sheet
// instead of dead-ending on a toast.
const SETUP_REQUIRED_CODES = new Set(['voice_dictation_disabled', 'voice_model_not_selected'])
const LEGACY_DESKTOP_SPEECH_SETUP_MESSAGE =
'Update the paired desktop Orca app to use mobile voice settings.'
// Why: mobile can pair with older desktop runtimes that predate speech.models.list;
// show upgrade guidance instead of leaking the raw denial or not-found error.
function isLegacyDesktopSpeechSetupError(
error: { code?: string; message?: string } | undefined
): boolean {
const message = error?.message ?? ''
return (
message.includes('speech.models.list') &&
(error?.code === 'method_not_found' || message.includes('not available to mobile clients'))
)
}
export function isDictationSetupRequiredError(message: string): boolean {
return SETUP_REQUIRED_CODES.has(message) || message.startsWith('voice_model_not_ready:')
@@ -19,6 +33,9 @@ export async function fetchDictationSetup(
): Promise<MobileSpeechSetup> {
const response = await client.sendRequest('speech.models.list', null)
if (!response.ok) {
if (isLegacyDesktopSpeechSetupError(response.error)) {
throw new Error(LEGACY_DESKTOP_SPEECH_SETUP_MESSAGE)
}
throw new Error(response.error?.message || 'Failed to load dictation models')
}
return (response as RpcSuccess).result as MobileSpeechSetup