TTS voiceMap silently uses stale data if provider's checkReady() takes over 1s (race against debounce_timeout.relaxed)

Author: MatdredaliaCreated Sep 28, 2026Updated Sep 28, 2026

Hey ST Team, quick thanks for all you do before I get to the important part:

Diagnosed and locally patched with Claude's help — sending it to the much higher ups since this seems like it'd affect anyone using a higher-latency TTS provider, not just me.

onChatChanged() in public/scripts/extensions/tts/index.js races initVoiceMap() against a fixed 1-second timeout (debounce_timeout.relaxed):

const voiceMapInit = initVoiceMap(); await Promise.race([voiceMapInit, delay(debounce_timeout.relaxed)]);

initVoiceMap() calls the active TTS provider's checkReady(), which for network-based providers (ElevenLabs, etc.) is a real API round-trip. If that response takes just over 1 second — not unusual for a cloud API, especially under any load — the Promise.race proceeds anyway, and the function continues with whatever voiceMap state existed before this reinitialization. No error is shown; it fails silently.

Symptom: intermittent wrong or missing character voice shortly after switching chats, with no visible error — hard to pin down because it's timing-dependent, not deterministic. Reported here as roughly 1 in 10 chat switches when using ElevenLabs.

Suggested fix: widen the timeout to something realistic for an actual network call (I tested 10 seconds locally) — the safety net (don't let a chat switch hang forever if a provider is fully unresponsive) still works, it's just no longer tripped by ordinary API latency.