{"record":{"id":"a7e3ed79b5ee908c","repo":"hashicorp/nomad","slug":"job-q-in-namespace-q-at-version-d-not-found","errorCode":null,"errorMessage":"job %q in namespace %q at version %d not found","messagePattern":"job %q in namespace %q at version (.+?) not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/job_endpoint.go","lineNumber":589,"sourceCode":"\t}\n\tws := memdb.NewWatchSet()\n\tcur, err := snap.JobByID(ws, args.RequestNamespace(), args.JobID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif cur == nil {\n\t\treturn fmt.Errorf(\"job %q not found\", args.JobID)\n\t}\n\tif args.JobVersion == cur.Version {\n\t\treturn fmt.Errorf(\"can't revert to current version\")\n\t}\n\n\tjobV, err := snap.JobByIDAndVersion(ws, args.RequestNamespace(), args.JobID, args.JobVersion)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif jobV == nil {\n\t\treturn fmt.Errorf(\"job %q in namespace %q at version %d not found\", args.JobID, args.RequestNamespace(), args.JobVersion)\n\t}\n\n\t// Build the register request\n\trevJob := jobV.Copy()\n\n\t// Clear out the VersionTag to prevent tag duplication\n\trevJob.VersionTag = nil\n\n\t// Set the stable flag to false as this is functionally a new registration\n\t// and should handle deployment updates\n\trevJob.Stable = false\n\n\treg := &structs.JobRegisterRequest{\n\t\tJob:          revJob,\n\t\tWriteRequest: args.WriteRequest,\n\t}\n\n\t// If the request is enforcing the existing version do a check.","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/job_endpoint.go#L571-L607","documentation":"After confirming the job exists at some version, Revert looks up the specific historical version via snap.JobByIDAndVersion. If that (namespace, job ID, version) triple is absent from the version history it returns \"job %q in namespace %q at version %d not found\". Nomad keeps a bounded version history, so old versions can be gone even though the job itself exists.","triggerScenarios":"Calling Job.Revert with a JobVersion that was never registered, or one that has aged out of the retained version history (Nomad prunes job versions per job), while the job itself still exists.","commonSituations":"Reverting to a version number beyond the retained history after many deploys; guessing version numbers in scripts; referencing a version from before a job was purged and re-registered (versions restart); typos in the version number.","solutions":["List available versions (`nomad job history <id>` or job versions API) and pick an existing version","Use the job's Versions list from the inspect/status API to validate the target version before calling Revert","If the needed version was pruned, re-register the desired job specification from source control instead of reverting","Correct the version number in the script/CLI invocation"],"exampleFix":"// before (blind revert)\nclient.Jobs().Revert(\"webapp\", cur, 99, nil, nil, nil)\n// after (validate version exists)\nversions, _, _ := client.Jobs().Versions(\"webapp\", false, nil)\nfor _, v := range versions {\n    if *v.Version == 99 {\n        client.Jobs().Revert(\"webapp\", cur, 99, nil, nil, nil)\n        break\n    }\n}","handlingStrategy":"validation","validationCode":"versions, _, err := client.Jobs().Versions(jobID, false, nil)\nif err != nil { return err }\nfound := false\nfor _, v := range versions { if *v.Version == targetVersion { found = true } }\nif !found { return fmt.Errorf(\"version %d not in history for %s\", targetVersion, jobID) }","typeGuard":"func versionInHistory(versions []*api.Job, target uint64) bool {\n    for _, v := range versions { if v.Version != nil && *v.Version == target { return true } }\n    return false\n}","tryCatchPattern":"_, _, err := client.Jobs().Revert(jobID, cur, target, nil, nil, wo)\nif err != nil && strings.Contains(err.Error(), \"at version\") {\n    // version missing from history: fall back to re-registering the spec\n}","preventionTips":["Enumerate job versions before reverting to any specific number","Keep the desired job specification in source control as a fallback when history is pruned","Remember Nomad bounds retained versions per job — don't target arbitrarily old versions","After a purge/re-register, version numbers restart at 0"],"tags":["nomad","job-revert","version-not-found","history"],"backgroundTag":"resource-version-not-found","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"}