AI engineering tip of the week: Recover from Pipeline Failures with Retries and Self-Healing Tasks
ML pipelines fail. APIs time out. Spot instances get preempted. GPUs run out of memory. The question isn't whether your pipeline will eventually fail, it's how gracefully it recovers.
Flyte 2 handles transient failures with automatic retries, and can turn others into Python exceptions you can catch. Once a failure is a Python exception, the code that hit it can also fix it. Together they cover everything from a flaky API call to self-healing agents that catch their own OOM and ask for more resources.
Automatic retries
Add `retries=N` to your task and Flyte automatically re-runs it up to N times if it fails:
No retry loops, no exponential backoff boilerplate. Flyte handles it at the infrastructure level. Each retry gets a fresh container.
Catch errors from other tasks with try/except
In Flyte 2, task errors are just Python exceptions. Catch them with standard `try`/`except`:
The `e.code` field contains the exception class name (like `"ValueError"`), so you can handle different error types differently.
Handle out-of-memory errors
OOM errors are common in ML. Flyte gives you a specific exception for them:
Catch the OOM, bump the resources with `.override()`, and try again. No manual intervention needed.
This is what makes self-healing pipelines and agents possible: your infrastructure becomes part of the context your code can reason about. The failure isn't a log line someone reads the next morning, it's a typed Python exception in the same function that can fix it. An agent that hits an OOM can request more memory. One that hits a timeout can swap to a smaller model or a bigger GPU. One that gets a `NonRecoverableError` knows not to waste attempts and can escalate instead.
Same idea scales past resources. Because the handler is ordinary Python, the recovery path can call another task, ask an LLM what to do next, or write the failure to a store the next run reads. Your pipeline no longer a static DAG that dies on the first bad node and starts being something that adapts to what the infrastructure tells it.
Skip retries for non-recoverable errors
Some errors should fail immediately. Retrying a bad input 3 times just wastes time. Use `NonRecoverableError`:
Even though the task has 3 retries configured, `NonRecoverableError` causes immediate failure without consuming any retry attempts.
Add timeouts to prevent runaway tasks
Combine retries with timeouts so a stuck task doesn't block your pipeline forever:
Combine retries with traces for maximum efficiency
When you pair retries with `@flyte.trace` (from Flyte Log #3), failed retries skip work that already completed:
Key things to know
- `retries=3` means up to 4 total attempts (1 initial + 3 retries)
- Task errors become `flyte.errors.RuntimeUserError` with the original exception name in `e.code`
- `OOMError` and `TaskTimeoutError` are specific subclasses you can catch individually
- `NonRecoverableError` skips all remaining retries and fails immediately
- Retries, timeouts, and traces all compose together naturally
Full retries docs: https://www.union.ai/docs/v2/flyte/user-guide/tasks/task-configuration/retries-and-timeouts/
See what's happening in the Flyte Community:
Latest from the blog
- Flyte 2 Is Generally Available: The Durable, Open-Source AI Runtime - Read on Union.ai
- A Memory Store Built on Flyte and Cognee - Read on Union.ai
- Building Grounded Agents on Fresh Web Data - Read on Union.ai
- From DNA to 3D Fold: Compare a Gene Across Six Species with Carbon and ESMFold - Read on Union.ai
- Run Models, Agents and Apps on Infrastructure You Own - Read on union.ai
- Agents That Survive Production: Rebuilding 21 Design Patterns on Flyte - Read on union.ai
- Introducing Queues and Cluster Controls: Durable Workloads Under Contention - Read on union.ai
- Fine-tune an LLM with LoRA & QLoRA in a Flyte Pipeline - Read on union.ai
Recent talks & recordings
- When the Pipeline Breaks: Building ML Infrastructure for Biotech R&D | Session 1 - Watch on YouTube
- Building Code Mode Agents - Watch on YouTube
- LLM fine-tuning with GRPO - Watch on YouTube
- LLM fine-tuning with LoRA & QLoRA - Watch on YouTube
Upcoming events
- Aug 18th: Flyte 2: The Durable Runtime Built for AI - RSVP on Luma
- Aug 20th: Seattle RAG & Agent Context with Vector Stores | AI Hacknight - RSVP on Luma
Releases & updates
- Flyte 2 Is Generally Available: The Durable, Open-Source AI Runtime - Read on Union.ai
<div class="button-group is-center"><a class="button" target="_blank" rel="noopener noreferrer" href="https://www.union.ai/docs/v2/flyte/user-guide/run-modes/running-devbox/">Download Devbox</a></div>
From the community
- Open-Source Music Generation: Text-to-Music & Lyrics-to-Song - RSVP on Luma
- AI Book Club: Build a Reasoning Model (From Scratch) - RSVP on Luma
That's all for this week! - Sage Elliott




