From 30bfd4493729afaf175af061fbdc99691ca139f7 Mon Sep 17 00:00:00 2001 From: Stu Alexander Date: Fri, 6 Nov 2026 22:35:25 +0000 Subject: [PATCH] feat(recordings): add Reprocess Summary to the recording menus POST /api/conversations/{id}/reprocess-summary re-queues the title, short summary and detailed summary jobs. It returns 409 when the recording has no transcript or a summary bundle is still running, because the bundle job IDs are fixed. Co-Authored-By: Claude Opus 5.5 --- .../controllers/conversation_controller.py | 36 ++++++++++ .../backend/controllers/queue_controller.py | 26 +++++++ .../routers/modules/conversation_routes.py | 10 +++ backend/tests/test_reprocess_summary.py | 72 +++++++++++++++++++ backend/webui/src/hooks/useConversations.ts | 11 +++ backend/webui/src/pages/RecordingDetail.tsx | 29 +++++++- backend/webui/src/pages/Recordings.tsx | 38 +++++++++- backend/webui/src/services/api.ts | 1 + 8 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 backend/tests/test_reprocess_summary.py diff --git a/backend/src/backend/controllers/conversation_controller.py b/backend/src/backend/controllers/conversation_controller.py index e8f97e47..ab3bc46a 100644 --- a/backend/src/backend/controllers/conversation_controller.py +++ b/backend/src/backend/controllers/conversation_controller.py @@ -23,6 +23,7 @@ memory_queue, post_conv_enqueue_kwargs, start_post_conversation_jobs, + summary_bundle_in_flight, transcription_queue, ) from backend.models.conversation import Conversation @@ -1260,6 +1261,41 @@ async def reprocess_memory( ) +async def reprocess_summary(conversation_id: str, user: User): + """Regenerate the title, short summary and detailed summary from the active transcript.""" + conversation_model, error = await _get_conversation_or_error(conversation_id, user) + if error: + return error + if not conversation_model.transcript and not conversation_model.segments: + return JSONResponse( + status_code=409, + content={"error": "This recording has no transcript to summarise yet"}, + ) + if summary_bundle_in_flight(conversation_id): + return JSONResponse( + status_code=409, + content={ + "error": "A summary is already being generated for this recording" + }, + ) + + jobs = enqueue_summary_job_bundle( + conversation_id, + meta={"conversation_id": conversation_id, "trigger": "summary_reprocess"}, + ) + logger.info( + f"Enqueued summary reprocessing {[job.id for job in jobs.values()]} " + f"for conversation {conversation_id}" + ) + return JSONResponse( + content={ + "message": f"Summary reprocessing started for conversation {conversation_id}", + "job_ids": {stage: job.id for stage, job in jobs.items()}, + "status": "queued", + } + ) + + async def reprocess_speakers( conversation_id: str, transcript_version_id: str, diff --git a/backend/src/backend/controllers/queue_controller.py b/backend/src/backend/controllers/queue_controller.py index 9707b2fe..da7dd780 100644 --- a/backend/src/backend/controllers/queue_controller.py +++ b/backend/src/backend/controllers/queue_controller.py @@ -245,6 +245,32 @@ def enqueue_summary_job_bundle( } +_SUMMARY_BUNDLE_PREFIXES = ("title_", "short_summary_", "detailed_summary_") +_ACTIVE_JOB_STATUSES = { + JobStatus.QUEUED, + JobStatus.STARTED, + JobStatus.DEFERRED, + JobStatus.SCHEDULED, +} + + +def summary_bundle_in_flight(conversation_id: str) -> bool: + """True while any stage of this conversation's summary bundle is still pending. + + Bundle jobs use fixed IDs, so enqueuing another bundle now would overwrite a + job that a worker may already hold. + """ + suffix = conversation_id[:12] + for prefix in _SUMMARY_BUNDLE_PREFIXES: + try: + job = Job.fetch(f"{prefix}{suffix}", connection=redis_conn) + except NoSuchJobError: + continue + if job.get_status() in _ACTIVE_JOB_STATUSES: + return True + return False + + def get_queue(queue_name: str = DEFAULT_QUEUE) -> Queue: """Get an RQ queue by name.""" queues = { diff --git a/backend/src/backend/routers/modules/conversation_routes.py b/backend/src/backend/routers/modules/conversation_routes.py index 2c2394e3..22a72fba 100644 --- a/backend/src/backend/routers/modules/conversation_routes.py +++ b/backend/src/backend/routers/modules/conversation_routes.py @@ -204,6 +204,16 @@ async def reprocess_memory( ) +@router.post("/{conversation_id}/reprocess-summary") +async def reprocess_summary( + conversation_id: str, current_user: User = Depends(current_active_user) +): + """Regenerate the title and both summaries from the active transcript.""" + return await conversation_controller.reprocess_summary( + conversation_id, current_user + ) + + @router.post("/{conversation_id}/reprocess-speakers") async def reprocess_speakers( conversation_id: str, diff --git a/backend/tests/test_reprocess_summary.py b/backend/tests/test_reprocess_summary.py new file mode 100644 index 00000000..8e8f8b88 --- /dev/null +++ b/backend/tests/test_reprocess_summary.py @@ -0,0 +1,72 @@ +"""Manual summary reprocessing: the Recordings menu's "Reprocess Summary" action.""" + +import json +from types import SimpleNamespace + +import pytest + +from backend.controllers import conversation_controller as controller + +CONVERSATION_ID = "6e37beb4-7d00-4d3d-b9b3-4cb232a6e91a" +USER = SimpleNamespace(user_id="u1", is_superuser=False) + + +def _conversation(transcript="hello there, this is a test", segments=None): + return SimpleNamespace(transcript=transcript, segments=segments or []) + + +@pytest.fixture +def enqueued(monkeypatch): + calls = [] + + async def found(conversation_id, user): + return _conversation(), None + + def enqueue(conversation_id, *, meta=None, **_): + calls.append((conversation_id, meta)) + return { + stage: SimpleNamespace(id=f"{stage}_{conversation_id[:12]}") + for stage in ("title", "short_summary", "detailed_summary") + } + + monkeypatch.setattr(controller, "_get_conversation_or_error", found) + monkeypatch.setattr(controller, "enqueue_summary_job_bundle", enqueue) + monkeypatch.setattr(controller, "summary_bundle_in_flight", lambda _id: False) + return calls + + +async def test_queues_the_full_title_and_summary_bundle(enqueued): + response = await controller.reprocess_summary(CONVERSATION_ID, USER) + + assert response.status_code == 200 + body = json.loads(response.body) + assert body["job_ids"]["title"] == f"title_{CONVERSATION_ID[:12]}" + assert enqueued == [ + ( + CONVERSATION_ID, + {"conversation_id": CONVERSATION_ID, "trigger": "summary_reprocess"}, + ) + ] + + +async def test_refuses_while_a_bundle_is_still_running(enqueued, monkeypatch): + """Bundle job IDs are fixed, so a second enqueue would overwrite a held job.""" + + monkeypatch.setattr(controller, "summary_bundle_in_flight", lambda _id: True) + + response = await controller.reprocess_summary(CONVERSATION_ID, USER) + + assert response.status_code == 409 + assert enqueued == [] + + +async def test_refuses_a_recording_with_no_transcript(enqueued, monkeypatch): + async def empty(conversation_id, user): + return _conversation(transcript=""), None + + monkeypatch.setattr(controller, "_get_conversation_or_error", empty) + + response = await controller.reprocess_summary(CONVERSATION_ID, USER) + + assert response.status_code == 409 + assert enqueued == [] diff --git a/backend/webui/src/hooks/useConversations.ts b/backend/webui/src/hooks/useConversations.ts index 3d033c80..c2fea0bb 100644 --- a/backend/webui/src/hooks/useConversations.ts +++ b/backend/webui/src/hooks/useConversations.ts @@ -83,6 +83,17 @@ export function useReprocessMemory() { }) } +export function useReprocessSummary() { + const queryClient = useQueryClient() + return useMutation({ + mutationFn: (conversationId: string) => conversationsApi.reprocessSummary(conversationId), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['conversations'] }) + queryClient.invalidateQueries({ queryKey: ['conversation'] }) + }, + }) +} + export function useReprocessSpeakers() { const queryClient = useQueryClient() return useMutation({ diff --git a/backend/webui/src/pages/RecordingDetail.tsx b/backend/webui/src/pages/RecordingDetail.tsx index d310eed3..5a355e44 100644 --- a/backend/webui/src/pages/RecordingDetail.tsx +++ b/backend/webui/src/pages/RecordingDetail.tsx @@ -4,14 +4,14 @@ import { useParams, useNavigate, useLocation, useSearchParams } from 'react-rout import { useQueryClient } from '@tanstack/react-query' import { ArrowLeft, Calendar, User, Trash2, RefreshCw, MoreVertical, - RotateCcw, Zap, Download, Scissors, + RotateCcw, Zap, FileText, Download, Scissors, Save, X, Pencil, Clock, Database, Layers, Star, BarChart3, Hash, AudioLines, ChevronRight, Check, Copy } from 'lucide-react' import { annotationsApi, speakerApi, systemApi, BACKEND_URL } from '../services/api' import { useConversationDetail, - useDeleteConversation, useReprocessTranscript, useReprocessMemory, useReprocessSpeakers, useToggleStar + useDeleteConversation, useReprocessTranscript, useReprocessMemory, useReprocessSummary, useReprocessSpeakers, useToggleStar } from '../hooks/useConversations' import ConversationVersionHeader from '../components/ConversationVersionHeader' import MemoryAuditCard from '../components/MemoryAuditCard' @@ -128,6 +128,7 @@ export default function RecordingDetail({ dataset = false }: { dataset?: boolean // Reprocessing state const [reprocessingTranscript, setReprocessingTranscript] = useState(false) const [reprocessingMemory, setReprocessingMemory] = useState(false) + const [reprocessingSummary, setReprocessingSummary] = useState(false) const [reprocessingSpeakers, setReprocessingSpeakers] = useState(false) const [actionError, setActionError] = useState(null) const [idCopyStatus, setIdCopyStatus] = useState<'idle' | 'copied' | 'error'>('idle') @@ -185,6 +186,7 @@ export default function RecordingDetail({ dataset = false }: { dataset?: boolean const deleteConversationMutation = useDeleteConversation() const reprocessTranscriptMutation = useReprocessTranscript() const reprocessMemoryMutation = useReprocessMemory() + const reprocessSummaryMutation = useReprocessSummary() const reprocessSpeakersMutation = useReprocessSpeakers() const formatDate = (timestamp: number | string) => { @@ -310,6 +312,20 @@ export default function RecordingDetail({ dataset = false }: { dataset?: boolean } } + const handleReprocessSummary = async () => { + if (!id) return + setReprocessingSummary(true) + setOpenDropdown(false) + try { + await reprocessSummaryMutation.mutateAsync(id) + refetch() + } catch (err: any) { + setActionError(`Failed to reprocess summary: ${err.response?.data?.error || err.message || 'Unknown error'}`) + } finally { + setReprocessingSummary(false) + } + } + const handleReprocessSpeakers = async (diarizationSource: 'provider' | 'pyannote') => { if (!id) return setReprocessingSpeakers(true) @@ -498,6 +514,15 @@ export default function RecordingDetail({ dataset = false }: { dataset?: boolean Reprocess Memory )} +
+