My app IboChat is an AI voice chat. You make a character, record a voice sample, and the app clones that voice for the character. Then one day a character I created spoke in a plain default voice. No crash. No error on screen. Here's the bug, why it hid so well, and the three small changes that fixed it.

What Went Wrong: A Failed Step Saved as NULL

A separate voice service does the cloning, and it wasn't always running when someone created a character. The commit that fixed this is titled Surface failed voice clones + wire re-clone recovery into chat (was silent voice_id=None). The title says it all. Here's the part of the create endpoint that decides what happens when the clone fails:

 voice_id = None if audio_file and audio_file.filename: normalized_path = _normalize_voice_sample_to_wav(audio_file) try: if normalized_path: ... # post the normalized WAV to the clone service else: # ffmpeg normalization unavailable/failed — fall back to the # raw upload rather than block character creation entirely. resp = requests.post( f"{OMNIVOICE_URL}/profiles", data={'name': name, 'kind': 'clone', 'language': 'Auto'}, files={'ref_audio': (audio_file.filename, audio_file.stream, audio_file.mimetype or 'audio/wav')}, timeout=60 ) if resp.ok: voice_id = resp.json().get('id') else: print(f"[custom-character] voice clone failed: {resp.text}") except Exception as e: print(f"[custom-character] voice clone error: {e}") finally: if normalized_path and os.path.exists(normalized_path): os.remove(normalized_path) # No voice recorded, or cloning failed — character still gets # created, just falls back to edge-tts like any voice_id-less chat. 

This was on purpose, and it's reasonable. A character without a cloned voice still works, since chat falls back to a default text-to-speech voice. So the endpoint saves the character with voice_id = None and returns status 201. The error goes to the server console, where nobody's looking. The browser gets a success. The user gets a character that sounds wrong and no explanation.

Every layer did its job, and that's what makes this failure nasty. Falling back gracefully is fine. Falling back silently isn't, since the user can't spot the problem or do anything about it. The comment in the recovery endpoint says the second half plainly: a character whose clone failed is saved with voice_id = NULL permanently, because creation never retries automatically.

Three Questions for Any Silent Fallback

  • Can the user see that it happened? If not, show it on the page they're already looking at, not in a server log.

  • Can the user fix it? Don't just show a message. Put an action beside it.

  • Can they fix it without redoing their work? If the recording still exists, making someone record again is a poor answer.

Fix 1: Keep the Original Recording

At creation time, the page saves the raw recording in the browser's IndexedDB under the key character_recording::<id>. The other two fixes need this, since a retry has to have the original audio. One catch: the recording stays in that browser. So retry works only on the device that made the character. The app says so out loud instead of failing quietly.

Fix 2: Tell the User, With a Button

Now, when the chat page loads a character with no voice_id, it shows a warning with a retry button:

