From 14388e8186f22a4d157ce7d588b7bc4071731ce7 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 12 Apr 2026 18:44:09 +0500 Subject: [PATCH] fix: persist chapter-names results into job payload from sync SSE handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SSE (non-async) chapter-names handler streamed results to the client but never wrote them into the PocketBase job payload — only the initial {pattern} stub was stored. The Review button then fetched the job and found no results, showing 'No results found in this job's payload.' Fix: accumulate allResults across batches (same as the async handler) and write the full {pattern, slug, results:[...]} payload when marking done. --- backend/internal/backend/handlers_textgen.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/internal/backend/handlers_textgen.go b/backend/internal/backend/handlers_textgen.go index 4aa4a2d..f81c063 100644 --- a/backend/internal/backend/handlers_textgen.go +++ b/backend/internal/backend/handlers_textgen.go @@ -233,6 +233,7 @@ func (s *Server) handleAdminTextGenChapterNames(w http.ResponseWriter, r *http.R } } + var allResults []proposedChapterTitle chaptersDone := resumeFrom firstEvent := true for i, batch := range batches { @@ -287,6 +288,7 @@ func (s *Server) handleAdminTextGenChapterNames(w http.ResponseWriter, r *http.R NewTitle: p.Title, }) } + allResults = append(allResults, result...) chaptersDone += len(batch) if jobID != "" && s.deps.AIJobStore != nil { @@ -310,16 +312,20 @@ func (s *Server) handleAdminTextGenChapterNames(w http.ResponseWriter, r *http.R sseWrite(evt) } - // Mark job as done in PB. + // Mark job as done in PB, persisting results so the Review button works. if jobID != "" && s.deps.AIJobStore != nil { status := domain.TaskStatusDone if jobCtx.Err() != nil { status = domain.TaskStatusCancelled } + resultsJSON, _ := json.Marshal(allResults) + finalPayload := fmt.Sprintf(`{"pattern":%q,"slug":%q,"results":%s}`, + req.Pattern, req.Slug, string(resultsJSON)) _ = s.deps.AIJobStore.UpdateAIJob(r.Context(), jobID, map[string]any{ "status": string(status), "items_done": chaptersDone, "finished": time.Now().Format(time.RFC3339), + "payload": finalPayload, }) }