project-nomad/admin/app/services
Chris Sherwood fe599173ef fix(RAG): report ZIM ingestion progress in overall-file frame
Before this change, the Active Downloads / Processing Queue UI showed the
ingestion progress gauge jumping wildly during multi-batch ZIM ingestion
(e.g. 5% → 88% → 27% → 5% → 56% → 36% over ~60 seconds for cooking SE).

Each continuation batch is a separate BullMQ job, and `EmbedFileJob.handle()`
reported `job.progress` in two different reference frames depending on
where it was in the batch lifecycle:

  - During-batch (via the onProgress callback): 5% → 95% scaled across
    "% through this batch's chunks"
  - End-of-batch (just before dispatching the next): overwritten to
    `(nextOffset / totalArticles) * 100` — % through the whole file
  - Next continuation batch starts with progress = 5% explicitly, then
    climbs through the per-batch range again

`listActiveJobs()` returns the latest active BullMQ job's progress. With
GPU-accelerated ingestion completing a batch every ~4 seconds, the UI
saw the jobId rotate constantly and the gauge whipsaw between the two
reference frames.

`totalArticles` was already wired through the EmbedFileJob params shape
and used end-of-batch — but RagService never actually populated it,
so any frame-scaling that depended on it silently fell back to the
per-batch range. Two fixes together:

1. `ZIMExtractionService.extractZIMContent()` now returns
   `{ chunks: ZIMContentChunk[]; totalArticles: number }` instead of a
   raw chunks array, surfacing `archive.articleCount` to the caller.
   Single caller (rag_service) updated to destructure.

2. `RagService.processZimFile()` includes `totalArticles` in its result
   so `EmbedFileJob.dispatch()` can propagate it to the continuation
   batch (which the existing code already does via
   `totalArticles: totalArticles || result.totalArticles`).

3. `EmbedFileJob`'s onProgress callback scales the service-reported
   per-batch percent into the overall-file frame when `totalArticles`
   is known: `((batchOffset + (percent/100) * ZIM_BATCH_SIZE) /
   totalArticles) * 100`. Capped at 99% to leave room for the explicit
   100% set at file completion. Falls back to the original 5-95% range
   for single-batch files (uploaded PDFs/txts) where totalArticles is
   undefined — the gauge then represents % through the only batch,
   which is what the UI expects for one-shot files.

Validated on NOMAD8 (RX 6800, ROCm-accelerated nomic):

  - devdocs python (small, ~1500 articles): batch progressions seen
    monotonically across continuation jobIds:
    1501@30% → 1510@33% → 1514@43% → 1518@52%.
  - ifixit (huge, ~100k articles): stays near 3% for the first many
    batches at offset 0..3000 — correct, the file is enormous.
  - wikipedia_en_medicine (large, ~70k articles): stays near 0-1% for
    the first batches — also correct.
  - Brief 0-5% blip on continuation handoff (the explicit
    `safeUpdateProgress(job, 5)` at batch start, before the first
    onProgress callback fires) — visible but quickly resolves to the
    overall-frame value. No more 5% ↔ 88% chaos.
2026-05-13 16:10:51 -07:00
..
benchmark_service.ts fix(AI): vendor-aware AMD HSA override + benchmark discrete-GPU detection 2026-05-05 12:11:56 -07:00
chat_service.ts fix(AI): qwen2.5 loading on every chat message (#649) 2026-04-17 11:37:44 -07:00
collection_manifest_service.ts fix: update default branch name 2026-03-01 16:08:46 -08:00
collection_update_service.ts feat(content-updates): show size, surface downloads in Active Downloads 2026-05-03 13:17:07 -07:00
container_registry_service.ts feat: support for updating services 2026-03-11 14:08:09 -07:00
countries_service.ts feat(Maps): regional map downloads via go-pmtiles extract (#780) 2026-05-03 13:47:53 -07:00
docker_service.ts fix(DockerService): improve volume logic and documentation in forceReinstall 2026-05-13 14:26:59 -07:00
docs_service.ts docs: add Community Add-Ons page with field manuals + W3Schools packs (#753) 2026-04-20 14:57:53 -07:00
download_service.ts feat(Maps): regional map downloads via go-pmtiles extract (#780) 2026-05-03 13:47:53 -07:00
kiwix_library_service.ts fix: prevent ZIM corrupt file crash and deduplicate Ollama download logs (#741) 2026-04-17 11:54:04 -07:00
map_service.ts feat(Maps): regional map downloads via go-pmtiles extract (#780) 2026-05-03 13:47:53 -07:00
ollama_service.ts fix(RAG): pace continuation batches when embedding is CPU-only 2026-05-13 13:52:02 -07:00
queue_service.ts fix(queue): singleton QueueService to stop ioredis connection leak 2026-05-13 13:48:21 -07:00
rag_service.ts fix(RAG): report ZIM ingestion progress in overall-file frame 2026-05-13 16:10:51 -07:00
system_service.ts fix(System): validate StartedAt with fallback to tail:500 (PR review) 2026-05-13 15:07:48 -07:00
system_update_service.ts fix(security): SSRF validation for map downloads and error sanitization (CWE-918, CWE-209) (#552) 2026-04-17 14:12:02 -07:00
zim_extraction_service.ts fix(RAG): report ZIM ingestion progress in overall-file frame 2026-05-13 16:10:51 -07:00
zim_service.ts fix(queue): singleton QueueService to stop ioredis connection leak 2026-05-13 13:48:21 -07:00