hashicorp/nomad · error
job %s not found in namespace %s
Error message
job %s not found in namespace %s
What it means
The exec handler looks up the job referenced in the exec request (when args.JobID is provided) via the state store in the requested namespace. If the state store returns nil for that job, the server responds with HTTP 404 and this message. It guards against exec'ing with a stale or wrong job identifier.
Source
Thrown at nomad/client_alloc_endpoint.go:562
if alloc.ClientTerminalStatus() {
handleStreamResultError(fmt.Errorf("exec not possible, client status of allocation %s is %s", alloc.ID, alloc.ClientStatus),
new(int64(http.StatusBadRequest)), encoder)
return
}
// Handle job ID if requested.
if args.JobID != "" {
// Verify job exists.
job, err := snap.JobByID(nil, args.Namespace, args.JobID)
if err != nil {
handleStreamResultError(err,
new(int64(http.StatusInternalServerError)), encoder)
return
}
if job == nil {
handleStreamResultError(
fmt.Errorf("job %s not found in namespace %s", args.JobID, args.Namespace),
new(int64(http.StatusNotFound)), encoder)
return
}
// Verify requested allocation belongs to the job.
if args.JobID != alloc.JobID {
handleStreamResultError(
fmt.Errorf("job %s does not have allocation %s", args.JobID, alloc.ID),
new(int64(http.StatusBadRequest)), encoder,
)
}
}
nodeID := alloc.NodeID
// Make sure Node is valid and new enough to support RPC
node, err := snap.NodeByID(nil, nodeID)
if err != nil {View on GitHub (pinned to 482b49bf1a)
Solutions
- Confirm the job exists: `nomad job status <job-id>` in the same namespace; fix typos.
- Pass the correct namespace (`-namespace`) or unset JobID so the lookup is skipped and only the alloc is used.
- If the job was deleted, re-register it or exec using the allocation ID alone.
Example fix
// before
nomadExec({ jobID: 'batch-job', allocID, namespace: 'prod' })
// after
const ns = 'prod'
if (!jobExists(ns, 'batch-job')) { ns = 'default' } // or omit jobID
nomadExec({ jobID: 'batch-job', allocID, namespace: ns }) Defensive patterns
Strategy: validation
Validate before calling
const job = await nomad.job(jobID, namespace).catch(() => null)
if (!job) throw new Error(`job ${jobID} missing in namespace ${namespace}; fix ID/namespace before exec`)
return exec({ allocID, jobID, namespace }) Try / catch
try { await exec({ allocID, jobID, namespace }) }
catch (e) {
if (String(e).includes('not found in namespace')) {
return exec({ allocID, namespace }) // retry without JobID lookup
}
throw e
} Prevention
- Always pass -namespace consistently with your ACL token and job ID.
- Verify the job exists (`nomad job status`) before exec'ing with a JobID.
- Avoid hardcoding job IDs in scripts; derive them from the alloc.
- Re-check after job purges/deploys that the target job still exists.
When it happens
Trigger: AllocExec RPC with args.JobID set to a job ID that does not exist in args.Namespace at lookup time (job deleted, typo'd ID, wrong namespace).
Common situations: Job was purged/removed but a cached alloc ID is still used; executing from a script that hardcodes a job name; running in the wrong namespace (ACL token or -namespace mismatch).
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- no exec command is configured
- Invalid namespace name: %#v
- Invalid namespace policy: %#v
- unknown task name %q
- task %q not started yet.
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/14bbf5ea1b33fa62.
Report an issue: GitHub.