function showVoiceMissingNotice(characterName) { const chatArea = document.getElementById('chat-area'); if (!chatArea) return; const banner = document.createElement('div'); banner.className = 'alert alert-warning mx-3 mt-2 py-2'; // The character name is typed by the user, so it goes in as text (never as HTML). const nameEl = document.createElement('strong'); nameEl.textContent = characterName; banner.append(nameEl, ' has no cloned voice yet — replies will use a default voice. '); const recloneBtn = document.createElement('button'); recloneBtn.className = 'btn btn-sm btn-warning ms-1'; recloneBtn.textContent = 'Re-clone from saved recording'; recloneBtn.addEventListener('click', async () => { recloneBtn.disabled = true; recloneBtn.textContent = 'Cloning...'; try { const blob = (typeof IboAudioStore !== 'undefined') ? await IboAudioStore.get(`character_recording::${characterId}`) : null; if (!blob) { recloneBtn.textContent = 'No saved recording in this browser'; return; } const fd = new FormData(); fd.append('voice_sample', blob, 'voice_sample.webm'); const resp = await fetch(`/api/characters/${characterId}/reclone`, { method: 'POST', body: fd }); const data = await resp.json().catch(() => ({})); if (!resp.ok || !data.voice_id) throw new Error(data.error || `Re-clone failed (${resp.status})`); activeCelebrityVoiceId = data.voice_id; const btn = document.getElementById('celebrity-voice-btn'); if (btn) { btn.innerHTML = '<i class="fa-solid fa-star" style="color:#ffc107"></i>'; btn.title = `Using ${person}'s cloned voice`; } banner.remove(); } catch (err) { console.error('[custom-character] re-clone failed:', err); recloneBtn.disabled = false; recloneBtn.textContent = 'Re-clone failed — is OmniVoice running? Retry'; } }); banner.appendChild(recloneBtn); chatArea.insertAdjacentElement('beforebegin', banner); } 

Two details are worth copying. The button disables itself and says Cloning… while it works. And every outcome gets its own message: no saved recording, or the service still not running. A retry button that only says Failed teaches users to stop pressing it.

Fix 3: A Retry Endpoint That Updates the Row

@app.route('/api/characters/<char_id>/reclone', methods=['POST']) def reclone_character_voice(char_id): # Recovery path for characters whose voice clone failed at creation time # (most commonly: OmniVoice Studio wasn't running yet) and so were saved # with voice_id = NULL permanently — creation never retries automatically. # The browser still has the original recording in IndexedDB # (character_recording::<id>, see audio-store.js), so instead of asking # the user to re-record, chat.js's voice-debug panel can resend that same # blob here to try the OmniVoice clone again and patch voice_id in place. with sqlite3.connect(DATABASE) as conn: conn.row_factory = sqlite3.Row row = conn.execute( "SELECT id, name FROM custom_characters WHERE id = ?", (char_id,) ).fetchone() if not row: return jsonify({'error': 'character not found'}), 404 audio_file = request.files.get('voice_sample') if not audio_file or not audio_file.filename: return jsonify({'error': 'voice_sample is required'}), 400 normalized_path = _normalize_voice_sample_to_wav(audio_file) try: if normalized_path: with open(normalized_path, 'rb') as wav_f: resp = requests.post( f"{OMNIVOICE_URL}/profiles", data={'name': row['name'], 'kind': 'clone', 'language': 'Auto'}, files={'ref_audio': ('voice_sample.wav', wav_f, 'audio/wav')}, timeout=60 ) else: resp = requests.post( f"{OMNIVOICE_URL}/profiles", data={'name': row['name'], 'kind': 'clone', 'language': 'Auto'}, files={'ref_audio': (audio_file.filename, audio_file.stream, audio_file.mimetype or 'audio/wav')}, timeout=60 ) except Exception as e: return jsonify({'error': f'could not reach OmniVoice: {e}'}), 502 finally: if normalized_path and os.path.exists(normalized_path): os.remove(normalized_path) if not resp.ok: return jsonify({'error': f'OmniVoice clone failed: {resp.text}'}), 502 voice_id = resp.json().get('id') if not voice_id: return jsonify({'error': 'OmniVoice did not return a profile id'}), 502 with sqlite3.connect(DATABASE) as conn: conn.execute("UPDATE custom_characters SET voice_id = ? WHERE id = ?", (voice_id, char_id)) conn.commit() return jsonify({'id': char_id, 'voice_id': voice_id}), 200 

The endpoint answers each failure with its own status code. You get 404 for an unknown character and 400 for a missing file. You get 502 for anything wrong on the clone service's side: unreachable, an error reply, or a reply without an id. A 502 means "the thing I depend on failed". That's exactly what the page shows as "is the voice service running? Retry". On success, the endpoint patches the existing row with UPDATE. The character keeps its id, its chats and its links.

How I Tested It Without the Real Voice Service

The real clone service needs a graphics card and a model. So the test uses a stand-in that fails on purpose. It behaves like the real service did that day: the first calls fail, and later ones succeed.

calls = {"profiles": 0} @app.route("/profiles", methods=["GET"]) def list_profiles(): return jsonify([]) @app.route("/profiles", methods=["POST"]) def create_profile(): calls["profiles"] += 1 if calls["profiles"] <= 2: return "model is still loading", 503 return jsonify({"id": "voice-abc123"}) 

Then Playwright drives the real IboChat pages. The test creates a character while the fake is failing, opens the chat page and walks through the recovery. Here's the output of that run, from the real code:

1. create -> 201 {'id': '...', 'name': 'Nova', 'voice_id': None} 2. banner: Nova has no cloned voice yet - replies will use a default voice. Re-clone from saved recording click without a saved recording -> No saved recording in this browser 3. banner gone after the retry: True stored voice_id now: voice-abc123 4. banner after reload: 0 (0 = fixed) 

Read it like this. Step 1 shows the bug: a 201 with voice_id set to None. Steps 2 to 4 show the fix. The banner shows up, the no-recording case gets handled, the retry stores the id, and after a reload the warning is gone.

What to Remember

If a step can fail and you choose to keep going without it, the user needs to see that, fix it, and keep their work. For IboChat that meant three changes. Keep the original input. Show a warning with a retry button. Add a retry endpoint that updates the saved row. And test the failure deliberately, with a stand-in service that fails first. The happy path will never show you this bug.

The IboChat code lives in the Sample-code- repository at Python-projects/IboChat. The voice features are covered in How I Built IboChat. Want more posts with a clear cause and tested fixes? Try Flask Speech to Text With faster-whisper, KeyError in Python and TypeError: int Object Is Not Callable.