Skip to content

Enforce the Dag import timeout from the task supervisor side - #74571

Open
Andrushika wants to merge 9 commits into
apache:mainfrom
Andrushika:supervisor-parse-timeout
Open

Andrushika wants to merge 9 commits into
apache:mainfrom
Andrushika:supervisor-parse-timeout

Conversation

@Andrushika

@Andrushika Andrushika commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Why

#73806 lets the task supervisor stop a task process that runs past execution_timeout. The supervisor arms that deadline right before execute().

Before execute(), the task process parses the Dag file. During parsing, only the process's own dagbag_import_timeout alarm applies.

That alarm is a SIGALRM handler, so it never fires when the import is stuck in native code. Nothing outside the process watches this window.

What

Following the SetTimeout(0) suggestion in #73806, the task process sends SetExecutionTimeout with the file's dagbag_import_timeout before it parses a plain Python Dag file. Right after parsing, it sends SetExecutionTimeout(0), which clears the deadline.

The value comes from the get_dagbag_import_timeout cluster policy, with the same file path that the importer uses. If the policy disables the timeout, the task process sends nothing.

Zipped Dags are not armed. The importer gives each member of the archive its own timeout, so one deadline for the whole archive can be too short.

timeout_seconds accepts 0 for the clear. Supervisor schema version 2027-02-28 records this, because 2026-10-30 shipped in Task SDK 1.4.0 with timeout_seconds > 0.

Cost per task start, measured in breeze with a real supervisor (median of 2000 iterations, 3 runs):

  • policy lookup and the two new sends: about 130 µs
  • two existing sends, as a control: about 145 µs

related: #73806


Was generative AI tooling used to co-author this PR?
  • Yes, Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

Move the get_dagbag_import_timeout policy lookup, its fallback when
airflow settings cannot be imported, and the int/float check into a
module-level function, so the task runner can resolve the same value
for a Dag file before it is parsed.
The task process needs to drop the supervisor's deadline once a phase
it armed is over, so a value of 0 now means "no deadline" instead of
being rejected. The supervisor's timeout log line no longer names
execution_timeout, since it will also fire for the Dag parse phase.

SetExecutionTimeout has not been released yet, so the in-progress
supervisor schema version only gets a note instead of a VersionChange.
Before parsing a plain Python Dag file, the task process now sends the
file's dagbag_import_timeout to the supervisor and clears it once
parsing is done, so a parse stuck in native code is stopped from
outside like an execute() that overruns execution_timeout. The value
comes from the same get_dagbag_import_timeout policy the importer uses
for the file's own alarm. Nothing is sent when the policy disables the
timeout.

Zipped Dags are not armed: the importer gives each member its own
timeout, so a single deadline for the archive could be too short.
The message now carries the Dag import timeout as well as the task's
execution_timeout, and 0 clears the deadline, so the old name described
only one of its uses. It has not been released yet, so this is the last
point where the name can change without a migration.
@Andrushika
Andrushika force-pushed the supervisor-parse-timeout branch from cf21b7e to fcdaddc Compare October 12, 2026 06:03
Comment on lines +313 to +328
what = StartupDetails(
ti=TaskInstance(
id=uuid7(),
task_id="a",
dag_id="super_basic",
run_id="c",
try_number=1,
dag_version_id=uuid7(),
queue="default",
),
dag_rel_path="super_basic.py",
bundle_info=BundleInfo(name="my-bundle", version=None),
ti_context=make_ti_context(),
start_date=timezone.utcnow(),
sentry_integration="",
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda want to turn the StartupDetails setup into a common fixture, since about 20 tests in this file build it inline.
That would be a separate follow-up though, happy to do it if maintainers think it's worth it

@fat-catTW fat-catTW left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
thanks

@Andrushika

Copy link
Copy Markdown
Contributor Author

Another related: #69713 (it's a one-line change, ready for review but was closed due to the PR number limit policy)
We could reopen it if it's useful.

…meout

# Conflicts:
#	airflow-core/docs/core-concepts/tasks.rst
#	task-sdk/src/airflow/sdk/execution_time/supervisor.py
#	task-sdk/tests/task_sdk/execution_time/test_supervisor.py
#	task-sdk/tests/task_sdk/execution_time/test_task_runner.py
The 2026-10-30 version shipped in Task SDK 1.4.0 with timeout_seconds > 0,
so accepting 0 to clear the deadline belongs to the in-progress version.
@Andrushika
Andrushika marked this pull request as ready for review November 22, 2026 10:11
@Andrushika
Andrushika requested a review from uranusjr as a code owner November 22, 2026 10:11
@github-actions github-actions Bot added the fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. label Nov 22, 2026
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Fork CI: green. CI for the latest commit passed in your fork. The pull request is ready for maintainer review.

Pull requests from contributors run their CI in the contributor's own fork. GitHub Actions is free and has no minute limit on public forks, while the CI capacity of the Apache Software Foundation is shared by every ASF project and is finite.

Fork CI tested this branch merged with main at fecbb16aa0, as project CI would, 0 commits behind main when the run turned green.

Latest run: https://github.com/Andrushika/airflow/actions/runs/45125041930

How this works: CI in your fork.


This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated.

@github-actions github-actions Bot added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:task-sdk fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. kind:documentation ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants