Skip to content

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

Python

A permanently failed summary job keeps the transcript and shows the error as the summary (#412 audit P16)

Murtaza Nasir59b4feb4d271
diff --git a/src/services/job_queue.py b/src/services/job_queue.py
index 6b40952e..679a9414 100644
--- a/src/services/job_queue.py
+++ b/src/services/job_queue.py
@@ -419,9 +419,14 @@ class FairJobQueue:
if recording:
# Keep the recording with FAILED status so user can see the error and fix settings
recording.status = 'FAILED'
- # Format the error for nice display
+ # Format the error for nice display. A failed summary
+ # job keeps the transcript and shows the error as the
+ # summary; it used to overwrite a good transcript (#412).
from src.utils.error_formatting import format_error_for_storage
- recording.transcription = format_error_for_storage(error_str)
+ if job_type in ('summarize', 'reprocess_summary'):
+ recording.summary = format_error_for_storage(error_str)
+ else:
+ recording.transcription = format_error_for_storage(error_str)
if is_permanent_error:
logger.error(f"Job {job_id} failed permanently (non-retryable error)")
diff --git a/tests/test_cov_job_queue.py b/tests/test_cov_job_queue.py
index 3bbb8602..f36c830e 100644
--- a/tests/test_cov_job_queue.py
+++ b/tests/test_cov_job_queue.py
@@ -830,3 +830,27 @@ def test_cleanup_old_jobs_keeps_recent(track):
job_queue.cleanup_old_jobs(max_age_hours=24)
assert db.session.get(ProcessingJob, recent.id) is not None
+
+
+def test_a_failed_summary_job_keeps_the_transcript(track):
+ """A permanently failed summary job shows the error as the summary and
+ keeps the transcript; it used to overwrite the transcript (#412 audit P16)."""
+ uid = _make_user(); track.user_ids.append(uid)
+ rid = _make_recording(uid, status="QUEUED"); track.recording_ids.append(rid)
+ rec = db.session.get(Recording, rid)
+ rec.transcription = "Speaker 1: the real transcript we must keep."
+ db.session.commit()
+ jid = job_queue.enqueue(uid, rid, "reprocess_summary", params={"user_id": uid})
+ track.job_ids.append(jid)
+ job = _claim(rid, SUMMARY_JOBS, "summary")
+
+ with patch("src.tasks.processing.generate_summary_only_task", side_effect=RuntimeError("model gone")), \
+ patch.object(job_queue, "_is_permanent_error", return_value=True), \
+ patch.object(job_queue, "_emit_failure_webhook"), patch.object(job_queue, "_emit_failure_email"):
+ job_queue._process_job(job)
+
+ db.session.expire_all()
+ rec = db.session.get(Recording, rid)
+ assert rec.status == "FAILED"
+ assert rec.transcription == "Speaker 1: the real transcript we must keep."
+ assert rec.summary and "model gone" in rec.summary