From d58e0366fde72fae83a4b2303c3c4cbe9ecbe4d2 Mon Sep 17 00:00:00 2001 From: viettranx Date: Sun, 12 Apr 2026 13:35:06 +0700 Subject: [PATCH] fix(vault): only reset enrichment progress on new batch, not mid-drain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Start() is called each drain loop in processBatch to update total. Only reset done=0 when transitioning from idle→running (new batch), not when already running (same batch, total growing). --- internal/vault/enrich_progress.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/vault/enrich_progress.go b/internal/vault/enrich_progress.go index 724e5180..a8b4ec7b 100644 --- a/internal/vault/enrich_progress.go +++ b/internal/vault/enrich_progress.go @@ -50,15 +50,18 @@ func (p *EnrichProgress) broadcast(e EnrichEvent) { } // Start signals enrichment with updated total and tenant scope. -// Resets done counter so the progress bar starts from 0%. +// Only resets done counter when starting a new batch (was idle). +// Subsequent calls within the same batch just update the total. func (p *EnrichProgress) Start(total int, tenantID uuid.UUID) { p.mu.Lock() defer p.mu.Unlock() - p.done = 0 + if !p.running { + p.done = 0 + } p.total = total p.tenantID = tenantID p.running = true - p.broadcast(EnrichEvent{Phase: "enriching", Done: 0, Total: p.total, Running: true}) + p.broadcast(EnrichEvent{Phase: "enriching", Done: p.done, Total: p.total, Running: true}) } // AddDone increments completed count by n and broadcasts progress.