Skip to content

Commit f2d0cd6

Browse files
fix: stop voice transcription polling hang on failed STT
1 parent e0dd1bd commit f2d0cd6

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

app/api/voice.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ async def process_voice_pipeline(
189189
print(f"❌ Pipeline error: {str(e)}\n")
190190
try:
191191
conversation.status = ConversationStatus.FAILED
192+
# Surface a short failure reason for UI polling/status screens.
193+
# Keep this concise and non-sensitive for end users.
194+
conversation.english_translation = f"Transcription failed: {str(e)[:220]}"
192195
db.commit()
193196
except Exception:
194197
db.rollback()

app/templates/upload.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,12 +1496,21 @@ <h5 class="mb-0 text-white" id="chatDevName">Developer Name</h5>
14961496
// Poll for Japanese transcription
14971497
async function pollForTranscription() {
14981498
let attempts = 0;
1499-
const maxAttempts = 30; // 30 seconds max
1499+
const maxAttempts = 120; // allow up to ~2 minutes on slow cold starts
15001500

15011501
while (attempts < maxAttempts) {
15021502
try {
15031503
const response = await fetch(`/api/voice/status/${currentConversationId}`);
1504+
if (!response.ok) {
1505+
throw new Error(`Status endpoint failed with HTTP ${response.status}`);
1506+
}
15041507
const data = await response.json();
1508+
1509+
// Fail fast on terminal error status instead of waiting for timeout.
1510+
if (data.status === 'failed') {
1511+
const reason = data.english_translation || 'Transcription failed during processing.';
1512+
throw new Error(reason);
1513+
}
15051514

15061515
// Check if we have Japanese transcription
15071516
if (data.japanese_transcript) {
@@ -1538,6 +1547,12 @@ <h5 class="mb-0 text-white" id="chatDevName">Developer Name</h5>
15381547

15391548
} catch (error) {
15401549
console.error('Status poll error:', error);
1550+
const errorText = String(error?.message || '');
1551+
if (errorText.toLowerCase().includes('transcription failed')) {
1552+
alert(errorText);
1553+
document.getElementById('recordingStatus').textContent = 'Transcription failed. Try again.';
1554+
return;
1555+
}
15411556
attempts++;
15421557
await sleep(1000);
15431558
}

0 commit comments

Comments
 (0)