Raw ContainerTask exiting non-zero is deleted and recreated forever instead of failing the action
Describe the bug
A raw ContainerTask whose command exits non-zero never fails its action. The executor deletes the pod and creates a new one under the same pod name with a new uid, indefinitely, while the action stays non-terminal and Attempts stays at 1. retries is no defence — the loop sits below it.
The identical task exiting 0 finalises correctly, so the exit code is the only variable.
I hit this on a CAD task that rejects malformed input in ~1.5s. It ran 16 times in two minutes before I killed it by hand; because the action reports RUNNING the whole time, it presents as a hang rather than a failure.
Expected behavior
A non-zero exit should fail the action (or consume a retry and then fail), not be re-created forever.
To Reproduce
Two tasks, identical except for the last token of the command:
from datetime import timedelta
import flyte
from flyte.extras import ContainerTask
IMAGE = "alpine:3.20"
WRITE_OUTPUT = "mkdir -p /var/outputs; echo ok > /var/outputs/status;"
exit_zero = ContainerTask(
name="exit_zero",
image=flyte.Image.from_base(IMAGE),
outputs={"status": str},
command=["/bin/sh", "-c", f"{WRITE_OUTPUT} exit 0"],
resources=flyte.Resources(cpu=1, memory="1Gi"),
retries=0,
timeout=timedelta(minutes=5),
)
exit_nonzero = ContainerTask(
name="exit_nonzero",
image=flyte.Image.from_base(IMAGE),
outputs={"status": str},
command=["/bin/sh", "-c", f"{WRITE_OUTPUT} exit 5"],
resources=flyte.Resources(cpu=1, memory="1Gi"),
retries=0,
timeout=timedelta(minutes=5),
)
env = flyte.TaskEnvironment.from_task("exitrepro", exit_zero, exit_nonzero)
flyte run repro.py exit_zero # SUCCEEDED in ~10s
flyte run repro.py exit_nonzero # never terminates; abort by hand
Watch the pod rather than the console, which just says Running:
kubectl get pod -n flyte <run>-a0-0 \
-o jsonpath='{.metadata.uid} {.status.phase} {.status.containerStatuses[0].restartCount}'
Observed
| task | result |
|---|---|
exit_zero (writes output) |
ACTION_PHASE_SUCCEEDED, ~10s |
exit_nonzero (writes output) |
never terminal. 11 distinct pod uids in 15 samples over ~45s, one pod name, restartCount 0 throughout, cycling Pending → Running → deleted |
exit_nonzero, no outputs= declared (no copilot sidecar) |
never terminal. 30 samples, 30 distinct uids, restartCount 0 — so the sidecar is not involved |
exit_zero, no outputs= declared |
terminal FAILED in 4s: plugin "pod" failed with system error 4 times: failed to read data from dataDir |
That last row is the useful contrast: the system-error path is correctly bounded by maxSystemFailures and terminates. Only the non-zero exit is unbounded.
This is not kubelet restarting the container: restartPolicy is Never on every Flyte task pod (verified across all 51 in the namespace), restartCount stays 0, and the pod uid changes — something is deleting and re-creating it.
Suspected area (not verified — pointers for whoever picks this up)
The delete-and-recreate is what the in-place restart block in executor/pkg/controller/taskaction_controller.go does on a USER-kind PhaseRetryableFailure: p.Abort(...), PluginState = nil, transition overridden to Queued. But that block is supposed to be bounded by currentAttempts < maxAttempts, and Status.Attempts never advances past 1 in flyte get action.
Two things worth checking:
observedAttempts()is 1-based — it returns 1 whenStatus.Attemptsis unset. The restart block consumes it as a count of completed attempts (restartAttempts = currentAttempts + 1). If the incremented value doesn't survive to the next reconcile,currentAttemptsis 1 forever and the guard never trips.- With
retries=0I'd expectGetMaxAttempts()to be 1, which should make1 < maxAttemptsfalse and fail permanently on the first failure. It doesn't, so either the budget is larger than the task declares or the counter is being reset.
Related but not a fix for this: #7823 (v2.0.41) makes deterministic plugin errors fail immediately, and its own description notes it only catches errors returned directly by a plugin — "errors built from a failure phase go through systemErrorFromPhaseInfo, which flattens the code into the message text". A container exit is a failure phase, so it isn't covered. I diffed taskaction_controller.go between v2.0.35 and v2.0.42: the retryable-failure and attempts logic is byte-identical, so this reproduces on current main.
Workaround
A raw container must always exit 0 and report its outcome through a declared output, which a downstream Python task reads and raises on. pod_template is not an option for this — setting one routes serialization through _get_k8s_pod, which drops data_config and so removes the copilot sidecar entirely.
The cost of the workaround is that a rejected case now shows SUCCEEDED in the console, so failures are invisible in the UI.
Environment
- Flyte backend:
cr.flyte.org/flyteorg/flyte-binary-v2:v2.0.35(also present in v2.0.42 by inspection) - Flyte SDK:
flyte2.5.7 - Kubernetes: GKE v1.35.6-gke.1258000
This is a confirmed bug: when a raw ContainerTask exits non-zero, the Flyte executor repeatedly deletes and recreates the pod without ever failing the action, regardless of the retries setting. This is due to the controller logic in taskaction_controller.go, where USER-kind PhaseRetryableFailure should increment attempts and eventually fail, but the attempt counter (Status.Attempts) is not advancing, so the restart loop is unbounded and the action never becomes terminal. With retries=0, GetMaxAttempts() should be 1, so the first failure should be terminal, but this is not happening—likely due to a bug in how attempts are tracked or persisted (source).
As a workaround, ensure your container always exits 0 and communicates failure via outputs, which a downstream Python task can interpret and raise as an error. However, this means failures will appear as SUCCEEDED in the UI, making them less visible. The root cause is not related to pod restart policy or the copilot sidecar, but to the controller's handling of retryable failures and attempt counting (source). Would you like a step-by-step breakdown of the relevant controller logic or suggestions for a more robust workaround?
Sources:
This is an AI-generated response and your feedback is appreciated! Please leave a 👍 if this is helpful and 👎 if it is not.
Mention @herald to ask follow-up questions. See runllm.com for more!
Hi @evan-sadler , thanks for the detailed report. Let me look into this.
#take
@evan-sadler We just merged a PR that fixed this issue. Could you try again?