{"record":{"id":"e310b3f9f7e5f50f","repo":"hashicorp/nomad","slug":"failed-to-lookup-task-group-q","errorCode":null,"errorMessage":"failed to lookup task group %q","messagePattern":"failed to lookup task group %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/alloc_runner.go","lineNumber":239,"sourceCode":"\t// partitions is an interface for managing cpuset partitions\n\tpartitions cinterfaces.CPUPartitions\n\n\t// widsigner signs workload identities\n\twidsigner widmgr.IdentitySigner\n\n\t// widmgr manages workload identity signatures\n\twidmgr widmgr.IdentityManager\n\n\t// users manages a pool of dynamic workload users\n\tusers dynamic.Pool\n}\n\n// NewAllocRunner returns a new allocation runner.\nfunc NewAllocRunner(config *config.AllocRunnerConfig) (interfaces.AllocRunner, error) {\n\talloc := config.Alloc\n\ttg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\n\tif tg == nil {\n\t\treturn nil, fmt.Errorf(\"failed to lookup task group %q\", alloc.TaskGroup)\n\t}\n\n\tar := &allocRunner{\n\t\tid:                       alloc.ID,\n\t\talloc:                    alloc,\n\t\tclientConfig:             config.ClientConfig,\n\t\tclientBaseLabels:         config.BaseLabels,\n\t\tconsulServicesHandler:    config.ConsulServices,\n\t\tconsulProxiesClientFunc:  config.ConsulProxiesFunc,\n\t\tvaultClientFunc:          config.VaultFunc,\n\t\ttasks:                    make(map[string]*taskrunner.TaskRunner, len(tg.Tasks)),\n\t\twaitCh:                   make(chan struct{}),\n\t\tdestroyCh:                make(chan struct{}),\n\t\tshutdownCh:               make(chan struct{}),\n\t\tstate:                    &state.State{},\n\t\tstateDB:                  config.StateDB,\n\t\tstateUpdater:             config.StateUpdater,\n\t\ttaskStateUpdatedCh:       make(chan struct{}, 1),","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/alloc_runner.go#L221-L257","documentation":"NewAllocRunner validates that the allocation's TaskGroup exists in its Job before constructing the runner. This error means alloc.TaskGroup named a group that alloc.Job does not contain — the allocation and its job definition are inconsistent.","triggerScenarios":"Creating an AllocRunner with a config whose Alloc.Job was not fully populated (e.g. job plan/restore path omitted task groups) or whose TaskGroup name does not match any group in the embedded job; callers include the test suite and internal restore paths.","commonSituations":"Custom tooling or upgrades injecting/stripping jobs from state (e.g. restoring an alloc whose job spec was truncated); a stale alloc referencing a job version whose group was renamed; hand-crafted alloc structs in automation/scripts.","solutions":["Verify alloc.Job and alloc.TaskGroup are both populated before calling NewAllocRunner: ensure the job was fetched/loaded with all task groups (LookupTaskGroup name match is exact)","Redeploy the job so a fresh, consistent allocation replaces the corrupt one","Inspect the client state store entry for this alloc — if the Job is missing groups, restore from a valid job file (`nomad job revert` or re-run the job)","If writing integrations/tests, always set Alloc.TaskGroup to a group name that exists in Alloc.Job.TaskGroups"],"exampleFix":"// before\nconfig.Alloc = alloc // Job not populated -> failed to lookup task group\n// after\njob, err := client.Jobs().Info(alloc.JobID)\nif err != nil { return err }\nalloc.Job = job\nif alloc.Job.LookupTaskGroup(alloc.TaskGroup) == nil {\n    return fmt.Errorf(\"alloc %s references unknown task group %q\", alloc.ID, alloc.TaskGroup)\n}","handlingStrategy":"validation","validationCode":"// Before constructing an alloc runner, validate consistency\nif alloc.Job == nil || alloc.Job.LookupTaskGroup(alloc.TaskGroup) == nil {\n  return fmt.Errorf(\"alloc %s: job missing task group %q\", alloc.ID, alloc.TaskGroup)\n}","typeGuard":null,"tryCatchPattern":"ar, err := NewAllocRunner(cfg)\nif err != nil {\n  if strings.Contains(err.Error(), \"failed to lookup task group\") {\n    // re-fetch job, restore state, or mark alloc corrupt\n  }\n  return err\n}","preventionTips":["Always populate Alloc.Job from a full job spec before building runners","Never hand-edit or truncate client state store entries","Match TaskGroup names exactly (case-sensitive) when crafting allocs","After job spec renames, redeploy rather than reusing old alloc structs"],"tags":["configuration","task-group","alloc-runner","validation"],"backgroundTag":"task-group-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"}