Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Surface and localize processing errors: title budget reason, summary-failure toast with reason, reset-status modal strings (+de)

Murtaza Nasird71ceeaff187
diff --git a/src/tasks/processing.py b/src/tasks/processing.py
index 04a00f85..ec411d73 100644
--- a/src/tasks/processing.py
+++ b/src/tasks/processing.py
@@ -23,7 +23,7 @@ from openai import OpenAI
from src.database import db
from src.models import Recording, Tag, Event, TranscriptChunk, SystemSetting, GroupMembership, RecordingTag, InternalShare, SharedRecordingState, User, NamingTemplate
from src.services.embeddings import process_recording_chunks
-from src.services.llm import is_using_openai_api, call_llm_completion, format_api_error_message, TEXT_MODEL_NAME, client, http_client_no_proxy
+from src.services.llm import is_using_openai_api, call_llm_completion, format_api_error_message, TEXT_MODEL_NAME, client, http_client_no_proxy, TokenBudgetExceeded
from src.utils import extract_json_object, safe_json_loads
from src.utils.ffprobe import get_codec_info, is_video_file, is_lossless_audio, FFProbeError
from src.utils.ffmpeg_utils import convert_to_mp3, extract_audio_from_video as ffmpeg_extract_audio, compress_audio, FFmpegError, FFmpegNotFoundError
@@ -293,8 +293,14 @@ def generate_title_task(app_context, recording_id, will_auto_summarize=False):
current_app.logger.warning(f"Transcription for recording {recording_id} is too short or empty. Skipping AI title generation.")
ai_title = None
else:
- # Generate AI title via LLM
- ai_title = _generate_ai_title(recording)
+ # Generate AI title via LLM. A budget-exceeded error is actionable
+ # by the user but must not fail the whole recording here — skip
+ # titling and continue (the interactive endpoint surfaces it).
+ try:
+ ai_title = _generate_ai_title(recording)
+ except TokenBudgetExceeded as e:
+ current_app.logger.warning(f"Skipping AI title for recording {recording_id}: {e}")
+ ai_title = None
# Apply naming template if we have one
final_title = None
@@ -426,6 +432,12 @@ Title:"""
return title
+ except TokenBudgetExceeded:
+ # Budget-exceeded is actionable by the user, so let it propagate: the
+ # interactive regenerate-title endpoint surfaces the real reason
+ # instead of a generic "Failed to generate a title". Background callers
+ # catch it and skip titling gracefully (see generate_title_task).
+ raise
except Exception as e:
current_app.logger.error(f"Error generating AI title for recording {recording.id}: {str(e)}")
current_app.logger.error(f"Exception details:", exc_info=True)
diff --git a/static/js/modules/composables/reprocess.js b/static/js/modules/composables/reprocess.js
index d6912d77..3a183335 100644
--- a/static/js/modules/composables/reprocess.js
+++ b/static/js/modules/composables/reprocess.js
@@ -452,7 +452,7 @@ export function useReprocess(state, utils) {
}
if (statusData.status === 'COMPLETED') {
- showToast('Processing completed!', 'fa-check-circle');
+ showToast((utils.t && utils.t('toasts.processingCompleted')) || 'Processing completed!', 'fa-check-circle');
// Refresh token budget after LLM operations complete
if (onChatComplete) onChatComplete();
}
@@ -461,6 +461,7 @@ export function useReprocess(state, utils) {
stopReprocessingPoll(recordingId);
// Fetch full recording data to get error details for display
+ let failureReason = '';
try {
const failedResponse = await fetch(`/api/recordings/${recordingId}`);
if (failedResponse.ok) {
@@ -477,12 +478,20 @@ export function useReprocess(state, utils) {
selectedRecording.value = failedData;
await nextTick();
}
+
+ // The backend stores the failure reason as a marker in
+ // the summary (e.g. "[Summary generation failed: Monthly
+ // token budget exceeded ...]"). Pull the reason out so the
+ // toast explains WHY, not just "failed".
+ const m = (failedData.summary || '').match(/^\[Summary[^:\]]*:\s*([\s\S]+?)\]\s*$/);
+ if (m) failureReason = m[1].trim();
}
} catch (err) {
console.error('Failed to fetch error details:', err);
}
- showToast('Processing failed', 'fa-exclamation-circle');
+ const base = (utils.t && utils.t('toasts.processingFailed')) || 'Processing failed';
+ showToast(failureReason ? `${base}: ${failureReason}` : base, 'fa-exclamation-circle', 6000, 'error');
}
} catch (error) {
console.error('Polling error:', error);
diff --git a/static/locales/de.json b/static/locales/de.json
index f3138e8e..3ab858ed 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -1156,6 +1156,8 @@
"reprocessSummary": "Zusammenfassung neu verarbeiten",
"reprocessTranscription": "Transkription neu verarbeiten",
"resetStatus": "Aufnahme-Status zurücksetzen?",
+ "resetStatusBody": "Dies markiert die Aufnahme als „Fehlgeschlagen“. Das ist nützlich, wenn die Verarbeitung hängen bleibt. Sie können sie anschließend erneut verarbeiten.",
+ "resetStatusConfirm": "Ja, Status zurücksetzen",
"shareRecording": "Aufnahme teilen",
"sharedTranscripts": "Meine geteilten Transkripte",
"systemAudioHelp": "System-Audio Hilfe",
@@ -1687,6 +1689,8 @@
"discardUnsavedRecording": "Sie haben eine nicht gespeicherte Aufnahme. Beim Verlassen geht sie verloren. Fortfahren?"
},
"toasts": {
+ "processingFailed": "Verarbeitung fehlgeschlagen",
+ "processingCompleted": "Verarbeitung abgeschlossen!",
"uploadFailedDownloadedLocally": "Upload fehlgeschlagen. Audio wurde im Downloads-Ordner für einen späteren Versuch gespeichert.",
"uploadFailedNoRecovery": "Upload fehlgeschlagen und Audio konnte nicht lokal gespeichert werden. Bitte erneut aufnehmen.",
"shareTargetReceived": "Geteilte Audiodatei empfangen und zur Transkription eingereiht",
diff --git a/static/locales/en.json b/static/locales/en.json
index 765e2e80..48f1f397 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -1158,6 +1158,8 @@
"reprocessSummary": "Reprocess Summary",
"reprocessTranscription": "Reprocess Transcription",
"resetStatus": "Reset Recording Status?",
+ "resetStatusBody": "This will mark the recording as 'Failed'. This is useful if processing is stuck. You will be able to reprocess it afterwards.",
+ "resetStatusConfirm": "Yes, Reset Status",
"shareRecording": "Share Recording",
"sharedTranscripts": "Shared Transcripts",
"systemAudioHelp": "System Audio Help",
@@ -1693,6 +1695,8 @@
"discardUnsavedRecording": "You have an unsaved recording. Leaving will discard it. Continue?"
},
"toasts": {
+ "processingFailed": "Processing failed",
+ "processingCompleted": "Processing completed!",
"uploadFailedDownloadedLocally": "Upload failed. Audio saved to your Downloads folder for later retry.",
"uploadFailedNoRecovery": "Upload failed and audio could not be saved locally. Please record again.",
"shareTargetReceived": "Shared audio received and queued for transcription",
diff --git a/templates/modals/reset-modal.html b/templates/modals/reset-modal.html
index fc64500e..66eda0ca 100644
--- a/templates/modals/reset-modal.html
+++ b/templates/modals/reset-modal.html
@@ -7,11 +7,11 @@
<button @click="cancelReset" class="modal-close" :title="t('buttons.close')"><i class="fas fa-times"></i></button>
</div>
<div class="modal-body">
- <p class="t-meta">This will mark the recording as 'Failed'. This is useful if processing is stuck. You will be able to reprocess it afterwards.</p>
+ <p class="t-meta">${ t('modal.resetStatusBody') }</p>
</div>
<div class="modal-footer">
<button @click="cancelReset" class="btn btn--ghost">${ t('buttons.cancel') }</button>
- <button @click="executeReset" class="btn btn--primary" style="background: #f97316; border-color: #f97316;">Yes, Reset Status</button>
+ <button @click="executeReset" class="btn btn--primary" style="background: #f97316; border-color: #f97316;">${ t('modal.resetStatusConfirm') }</button>
</div>
</div>
</div>