Task duration keeps increasing for skipped tasks due to DAG timeout
- Dominant language
- Python
- Stars
- 46.9k
- Forks
- 17.8k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 483
Description
### Discussed in https://github.com/apache/airflow/discussions/53868
Originally posted by **Szjs-z** July 29, 2025
Hi Airflow community,
I've encountered an issue where task duration keeps increasing for tasks that are skipped due to DAG timeout:
**Problem Description:**
When a DAG run times out due to `dagrun_timeout`, the unfinished tasks are marked as `SKIPPED`. However, in the Web UI, the task duration continues to increase even though the task state is `SKIPPED` :
**Root Cause Analysis:**
From code inspection in `airflow/jobs/scheduler_job.py`, the `_schedule_dag_run` method handles DAG timeout by:
```python
if (
dag_run.start_date
and dag.dagrun_timeout
and dag_run.start_date < timezone.utcnow() - dag.dagrun_timeout
):
dag_run.set_state(DagRunState.FAILED)
unfinished_task_instances = session.scalars(
select(TI)
.where(TI.dag_id == dag_run.dag_id)
.where(TI.run_id == dag_run.run_id)
.where(TI.state.in_(State.unfinished))
)
for task_instance in unfinished_task_instances:
task_instance.state = TaskInstanceState.SKIPPED
session.merge(task_instance)
session.flush()
self.log.info("Run %s of %s has timed-out", dag_run.run_id, dag_run.dag_id)
```
1. Setting DAG run state to FAILED
2. Marking unfinished tasks as SKIPPED
3. But it doesn't set `end_date` for these task instances
I'm wondering if this is a known issue or if there's a recommended way to handle this.
Thanks,
Chris Zhao
Contributor guide
Research direction
Start in airflow/jobs/scheduler_job.py at _schedule_dag_run, where DAG timeout handling marks unfinished task instances as SKIPPED. Trace how the task instance end time is used for Web UI duration, then verify the timeout path records it so the displayed duration stops when the task is skipped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100