diff --git a/internal/http/vault_handlers.go b/internal/http/vault_handlers.go index 4c87bde9..9bb3f868 100644 --- a/internal/http/vault_handlers.go +++ b/internal/http/vault_handlers.go @@ -204,14 +204,15 @@ func (h *VaultHandler) handleRescan(w http.ResponseWriter, r *http.Request) { // and AddDone calls are not dropped by the !running guard. total := result.New + result.Updated - // If no new/updated files, check for unenriched docs and re-enqueue them. - // This handles the case where previous enrichment failed (e.g. provider timeout). - if total == 0 && h.enrichWorker != nil { + // Always re-enqueue docs that lack summaries (failed previous enrichment). + // Worker-level dedup (DocID+ContentHash) prevents double-processing docs + // that are also in PendingEvents from the current scan. + if h.enrichWorker != nil { enqueued, err := h.enrichWorker.EnqueueUnenriched(ctx, tenantID, wsPath, h.eventBus, 0) if err != nil { slog.Warn("vault.rescan: enqueue_unenriched failed", "tenant", tenantID, "error", err) } else if enqueued > 0 { - total = enqueued + total += enqueued result.Reenqueued = enqueued slog.Info("vault.rescan: re-enqueued unenriched docs", "tenant", tenantID, "count", enqueued) } diff --git a/internal/vault/enrich_progress.go b/internal/vault/enrich_progress.go index 5abe57bb..998905fe 100644 --- a/internal/vault/enrich_progress.go +++ b/internal/vault/enrich_progress.go @@ -78,9 +78,13 @@ func (p *EnrichProgress) Start(total int, tenantID uuid.UUID) { // AddError increments error count and broadcasts an error event. // Used when enrichment fails for a document (e.g., LLM retries exhausted). +// Suppressed after Finish() to prevent stale errors from cancelled goroutines. func (p *EnrichProgress) AddError(errMsg string) { p.mu.Lock() defer p.mu.Unlock() + if !p.running { + return + } p.errorCount++ p.lastError = errMsg p.broadcast(EnrichEvent{ diff --git a/internal/vault/enrich_worker.go b/internal/vault/enrich_worker.go index 9494352b..18d9f49e 100644 --- a/internal/vault/enrich_worker.go +++ b/internal/vault/enrich_worker.go @@ -460,7 +460,8 @@ func (w *EnrichWorker) batchSummarize(ctx context.Context, provider providers.Pr }) if err != nil { slog.Warn("vault.enrich: batch_summarize", "count", len(paths), "err", err) - if w.progress != nil { + // Don't report context cancellation as enrichment error — expected during stop. + if w.progress != nil && ctx.Err() == nil { w.progress.AddError(fmt.Sprintf("batch summarize failed: %v", err)) } return nil