Model downloads report retrying jobs as permanently failed: the model mapper ignores BullMQ state

Author: chriscrosstalkCreated Sep 3, 2026Updated Sep 25, 2026

Summary

In Easy Setup, selecting AI Assistant plus some models shows the models failing immediately with Download failed: Ollama service is not installed or running.

The download itself is fine and will almost certainly succeed on its own. The status is wrong. Model downloads are the only download type that never reads the real BullMQ job state, so a job that is queued to retry renders as a permanent red failure with a Retry button.

What is actually correct already

  • The wizard fires model downloads without waiting for Ollama to be running. easy-setup/index.tsx says so directly: // All of these ops don't actually wait for completion, they just kick off the process. api.installService() returns once the install is dispatched.
  • That was anticipated. DownloadModelJob.dispatch uses attempts: 40 with a fixed 60s backoff, commented "Many attempts since services may take considerable time to install" — up to 40 minutes of retrying.
  • Each attempt builds a fresh OllamaService inside handle(), so nothing stale is cached between tries.
  • The frontend already handles this correctly. ActiveDownloads.tsx:
    javascript
    if (download.status === 'failed') return 'failed'
    if (download.status === 'waiting' || download.status === 'delayed') return 'queued'

So the retry design works and the UI has a "queued" path. It is simply unreachable for models.

Root cause

admin/app/services/download_service.ts:

javascript
const modelDownloads = modelJobs.map((job) => ({
  ...
  status: (job.failedReason ? 'failed' : 'active') as 'active' | 'failed',
  failedReason: job.failedReason || undefined,
}))

Status is inferred from the presence of failedReason rather than from the job state. Every other download type goes through fetchJobsWithStates(), which queries waiting/active/delayed/failed separately and tags the real state. The canonical type in admin/types/downloads.ts is status?: 'active' | 'waiting' | 'delayed' | 'failed'; the cast here narrows away the two states that matter.

BullMQ sets failedReason on every failed attempt, including ones that will be retried. From bullmq/dist/cjs/classes/job.js:

javascript
this.failedReason = err?.message                                  // set first
const [shouldRetry, retryDelay] = await this.shouldRetryJob(err)
...
  failedReason: this.failedReason,                                // in fieldsToUpdate
  if (shouldRetry) {
    result = await this.scripts.moveToDelayed(..., { fieldsToUpdate, ... })
  }

So a retrying job is moved to delayed with failedReason persisted, and the mapper reads that as failed.

Reproduced on a live box

Stopped nomad_ollama, dispatched a model download, polled Redis and the API together. At t+5s:

BullMQ state delayed (in the delayed zset, absent from failed)
failedReason set
GET /api/downloads/jobs status: "failed"

The underlying error in that run differed from the wizard's, but the state-reporting defect is identical: a delayed job reported as failed.

Secondary: the friendly guard is dead code

download_model_job.ts has a readiness guard clearly meant for this case:

javascript
const existingModels = await ollamaService.getModels()
if (!existingModels) {
  logger.warn(`... Ollama service not ready yet ... Will retry...`)
  throw new Error('Ollama service not ready yet')
}

It can never fire:

  1. getModels() calls _ensureDependencies() first, which throws Ollama service is not installed or running. before the guard is reached, and
  2. its return type is Promise<NomadInstalledModel[]> — never null — and an empty array is truthy.

So the user gets the blunt message instead of the intended one.

Impact

Cosmetic in mechanism, real in effect: the first thing a new user sees at the end of Easy Setup is a red failure on something that is working. The natural response is to click Retry, which routes into retryFailedJob and its dispatch-then-remove bug (#1214, PR #1225).

Suggested fix

  1. Route model jobs through fetchJobsWithStates() like every other type, or otherwise report the real state, so a retrying job reads delayed and renders as "queued".
  2. Make the readiness guard reachable — catch the init failure and throw the intended Ollama service not ready yet, so the retry message is honest.

Source: Crosstalk-Solutions/project-nomad