{"record":{"id":"867306b533244577","repo":"apache/hadoop","slug":"taskid-tid-not-found-or-invalid","errorCode":null,"errorMessage":"taskid {tid} not found or invalid","messagePattern":"taskid (.+?) not found or invalid","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"warning","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsWebServices.java","lineNumber":389,"sourceCode":"    Task task = AMWebServices.getTaskFromTaskIdString(tid, job);\n    return new TaskInfo(task);\n\n  }\n\n  @GET\n  @Path(\"/mapreduce/jobs/{jobid}/tasks/{taskid}/counters\")\n  @Produces({ MediaType.APPLICATION_JSON + \"; \" + JettyUtils.UTF_8,\n      MediaType.APPLICATION_XML + \"; \" + JettyUtils.UTF_8 })\n  public JobTaskCounterInfo getSingleTaskCounters(\n      @Context HttpServletRequest hsr, @PathParam(\"jobid\") String jid,\n      @PathParam(\"taskid\") String tid) {\n\n    init();\n    Job job = AMWebServices.getJobFromJobIdString(jid, ctx);\n    checkAccess(job, hsr);\n    TaskId taskID = MRApps.toTaskID(tid);\n    if (taskID == null) {\n      throw new NotFoundException(\"taskid \" + tid + \" not found or invalid\");\n    }\n    Task task = job.getTask(taskID);\n    if (task == null) {\n      throw new NotFoundException(\"task not found with id \" + tid);\n    }\n    return new JobTaskCounterInfo(task);\n  }\n\n  @GET\n  @Path(\"/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts\")\n  @Produces({ MediaType.APPLICATION_JSON + \"; \" + JettyUtils.UTF_8,\n      MediaType.APPLICATION_XML + \"; \" + JettyUtils.UTF_8 })\n  public TaskAttemptsInfo getJobTaskAttempts(@Context HttpServletRequest hsr,\n      @PathParam(\"jobid\") String jid, @PathParam(\"taskid\") String tid) {\n\n    init();\n    TaskAttemptsInfo attempts = new TaskAttemptsInfo();\n    Job job = AMWebServices.getJobFromJobIdString(jid, ctx);","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsWebServices.java#L371-L407","documentation":"Returned as HTTP 404 by the JobHistoryServer REST task endpoints (e.g. GET /ws/v1/history/mapreduce/jobs/{jobid}/tasks/{taskid}/counters) when MRApps.toTaskID(tid) yields null, i.e. the {taskid} path segment cannot be converted into a TaskId object. This is the guard for unparseable or invalid task identifiers before the job's task map is consulted. Note: because TaskID.forName uses a strict regex (task_<jobTimestamp>_<jobId>_[m|r]_<taskNum>), many malformed ids also surface as 400/500 from the parser; this 404 covers the null-return path and ids that parse structurally but do not belong to the job.","triggerScenarios":"GET /ws/v1/history/mapreduce/jobs/job_1400000000000_0001/tasks/task_9999999999999_0001_m_0/counters — a task id whose embedded job portion or format is wrong (e.g. attempt_... passed instead of task_..., missing trailing task number).","commonSituations":"Passing an attempt id (attempt_...) where a task id (task_...) is required; Cutting the id short or including the '_m_'/'_r_' literal from documentation examples; Mixing ids from a different job or cluster (valid shape, unknown to this job)","solutions":["Use a task id of the exact form task_<timestamp>_<seq>_[m|r]_<n> taken from the job's task listing","List tasks first (GET .../tasks) and copy the id field from the response","Do not substitute attempt ids; attempts live under .../tasks/{taskid}/attempts"],"exampleFix":"# before\ncurl \"http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks/attempt_1400000000000_0001_m_000000_0/counters\"\n\n# after\ncurl \"http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks/task_1400000000000_0001_m_000000/counters\"","handlingStrategy":"validation","validationCode":"private static final Pattern TASK_ID =\n  Pattern.compile(\"task_\\\\d+_\\\\d+_[mr]_\\\\d+\");\nboolean isValidTaskId(String tid) {\n  return tid != null && TASK_ID.matcher(tid).matches()\n      && tid.startsWith(\"task_\" + jobIdSubstring(jid)); // embedded job must match\n}","typeGuard":"boolean isRequestableTaskId(String tid) {\n  return tid != null && TASK_ID.matcher(tid).matches();\n}","tryCatchPattern":"try { counters = jhsClient.getTaskCounters(jid, tid); }\ncatch (NotFoundException e) { /* unknown or invalid task id for this job */ }","preventionTips":["Always source task ids from the .../tasks listing response, never construct them by string surgery","Pass task_ ids to task endpoints and attempt_ ids to attempt endpoints — never interchange","A well-formed id from another job parses fine but 404s at the job lookup — keep ids paired with their job"],"tags":["hadoop","mapreduce","jobhistory","rest","http-404","task-id","identifier-format"],"backgroundTag":"malformed-identifier","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}