diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp index a8996b00c9..7f3151b180 100644 --- a/tools/server/server-models.cpp +++ b/tools/server/server-models.cpp @@ -2158,9 +2158,23 @@ void server_models_routes::init_routes() { throw std::invalid_argument("model validation failed, unable to download"); } - // reject if model already exists + // reject if model already exists, but a paused download parks its entry as + // DOWNLOADED until the next reload: re-posting that tag is how a resume is + // asked for, so a download that is not running is replaced instead if (models.has_model(name)) { - throw std::invalid_argument("model '" + name + "' already exists"); + auto existing = models.get_meta(name); + + // the entry can disappear here: get_meta() triggers the reload that + // erases a finished download, which is the resume case as well + const bool resumable = existing.has_value() && !existing->is_running() && + (existing->status == SERVER_MODEL_STATUS_DOWNLOADED || + existing->status == SERVER_MODEL_STATUS_DOWNLOADING); + + if (existing.has_value() && !resumable) { + throw std::invalid_argument("model '" + name + "' already exists"); + } + + SRV_INF("resuming download for model '%s'\n", name.c_str()); } // then, proceed with the actual download diff --git a/tools/ui/src/lib/stores/models/status.svelte.ts b/tools/ui/src/lib/stores/models/status.svelte.ts index bb2c8996a6..b28072bb09 100644 --- a/tools/ui/src/lib/stores/models/status.svelte.ts +++ b/tools/ui/src/lib/stores/models/status.svelte.ts @@ -259,6 +259,7 @@ export class ModelStatusManager { // not fall back to 0%, and let the server discard its stale DOWNLOADED entry // (via the list fetch) before re-posting const snapshot = this.pausedDownloads.get(repoWithTag) ?? null; + const wasPaused = this.pausedDownloads.has(repoWithTag); if (this.deletePausedDownload(repoWithTag) || this.stopRequests.delete(repoWithTag)) { await this.host.fetchRouterModels(); @@ -276,7 +277,15 @@ export class ModelStatusManager { toast.success(`Download started: ${this.host.toDisplayName(repoWithTag)}`); } catch (error) { - toast.error(`Download failed: ${repoWithTag}`); + // the download did not start: a resumed one stays paused rather than + // dropping off the list, which reads as a finished download + if (wasPaused) { + this.setPausedDownload(repoWithTag, snapshot); + } + + const reason = error instanceof Error ? error.message : 'unknown error'; + + toast.error(`Download failed: ${repoWithTag} (${reason})`); throw error; }