Anish S
04/01/2026, 2:00 PMMarvin
04/01/2026, 2:00 PMMarvin
04/01/2026, 2:05 PMprefect flow-run inspect <FLOW_RUN_ID>
- CLI (logs, including worker’s exit-code hint):
prefect flow-run logs <FLOW_RUN_ID>
- Python API:
from prefect import get_client
async def show_status(flow_run_id):
async with get_client() as client:
fr = await client.read_flow_run(flow_run_id)
print(fr.state.type) # e.g. 'Crashed'
print(fr.state.message) # includes "non-zero status code <N>"
Notes
- Exit codes are not stored as a separate field; they’re included in the flow run’s state message and worker logs.
- Any non‑zero exit code is treated as infrastructure failure → Crashed. Common examples: 137 (OOM/SIGKILL), 143 (SIGTERM), 125/126/127 (container/command errors).
- If you need a specific code, you can make your container/entrypoint return it; Prefect will record it in the message.
Docs and source
- States concept: States in Prefect
- Docker worker guide: Run with Docker
- CLI reference (inspect/logs): prefect flow-run commands
- Docker worker capturing exit code (source): prefect-docker worker.py
- Worker mapping non‑zero exit → Crashed: prefect workers/base.py
- Exit code hints registry (explanations in logs): _infrastructure_exit_codes.py
If you want, I can share a tiny helper to parse the numeric code out of the state message programmatically.Anish S
04/01/2026, 3:42 PMprefect/utilities/_infrastructure_exit_codes.py
Is there a way to find similar functionality for get_infrastructure_exit_info?Marvin
04/01/2026, 3:42 PMMarvin
04/01/2026, 3:43 PMprefect.utilities._infrastructure_exit_codes module and no get_infrastructure_exit_info helper. That centralized “exit code → explanation” mapping was added later.
What happens in 3.4.8
- Workers (including the Docker worker) capture the raw infrastructure exit code and, if it’s non‑zero, mark the flow run Crashed with a generic message:
- “Flow run infrastructure exited with non-zero status code <N>.”
- There’s no built‑in mapping to human‑readable hints (e.g., 137 = OOM) in 3.4.8.
Where this is handled in 3.4.8 (source links)
- Base worker: non‑zero exit → Crashed with generic message
- base.py L1322-L1328
- Also in ad‑hoc path: base.py L895-L902
- Docker worker: extracts exit code from container and returns it
- Extract exit code: prefect_docker/worker.py L471-L475
- Non‑zero handling path: prefect_docker/worker.py L597-L604
How to get similar functionality to “exit code hints”
- Option A: Manually map common codes in your own post‑processing (e.g., parse flow_run.state.message and add hints in your observability/logging).
COMMON_EXIT_HINTS = {
137: "Likely OOM kill (SIGKILL)",
143: "Graceful termination (SIGTERM)",
125: "Container failed to run (Docker/OCI)",
126: "Command not executable (permission issue)",
127: "Command not found",
}
- Option B: Upgrade to a newer Prefect 3.x where centralized exit‑code hints were added. Then worker logs/state messages include short explanations automatically.
Quick ways to inspect the code/message today
- See state + message (includes exit code):
prefect flow-run inspect <FLOW_RUN_ID>
- See logs (worker logs will show the generic non‑zero message in 3.4.8):
prefect flow-run logs <FLOW_RUN_ID>
- Via API:
from prefect import get_client
async def show_status(flow_run_id):
async with get_client() as client:
fr = await client.read_flow_run(flow_run_id)
print(fr.state.type) # 'Crashed' if non-zero
print(fr.state.message) # includes "non-zero status code <N>"
If you’d like, I can share a small utility that:
- Pulls recent Crashed runs
- Extracts the numeric exit code from state.message
- Adds a human‑readable hint using a mapping like above
- Emits a summary report in Slack or logs