hashicorp/nomad · error · RegisterEnforceIndexErrPrefix

%s %d: job exists with conflicting job modify index: %d

Error message

%s %d: job exists with conflicting job modify index: %d

What it means

Job.EnforceIndex compare-and-set check: when the job exists and the requested index is non-zero but does not equal the job's JobModifyIndex, registration is rejected because the caller's view is stale. Prefixed with RegisterEnforceIndexErrPrefix.

Source

Thrown at nomad/structs/job.go:313

	for _, tg := range j.TaskGroups {
		for _, t := range tg.Tasks {
			if t.Schedule != nil {
				result.Insert(tg.Name)
				break // to next TaskGroup
			}
		}
	}
	return result
}

// EnforceIndex checks the `EnforceIndex` logic: if the job exists (not `nil`)
// it must match the `index` argument and if `index == 0` the job must be `nil`.
func (j *Job) EnforceIndex(index uint64) error {
	if j != nil {
		if index == 0 {
			return fmt.Errorf("%s 0: job already exists", RegisterEnforceIndexErrPrefix)
		} else if index != j.JobModifyIndex {
			return fmt.Errorf("%s %d: job exists with conflicting job modify index: %d",
				RegisterEnforceIndexErrPrefix, index, j.JobModifyIndex)
		}
	} else if index != 0 {
		return fmt.Errorf("%s %d: job does not exist", RegisterEnforceIndexErrPrefix, index)
	}
	return nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Re-read the job (GET /v1/job/...) and use the fresh JobModifyIndex
  2. Retry the register after fetching the current index
  3. Disable EnforceIndex if last-write-wins semantics are acceptable

Example fix

// before
EnforceIndex: true, JobModifyIndex: 42
// after
job := api.Jobs().Info(...) // read current index
EnforceIndex: true, JobModifyIndex: job.JobModifyIndex
Defensive patterns

Strategy: retry

Try / catch

for i := 0; i < 3; i++ {
  state, _, err := client.Jobs().Info(jobID)
  if err != nil { return err }
  job.JobModifyIndex = *state.JobModifyIndex
  _, _, err = client.Jobs().Register(job, &api.RegisterOptions{EnforceIndex: true})
  if err == nil || !strings.Contains(err.Error(), "conflicting job modify index") { return err }
}

Prevention

When it happens

Trigger: Job register with EnforceIndex=true and EnforceIndex set to an index value differing from the stored JobModifyIndex (e.g. after another client modified the job).

Common situations: Two operators editing the same job concurrently; CI re-deploying with a cached index from an earlier read; script using hardcoded index values.

Related errors


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