hashicorp/nomad · critical

failed to retrieve latest deployment: %v

Error message

failed to retrieve latest deployment: %v

What it means

Returned by FSM applyUpsertJob when, for a job registration that includes a new deployment, the state store fails to look up the job's latest deployment (LatestDeploymentByJobID). The lookup is needed to cancel any previous active deployment.

Source

Thrown at nomad/fsm.go:774

			}

			launch := &structs.PeriodicLaunch{
				ID:        parentID,
				Namespace: req.Namespace,
				Launch:    t,
			}
			if err := n.state.UpsertPeriodicLaunch(index, launch); err != nil {
				n.logger.Error("UpsertPeriodicLaunch failed", "error", err)
				return err
			}
		}
	}

	if req.Deployment != nil {
		// Cancel any preivous deployment.
		lastDeployment, err := n.state.LatestDeploymentByJobID(ws, req.Job.Namespace, req.Job.ID)
		if err != nil {
			return fmt.Errorf("failed to retrieve latest deployment: %v", err)
		}
		if lastDeployment != nil && lastDeployment.Active() {
			activeDeployment := lastDeployment.Copy()
			activeDeployment.Status = structs.DeploymentStatusCancelled
			activeDeployment.StatusDescription = structs.DeploymentStatusDescriptionNewerJob
			if err := n.state.UpsertDeployment(index, activeDeployment); err != nil {
				return err
			}
		}

		// Update the deployment with the latest job indexes.
		req.Deployment.JobCreateIndex = req.Job.CreateIndex
		req.Deployment.JobModifyIndex = req.Job.ModifyIndex
		req.Deployment.JobSpecModifyIndex = req.Job.JobModifyIndex
		req.Deployment.JobVersion = req.Job.Version

		if err := n.state.UpsertDeployment(index, req.Deployment); err != nil {
			return err

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Inspect the embedded state-store error and address the underlying cause (disk, memory, corruption)
  2. Retry the job registration; the FSM apply is deterministic so a transient store error may clear on retry
  3. If persistent, check server health and restore/rebuild the state store
Defensive patterns

Strategy: retry

Validate before calling

_, _, err := client.Jobs().Deployments(jobID, nil)
if err != nil { return fmt.Errorf("deployment lookup pre-check failed: %w", err) }

Try / catch

err := registerJobWithDeployment(req)
if err != nil && strings.Contains(err.Error(), "failed to retrieve latest deployment") {
    return retryWithBackoff(err)
}

Prevention

When it happens

Trigger: req.Deployment != nil and n.state.LatestDeploymentByJobID(ws, namespace, jobID) returns an error during Raft apply — state store read failure or index/iterator error.

Common situations: Degraded state store during job registration with a deployment object; rare internal state-store errors (BoltDB txn failures) on a busy or unhealthy server.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/d03a9bddf3f7c97b. Report an issue: GitHub.