hashicorp/nomad · error
Check %s is invalid: may only specify task the check belongs
Error message
Check %s is invalid: may only specify task the check belongs to, got %q
What it means
Like services, a check inside a task-level service may only specify the task it belongs to; a check with task_name set to a different task is rejected. This keeps check execution tied to the task that owns the service.
Source
Thrown at nomad/structs/structs.go:7501
if len(task.Services) == 0 {
continue
}
for _, service := range task.Services {
// Ensure no task-level service can only specify the task it belongs to.
if service.TaskName != "" && service.TaskName != task.Name {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("Service %s is invalid: may only specify task the service belongs to, got %q", service.Name, service.TaskName),
)
}
// Ensure no task-level checks can only specify the task they belong to.
for _, check := range service.Checks {
if check.TaskName != "" && check.TaskName != task.Name {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("Check %s is invalid: may only specify task the check belongs to, got %q", check.Name, check.TaskName),
)
}
}
// Track that we have seen this service id
id := unique{service.Name, task.Name, service.PortLabel}
if !idSet.Insert(id) {
// accumulate duplicates for a single error later on
idDuplicateSet.Insert(id)
}
// Track that we have seen this service provider
providerSet.Insert(service.Provider)
}
}
for i, service := range tg.Services {
View on GitHub (pinned to 482b49bf1a)
Solutions
- Remove the task field from the check so it inherits the service's task.
- Set the check's task to the name of the task that contains the service.
- Move the service (with the check) to the group-level services block if cross-task targeting is intended.
Example fix
// before
check "c" { task="api" }
// after
check "c" { } Defensive patterns
Strategy: validation
Validate before calling
for _, c := range svc.Checks {
if c.TaskName != "" && c.TaskName != enclosingTaskName {
return fmt.Errorf("check %q: task %q != enclosing %q", c.Name, c.TaskName, enclosingTaskName)
}
} Prevention
- Omit task on checks inside task services
- Keep checks next to the service they probe
- Grep job files for 'task =' inside check blocks after refactors
When it happens
Trigger: A check inside a task's service block sets task = "other-task" (different from the enclosing task), triggering validation of service.Checks.
Common situations: Copy-pasting a check from a group-level service; refactoring jobs and moving checks between tasks; HCL templating that fills task names incorrectly.
Related errors
- Service %s is invalid: may only specify task the service bel
- Check %q invalid: cannot use address_mode="driver", only che
- service[%d] %+q validation failed: %s
- expose may only be set for Consul service checks
- on_update may only be set to ignore_warnings for Consul serv
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/b36b653a9bc2b944.
Report an issue: GitHub.