airflowctl tasks state, failed-deps and logs can't select a task instance inside a task loop
Airflow CTL Version
Latest stable version
Airflow CTL Command
airflowctl tasks state loop_ctl body.step ctl1
Keyring Backend / Version
Keyring Backend/Headless
Auth Type
Token
What is the current behaviour?
Every iteration of a task loop has a task instance with the same Dag id, run id, task id and map index. The API tells them apart by region_id and region_index and rejects a lookup without them. tasks state, tasks failed-deps and tasks logs only take --map-index, so they can't reach any task instance inside a loop:
$ airflowctl tasks state loop_ctl body.step ctl1
Server response error: Client error message: {'detail': 'Select a region and index for this task instance'}
Client error, Please check the command and its parameters. If you need help, run the command with --help.
None of the command's parameters can select the iteration, though. tasks states-for-dag-run lists the iterations without their region, so they look like duplicate rows:
$ airflowctl tasks states-for-dag-run loop_ctl ctl1 -o table
dag_id | task_id | state | ...
loop_ctl | body.step | success | ...
loop_ctl | body.stop_at_three | success | ...
loop_ctl | body.step | success | ...
loop_ctl | body.stop_at_three | success | ...
loop_ctl | body.step | success | ...
loop_ctl | body.stop_at_three | success | ...
What is the expected results?
tasks state,tasks failed-depsandtasks logsaccept--region-idand--region-indexand pass them to the API, as the UI does.- When the API answers "Select a region and index for this task instance", the command says the task runs inside a task loop and which options to pass.
tasks states-for-dag-runshowsregion_idandregion_indexfor task instances in a loop.
Anything else?
Found on main against an apache/airflow:3.4.0 server. tasks state, failed-deps and logs aren't in a release yet (0.1.6 only has states-for-dag-run), so this can be fixed before they ship.
Reproduction Dag (trigger it and let it run its 3 iterations):
import pendulum
from airflow.sdk import DAG, task, task_group
with DAG("loop_ctl", start_date=pendulum.datetime(2026, 1, 1, tz="UTC"), schedule=None):
@task_group
def body():
@task
def step(*, loop):
return loop.index
step()
def stop_at_three(*, loop):
return loop.result >= 3
body.loop(max_iterations=5, until=stop_at_three)
Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Proposed solution:
Add the task-instance loop coordinates as common optional parameters to the three affected airflowctl commands:
tasks statetasks failed-depstasks logs
The CLI should expose --region-id and --region-index, pass both values through the command layer, and include them in the API request/query used to identify the task instance. They should be treated as a pair: reject only one being supplied, with a clear usage error.
For list-style output such as tasks states-for-dag-run, include the region coordinates in table/JSON/YAML output so duplicate task IDs from different loop iterations remain distinguishable.
Regression coverage should include:
- parsing and validation of the two options;
- request construction with both coordinates;
- a task-loop fixture containing repeated task IDs;
- JSON/table output showing the region fields;
- unchanged behavior for ordinary mapped tasks and non-loop task instances.