metaflow debug task command downloads a task’s code package, sets up the environment, and generates debugging scripts and Jupyter notebooks that allow you to inspect and debug task execution.
Synopsis
Global Options
Suppress unnecessary messages
Commands
metaflow debug task
Create a new debugging notebook based on a task pathspec.Arguments
Pathspec to a task in the format
FlowName/RunId/StepName/TaskId. Can also be:- Flow only:
FlowName(uses latest successful run’s end step) - Flow and Run:
FlowName/RunId(uses end step) - Flow, Run, and Step:
FlowName/RunId/StepName(if step has a single task)
Options
Root directory where the code package and debug scripts/notebooks should be generated
Name of the named environment to use for debugging the task. Overrides the Conda environment from this task
Pathspec to use as environment for debugging the task. Overrides the Conda environment from this task
If true, allows the user to inspect the state of the task after it has finished running
Description
Thedebug task command performs the following operations:
- Resolves the task: Converts the pathspec to a specific task, using defaults for missing components
- Sets up the environment: Creates or reuses the Conda environment used by the task
- Downloads code package: Extracts the task’s code package to the specified directory
- Generates escape trampolines: Creates import wrappers to enable proper debugging
- Creates debug scripts: Generates a Python script that replicates the task’s execution context
- Creates debug notebook: Generates a Jupyter notebook pre-configured with the task’s environment
Pathspec Resolution
The command intelligently resolves partial pathspecs:MyFlow→MyFlow/<latest_run_id>/end/<task_id>MyFlow/123→MyFlow/123/end/<task_id>MyFlow/123/my_step→MyFlow/123/my_step/<task_id>(if single task)MyFlow/123/my_step/456→ Used as-is
Environment Override
You can override the task’s original environment using either:--override-env: Specify a named environment alias--override-env-from-pathspec: Use the environment from another task
- The original environment has issues
- You want to test with a different set of dependencies
- You need additional debugging tools not in the original environment
Inspect Mode
When--inspect is enabled, the generated debug script loads the task’s artifacts and final state, allowing you to:
- Examine output artifacts
- Inspect self attributes
- Analyze the task’s final state without re-running the code
Examples
Debug a specific task:Generated Files
The command creates the following in--metaflow-root-dir:
Using the Debug Notebook
Once generated, launch Jupyter and opendebug_notebook.ipynb:
- Pre-loaded task context (self, inputs, artifacts)
- Step code ready to execute
- Access to all task metadata
- Proper environment configuration
Using the Debug Script
Alternatively, run the debug script directly:Requirements
- The task must have been executed remotely (must have a code package)
- The task’s environment must be resolvable
- Jupyter must be installed if using notebooks
Error Handling
Task has no code package:--with batch or deployed to Argo/Step Functions) can be debugged.
Step has multiple tasks:
MyFlow/123/train/456
Environment not found:
metaflow environment get to fetch it first.
Advanced Usage
Kernel Configuration
The command automatically configures a Jupyter kernel with:- Correct Python executable
- PYTHONPATH set to include escape trampolines
- All environment variables from the task’s Metaflow version
Environment Variables
The generatedmetaflow_setup.sh script contains all necessary environment variables:
Debugging Decorators
The debug environment preserves all decorators from the original task:@conda/@pypienvironments@resourcessettings@timeoutvalues- Custom decorators
Related Commands
- metaflow environment create - Create environments for debugging
- metaflow environment show - Inspect task environments
See Also
- Debugging Metaflow - General debugging techniques
- Managing Dependencies - Understanding Conda environments
