feat(ai-chat): allow cancelling in-progress model downloads#701
Open
chriscrosstalk wants to merge 1 commit intodevfrom
Open
feat(ai-chat): allow cancelling in-progress model downloads#701chriscrosstalk wants to merge 1 commit intodevfrom
chriscrosstalk wants to merge 1 commit intodevfrom
Conversation
Adds a cancel button to in-progress Ollama model downloads and unifies the Active Model Downloads card layout with the Active Downloads card used for ZIMs, maps, and pmtiles (byte counts, progress bar, live speed, status indicator). Closes #676.
Collaborator
Author
|
TL;DR - this bring the AI model active downloads display in line with the Content Explorer robust downloads display. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a cancel button to in-progress Ollama model downloads in the AI Settings page, mirroring the content download cancel pattern from PR #554. Also unifies the "Active Model Downloads" visual layout with the "Active Downloads" card used for ZIMs, maps, and pmtiles — same byte counts, progress bar, live speed, and status indicator.
Before this PR, if a user started a 40 GB model by accident or picked the wrong variant, their only options were to wait it out, restart the admin container, or
docker exec nomad_ollama pkill ollama. The Active Model Downloads card also showed only a percentage with no file size, speed, or status.Closes #676.
What changed
Backend (3 files):
OllamaService.downloadModel()— accepts an optionalAbortSignalandjobId. Passessignalto the axios pull stream, detectsERR_CANCELEDand returns a non-retryable failure. Tracks per-digest progress in aMapand aggregates total bytes across all blobs so the UI shows a single monotonically-increasing total instead of a percent that jumps around as each blob is pulled. Throttles Transmit broadcasts to every 500 ms to prevent SSE flooding from Ollama's rapid progress events.DownloadModelJob.handle()— mirrors theRunDownloadJobabort pattern: in-memoryabortControllersmap,signalCancel()static method, 2-second Redis poll loop (keynomad:download:model-cancel:{jobId}), andUnrecoverableErroron user-initiated cancel. Without theUnrecoverableError, BullMQ'sattempts: 40config would retry the cancelled download for 40 minutes. StoresdownloadedBytes/totalBytesin job data alongside percent.DownloadService.cancelJob()— refactored to check the model queue as a fall-through when the job isn't found in the file queue. Extracted_pollForTerminalState()and_removeJobWithLockFallback()helpers to share logic between both branches. On model cancel, broadcasts apercent: -2, status: 'cancelled'event so the frontend hook can clear the entry.No new controller, route, or API client method is needed —
POST /api/downloads/jobs/:jobId/cancelandapi.cancelDownloadJob(jobId)already existed from PR #554 and now handle both queues.Frontend (2 files):
useOllamaModelDownloads— addsjobId,downloadedBytes,totalBytesto theOllamaModelDownloadtype, handlespercent === -2(cancelled) with a 2-second auto-clear, exposes aremoveDownload(model)function for optimistic cleanup.ActiveModelDownloads— rewritten to match theActiveDownloadscard layout: bold title +ollamabadge +X GB / Y GB+ progress bar with percent overlay + "Downloading..." indicator with pulsing green dot and live speed (5-sample moving average of byte deltas, identical pattern to the content download component). Cancel X opens aStyledModalconfirmation that explains partial data behavior. Guards against missingjobId(defensive for stale broadcasts during hot upgrades).Bonus: the generic
ActiveDownloadscomponent (used in Easy Setup) automatically picks up cancel-for-model-downloads support since it already lists model jobs from/api/downloads/jobs.Visual consistency
The AI model download card now matches the Content Explorer download card:
ollama-model(via HorizontalBarChart)ollama(matcheszimbadge style)20.5% / 100%2.3 GB / 24.6 GB● Downloading... 111.1 MB/sPartial blob behavior — documented in the modal
Ollama saves model blobs incrementally during a pull but only writes the local manifest after ALL blobs are downloaded. This means:
ollama listdoes NOT show the partial model (no manifest)ollama rm <model>fails withmodel not found(nothing to remove via Ollama's API)There is currently no Ollama API to clean up orphaned partial blobs, and manually deleting blob files is unsafe because blobs are content-addressed and may be shared with other installed models.
The confirmation modal explains this trade-off directly to the user:
A follow-up "Reclaim disk space" feature (blob GC that walks installed manifests and removes unreferenced blobs) could be added in a future PR if disk reclamation becomes a common request.
Test plan
All verified on NOMAD3 (192.168.200.183, Ollama v0.20.4) via hot-patched JS:
phi3:mini,qwen2.5:14b,mistral:7b,gpt-oss:20ball pull and install cleanly through new signal-aware codemixtral:8x7bshowed2.3 GB / 24.6 GB, 9%,Downloading... 111.1 MB/swith pulsing green dotPOST /api/downloads/jobs/:jobId/cancel)Job failed: Download cancelledlog, zero retry attempts after 15s wait{success: true, message: 'Job not found (may have already completed)'}