apache/hadoop · error · NotFoundException

task attempt id {} not found or invalid

Error message

task attempt id {} not found or invalid

What it means

AMWebServices.getTaskAttemptFromTaskAttemptString converts the {attemptid} path parameter with MRApps.toTaskAttemptID(); the call returned null (null/empty input or missing 'attempt_' prefix) instead of throwing, so the AM REST API fails the request with HTTP 404 'task attempt id ... not found or invalid'. Malformed ids are reported as 404, not 400 (see the comment at AMWebServices.java:204-207).

Source

Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebServices.java:215

    TaskAttemptId attemptId;
    TaskAttempt ta;
    try {
      attemptId = MRApps.toTaskAttemptID(attId);
    } catch (YarnRuntimeException e) {
      // TODO: after MAPREDUCE-2793 YarnRuntimeException is probably not expected here
      // anymore but keeping it for now just in case other stuff starts failing.
      // Also, the webservice should ideally return BadRequest (HTTP:400) when
      // the id is malformed instead of NotFound (HTTP:404). The webserver on
      // top of which AMWebServices is built seems to automatically do that for
      // unhandled exceptions
      throw new NotFoundException(e.getMessage());
    } catch (NumberFormatException ne) {
      throw new NotFoundException(ne.getMessage());
    } catch (IllegalArgumentException e) {
      throw new NotFoundException(e.getMessage());
    }
    if (attemptId == null) {
      throw new NotFoundException("task attempt id " + attId
          + " not found or invalid");
    }
    ta = task.getAttempt(attemptId);
    if (ta == null) {
      throw new NotFoundException("Error getting info on task attempt id "
          + attId);
    }
    return ta;
  }


  /**
   * check for job access.
   *
   * @param job
   *          the job that is being accessed
   */
  void checkAccess(Job job, HttpServletRequest request) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Use an attempt id exactly as returned by GET .../tasks/{taskid}/attempts
  2. Check the format: attempt_<jobTimestamp>_<jobSeq>_[m|r]_<taskSeq>_<attemptSeq>, e.g. attempt_1401318629735_0001_m_000005_0
  3. Trim and URL-encode the parameter; ensure no prefix other than 'attempt_'

Example fix

// before
GET .../jobs/job_1_0001/tasks/task_1_0001_m_000005/attempts/task_1_0001_m_000005
// 404 { "task attempt id task_1_0001_m_000005 not found or invalid" }

// after
GET .../jobs/job_1_0001/tasks/task_1_0001_m_000005/attempts/attempt_1_0001_m_000005_0
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern ATTEMPT_ID_RE =
    Pattern.compile("^attempt_\\d+_\\d+_[mr]_\\d+_\\d+$");

if (attId == null || !ATTEMPT_ID_RE.matcher(attId).matches()) {
  throw new IllegalArgumentException("bad attempt id: " + attId);
}

Type guard

static boolean isWellFormedAttemptId(String attId) {
  return attId != null && attId.startsWith("attempt_")
      && attId.split("_").length == 6;
}

Try / catch

try {
  AttemptInfo a = client.target(amBase)
      .path("jobs/{jid}/tasks/{tid}/attempts/{aid}")
      .resolveTemplates(Map.of("jid", jid, "tid", tid, "aid", attId))
      .request(MediaType.APPLICATION_JSON).get(AttemptInfo.class);
} catch (javax.ws.rs.NotFoundException nfe) {
  // malformed or unknown attempt id
}

Prevention

When it happens

Trigger: Any /ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts/{attemptid}... endpoint (info, counters, PUT state) where attemptid lacks the 'attempt_' prefix - e.g. a bare task id 'task_1401..._m_000005' - or is null/empty.

Common situations: A task id is used where the attempt id is expected; the trailing attempt number is dropped (attempt_..._000005 instead of attempt_..._000005_0); long ids truncated in logs, terminals, or templating systems.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/6dea70b1843eafeb. Report an issue: GitHub.