{"record":{"id":"f179ada3d0b050b0","repo":"hashicorp/nomad","slug":"can-t-revert-to-current-version","errorCode":null,"errorMessage":"can't revert to current version","messagePattern":"can't revert to current version","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/job_endpoint.go","lineNumber":581,"sourceCode":"\tif args.JobID == \"\" {\n\t\treturn fmt.Errorf(\"missing job ID for revert\")\n\t}\n\n\t// Lookup the job by version\n\tsnap, err := j.srv.fsm.State().Snapshot()\n\tif err != nil {\n\t\treturn err\n\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","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/job_endpoint.go#L563-L599","documentation":"Revert refuses a no-op rollback: after looking up the current job it compares the requested JobVersion to the job's currently registered version, and if they are equal returns \"can't revert to current version\". The endpoint exists to move a job to a *different* version, so reverting to the version already running is rejected explicitly.","triggerScenarios":"Calling Job.Revert with args.JobVersion equal to cur.Version — i.e. the target version of the revert is the same as the job's currently registered version. E.g. `nomad job revert <id> <current-version-number>`.","commonSituations":"Scripting reverts with stale version numbers after someone already re-deployed; race where another operator reverted first; CI retry re-running a revert that already succeeded; hard-coding a version that happens to be the current one.","solutions":["Check the current version first (`nomad job inspect <id>` → Job.Version) and only call Revert if the target differs","If the desired config is already live, do nothing — the revert is complete","Re-fetch job state after prior operations before issuing the revert to avoid stale version numbers","Handle the error idempotently in scripts: treat it as success when the target version is already current"],"exampleFix":"// before\njob, _ := client.Jobs().Info(\"webapp\", nil)\nclient.Jobs().Revert(\"webapp\", *job.Version, 5, nil, nil, nil)\n// after\ncur := *job.Version\nif cur != 5 {\n    client.Jobs().Revert(\"webapp\", cur, 5, nil, nil, nil)\n}","handlingStrategy":"validation","validationCode":"cur, _, err := client.Jobs().Info(jobID, qo)\nif err == nil && *cur.Version == targetVersion {\n    return nil // already at target; revert is a no-op\n}","typeGuard":"func isNoOpRevert(currentVersion, targetVersion uint64) bool { return currentVersion == targetVersion }","tryCatchPattern":"_, _, err := client.Jobs().Revert(jobID, cur, target, nil, nil, wo)\nif err != nil && strings.Contains(err.Error(), \"can't revert to current version\") {\n    return nil // idempotent success: target already live\n}","preventionTips":["Fetch current version immediately before each revert","Make revert scripts idempotent by short-circuiting on equal versions","Re-check state after any concurrent deploy step in CI"],"tags":["nomad","job-revert","no-op","version-mismatch"],"backgroundTag":"invalid-operation","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"}