{"record":{"id":"d03a9bddf3f7c97b","repo":"hashicorp/nomad","slug":"failed-to-retrieve-latest-deployment-v","errorCode":null,"errorMessage":"failed to retrieve latest deployment: %v","messagePattern":"failed to retrieve latest deployment: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"nomad/fsm.go","lineNumber":774,"sourceCode":"\t\t\t}\n\n\t\t\tlaunch := &structs.PeriodicLaunch{\n\t\t\t\tID:        parentID,\n\t\t\t\tNamespace: req.Namespace,\n\t\t\t\tLaunch:    t,\n\t\t\t}\n\t\t\tif err := n.state.UpsertPeriodicLaunch(index, launch); err != nil {\n\t\t\t\tn.logger.Error(\"UpsertPeriodicLaunch failed\", \"error\", err)\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\tif req.Deployment != nil {\n\t\t// Cancel any preivous deployment.\n\t\tlastDeployment, err := n.state.LatestDeploymentByJobID(ws, req.Job.Namespace, req.Job.ID)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to retrieve latest deployment: %v\", err)\n\t\t}\n\t\tif lastDeployment != nil && lastDeployment.Active() {\n\t\t\tactiveDeployment := lastDeployment.Copy()\n\t\t\tactiveDeployment.Status = structs.DeploymentStatusCancelled\n\t\t\tactiveDeployment.StatusDescription = structs.DeploymentStatusDescriptionNewerJob\n\t\t\tif err := n.state.UpsertDeployment(index, activeDeployment); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\n\t\t// Update the deployment with the latest job indexes.\n\t\treq.Deployment.JobCreateIndex = req.Job.CreateIndex\n\t\treq.Deployment.JobModifyIndex = req.Job.ModifyIndex\n\t\treq.Deployment.JobSpecModifyIndex = req.Job.JobModifyIndex\n\t\treq.Deployment.JobVersion = req.Job.Version\n\n\t\tif err := n.state.UpsertDeployment(index, req.Deployment); err != nil {\n\t\t\treturn err","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/fsm.go#L756-L792","documentation":"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.","triggerScenarios":"req.Deployment != nil and n.state.LatestDeploymentByJobID(ws, namespace, jobID) returns an error during Raft apply — state store read failure or index/iterator error.","commonSituations":"Degraded state store during job registration with a deployment object; rare internal state-store errors (BoltDB txn failures) on a busy or unhealthy server.","solutions":["Inspect the embedded state-store error and address the underlying cause (disk, memory, corruption)","Retry the job registration; the FSM apply is deterministic so a transient store error may clear on retry","If persistent, check server health and restore/rebuild the state store"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"_, _, err := client.Jobs().Deployments(jobID, nil)\nif err != nil { return fmt.Errorf(\"deployment lookup pre-check failed: %w\", err) }","typeGuard":null,"tryCatchPattern":"err := registerJobWithDeployment(req)\nif err != nil && strings.Contains(err.Error(), \"failed to retrieve latest deployment\") {\n    return retryWithBackoff(err)\n}","preventionTips":["Avoid registering jobs with deployment payloads while the cluster is degraded","Monitor state-store health and server logs for BoltDB errors","Retry job registrations after transient state-store failures"],"tags":["nomad","fsm","deployment","state-store"],"backgroundTag":"state-store-unavailable","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}