{"record":{"id":"14bbf5ea1b33fa62","repo":"hashicorp/nomad","slug":"job-s-not-found-in-namespace-s","errorCode":null,"errorMessage":"job %s not found in namespace %s","messagePattern":"job (.+?) not found in namespace (.+?)","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"nomad/client_alloc_endpoint.go","lineNumber":562,"sourceCode":"\n\tif alloc.ClientTerminalStatus() {\n\t\thandleStreamResultError(fmt.Errorf(\"exec not possible, client status of allocation %s is %s\", alloc.ID, alloc.ClientStatus),\n\t\t\tnew(int64(http.StatusBadRequest)), encoder)\n\t\treturn\n\t}\n\n\t// Handle job ID if requested.\n\tif args.JobID != \"\" {\n\t\t// Verify job exists.\n\t\tjob, err := snap.JobByID(nil, args.Namespace, args.JobID)\n\t\tif err != nil {\n\t\t\thandleStreamResultError(err,\n\t\t\t\tnew(int64(http.StatusInternalServerError)), encoder)\n\t\t\treturn\n\t\t}\n\t\tif job == nil {\n\t\t\thandleStreamResultError(\n\t\t\t\tfmt.Errorf(\"job %s not found in namespace %s\", args.JobID, args.Namespace),\n\t\t\t\tnew(int64(http.StatusNotFound)), encoder)\n\t\t\treturn\n\t\t}\n\n\t\t// Verify requested allocation belongs to the job.\n\t\tif args.JobID != alloc.JobID {\n\t\t\thandleStreamResultError(\n\t\t\t\tfmt.Errorf(\"job %s does not have allocation %s\", args.JobID, alloc.ID),\n\t\t\t\tnew(int64(http.StatusBadRequest)), encoder,\n\t\t\t)\n\t\t}\n\t}\n\n\tnodeID := alloc.NodeID\n\n\t// Make sure Node is valid and new enough to support RPC\n\tnode, err := snap.NodeByID(nil, nodeID)\n\tif err != nil {","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/client_alloc_endpoint.go#L544-L580","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","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."],"exampleFix":"// before\nnomadExec({ jobID: 'batch-job', allocID, namespace: 'prod' })\n// after\nconst ns = 'prod'\nif (!jobExists(ns, 'batch-job')) { ns = 'default' } // or omit jobID\nnomadExec({ jobID: 'batch-job', allocID, namespace: ns })","handlingStrategy":"validation","validationCode":"const job = await nomad.job(jobID, namespace).catch(() => null)\nif (!job) throw new Error(`job ${jobID} missing in namespace ${namespace}; fix ID/namespace before exec`)\nreturn exec({ allocID, jobID, namespace })","typeGuard":null,"tryCatchPattern":"try { await exec({ allocID, jobID, namespace }) }\ncatch (e) {\n  if (String(e).includes('not found in namespace')) {\n    return exec({ allocID, namespace }) // retry without JobID lookup\n  }\n  throw e\n}","preventionTips":["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."],"tags":["nomad","exec","job-not-found","namespace"],"backgroundTag":"resource-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"}