Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(voice): address review — stale test result, key trim, dry-run contract

M3gA-Mindeaf1ab3b4997
diff --git a/app/src/components/settings/panels/VoicePanelKeyModal.tsx b/app/src/components/settings/panels/VoicePanelKeyModal.tsx
index 1a091b12d2..2ddb41c0cb 100644
--- a/app/src/components/settings/panels/VoicePanelKeyModal.tsx
+++ b/app/src/components/settings/panels/VoicePanelKeyModal.tsx
@@ -1,4 +1,4 @@
-import { useState } from 'react';
+import { useRef, useState } from 'react';
import type { VoiceInstallStatus } from '../../../services/api/voiceInstallApi';
import { testVoiceProvider } from '../../../services/api/voiceSettingsApi';
@@ -106,6 +106,14 @@ const VoicePanelKeyModal = ({
}: VoicePanelKeyModalProps) => {
const [isTestingKey, setIsTestingKey] = useState(false);
const [keyTestResult, setKeyTestResult] = useState<{ ok: boolean; detail: string } | null>(null);
+ // Monotonic id for the in-flight key test. The API-key field stays editable
+ // during a test (it is only disabled while *saving*), so without this a
+ // result for key A can land next to key B and read as a validation of B —
+ // the same "the UI is telling you something untrue about this key" failure
+ // this modal is being fixed for. Bumped on every edit and every new test;
+ // a response whose id is stale is dropped. Same guard as the LLM routing
+ // dialog's `testRequestIdRef`.
+ const testRequestIdRef = useRef(0);
const isPiper = pendingKeySlug === 'piper';
const close = () => {
@@ -174,6 +182,8 @@ const VoicePanelKeyModal = ({
disabled={!pendingKeyValue.trim() || isTestingKey || isSavingPendingKey}
onClick={async () => {
if (!pendingKeySlug || !pendingKeyValue.trim()) return;
+ const requestId = testRequestIdRef.current + 1;
+ testRequestIdRef.current = requestId;
setIsTestingKey(true);
setKeyTestResult(null);
try {
@@ -194,13 +204,18 @@ const VoicePanelKeyModal = ({
true,
pendingKeyValue
);
+ if (testRequestIdRef.current !== requestId) return;
setKeyTestResult(result);
} catch (err) {
+ if (testRequestIdRef.current !== requestId) return;
setKeyTestResult({
ok: false,
detail: err instanceof Error ? err.message : 'Test failed',
});
} finally {
+ // Unconditional: the Test button is disabled while
+ // `isTestingKey`, so there is only ever one test in
+ // flight and this cannot strand the button on "Testing…".
setIsTestingKey(false);
}
}}>
@@ -272,6 +287,9 @@ const VoicePanelKeyModal = ({
onChange={e => {
setPendingKeyValue(e.target.value);
setKeyTestResult(null);
+ // Any edit invalidates a test still in flight for the old
+ // key, so its result cannot arrive and describe this one.
+ testRequestIdRef.current += 1;
}}
disabled={isSavingPendingKey}
placeholder={t('voice.providers.chip.apiKeyPlaceholder')}
diff --git a/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx b/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx
index 76385728e0..a9f44800e1 100644
--- a/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx
+++ b/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx
@@ -859,6 +859,38 @@ describe('VoicePanel', () => {
expect(screen.getByTestId('voice-provider-key-modal')).toBeInTheDocument();
});
+ it('discards an in-flight Test Key result when the key is edited', async () => {
+ // The key field stays editable during a test (it is disabled only while
+ // *saving*). Without the request-id guard, key A's verdict lands next to
+ // key B and reads as a validation of B.
+ let resolveTest: (r: { ok: boolean; detail: string }) => void = () => {};
+ vi.mocked(testVoiceProvider).mockReturnValueOnce(
+ // Annotated: `VoiceTestResult` is not exported, and a bare `new Promise`
+ // would infer `Promise<unknown>` and fail typecheck on the mock.
+ new Promise<{ ok: boolean; detail: string }>(resolve => {
+ resolveTest = resolve;
+ })
+ );
+
+ renderWithProviders(<VoicePanel />, { initialEntries: ['/settings/voice'] });
+
+ await screen.findByTestId('voice-providers-section');
+ fireEvent.click(screen.getByTestId('voice-provider-chip-elevenlabs'));
+ await screen.findByTestId('voice-provider-key-modal');
+
+ const keyInput = screen.getByPlaceholderText(/sk/i);
+ fireEvent.change(keyInput, { target: { value: 'sk-key-AAAA-1234567890' } });
+ fireEvent.click(screen.getByRole('button', { name: /^Test Key$/i }));
+
+ // User edits to a different key before the verdict for the first arrives.
+ fireEvent.change(keyInput, { target: { value: 'sk-key-BBBB-0987654321' } });
+
+ resolveTest({ ok: true, detail: 'STALE VERDICT FOR KEY A' });
+
+ await waitFor(() => expect(screen.getByRole('button', { name: /^Test Key$/i })).toBeEnabled());
+ expect(screen.queryByText(/STALE VERDICT FOR KEY A/i)).not.toBeInTheDocument();
+ });
+
it('the ElevenLabs modal Cancel button closes without saving', async () => {
renderWithProviders(<VoicePanel />, { initialEntries: ['/settings/voice'] });
diff --git a/app/src/services/api/voiceSettingsApi.ts b/app/src/services/api/voiceSettingsApi.ts
index c6ae74af32..ccac05e21f 100644
--- a/app/src/services/api/voiceSettingsApi.ts
+++ b/app/src/services/api/voiceSettingsApi.ts
@@ -245,7 +245,10 @@ export async function testVoiceProvider(
// candidate as "fall back to the stored credential", and sending one
// for a provider with no stored key would report a confusing
// "no API key configured" instead of the real validation result.
- ...(apiKey?.trim() ? { api_key: apiKey } : {}),
+ // Trimmed on the way out so the guard and the payload agree — a key
+ // pasted with a trailing newline should be tested as the key the user
+ // will actually save, not as a different string.
+ ...(apiKey?.trim() ? { api_key: apiKey.trim() } : {}),
},
timeoutMs: VOICE_TEST_TIMEOUT_MS,
});
diff --git a/src/openhuman/voice/schemas/handlers/provider_server.rs b/src/openhuman/voice/schemas/handlers/provider_server.rs
index b9d039e6a9..56253cc45e 100644
--- a/src/openhuman/voice/schemas/handlers/provider_server.rs
+++ b/src/openhuman/voice/schemas/handlers/provider_server.rs
@@ -327,10 +327,20 @@ pub(crate) fn handle_voice_test_provider(params: Map<String, Value>) -> Controll
// always answered with a live transcription (#5896).
//
// Reserved slugs (`cloud`/`openhuman`/`backend`/`piper`/`whisper`/
- // `local`/empty) have no user-held API key to check, so they fall
- // through to the live test, where the factory reports misconfiguration
- // by name.
- if p.validate_only && !crate::openhuman::config::schema::is_voice_slug_reserved(trimmed) {
+ // `local`/empty) are managed or local engines with no user-held API
+ // key, so there is nothing to validate. They must still return here
+ // rather than fall through: `validate_only` promises no inference
+ // call, and falling through would quietly bill the caller for a real
+ // transcription/synthesis. `ok: true` because nothing is wrong — a
+ // managed provider with no key to check is not a failed check.
+ if p.validate_only {
+ if crate::openhuman::config::schema::is_voice_slug_reserved(trimmed) {
+ return Ok(serde_json::json!({
+ "ok": true,
+ "detail": "No API key to validate — this provider is managed by OpenHuman.",
+ "latency_ms": start.elapsed().as_millis(),
+ }));
+ }
return match validate_provider_key(trimmed, &config, p.api_key.as_deref()).await {
Ok(detail) => {
let elapsed = start.elapsed().as_millis();