Trainer error 409: AlreadyExists

This article explains how to resolve a common conflict error that can occur when rerunning a MLOps Studio Trainer scenario with a job name that already exists.

Overview

When you repeat the Trainer launch scenario and reuse the same job name, Kubernetes rejects the new object because an object with that name is already present in the namespace.

In this case, the solution is simple: change the job name and update all later references to that same name.

When this issue appears

This issue can appear while following the first steps of the Trainer launch scenario from the main Trainer article.

Instead of creating the job successfully, you may see an error like this:

ApiException: (409)
Reason: Conflict
...
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"pytorchjobs.kubeflow.org \"mnist-optimized\" already exists","reason":"AlreadyExists","details":{"name":"mnist-optimized","group":"kubeflow.org","kind":"pytorchjobs"},"code":409}

This means that the name mnist-optimized is already in use in your namespace.

Why it happens

Kubernetes object names must be unique within the same namespace for a given resource type.

If a previous PyTorchJob with the same name still exists, creating another one with the identical name results in a 409 Conflict response.

How to fix the problem

To resolve the issue, change the job name in the manifest or Python job definition.

For example, change this:

"name": "mnist-optimized",

to something else, for example:

"name": "some-new-name",

After that, replace every later reference to mnist-optimized with the new name you chose.

Step-by-step fix

Step 1. Start from the Trainer launch scenario

Follow the same procedure as in the Trainer launch scenario until the point where the job creation fails.

Step 2. Check whether the 409 error appears

If the API returns a 409 Conflict error with the AlreadyExists reason, treat it as a naming collision.

Step 3. Change the job name

Update the job definition and replace the old name with a new one.

For example:

"name": "some-new-name",

Step 4. Update all later references

Do not change the job name only in one place.

Make sure that every later occurrence of the old name is also updated, including:

  • label selectors,

  • monitoring commands,

  • log commands,

  • cleanup commands,

  • any hard-coded references in the notebook cells.

For example, replace:

mnist-optimized

with:

some-new-name

everywhere in the remaining steps.

Expected result

After changing the job name consistently, the job should be created successfully and the scenario should continue normally.

What to do next

After fixing this issue, the next useful steps are:

  • rerun the Trainer scenario with the updated name,

  • verify that the new job appears in the namespace,

  • monitor the pod status and logs,

  • clean up old jobs that are no longer needed to avoid future name collisions.