Skip to content

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

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

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

Conversation

@Andrushika

@Andrushika Andrushika commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Why

Follow-up of #73806. That PR lets the task supervisor stop a task process that runs past execution_timeout, but the deadline is only armed right before execute().

Before that, the task process parses the Dag file under its own dagbag_import_timeout alarm. That alarm is the same SIGALRM handler, so it never fires when the import is stuck in native code, and nothing outside the process watches this window.

What

Following the SetTimeout(0) suggestion in #73806, the task process now sends the file's dagbag_import_timeout to the supervisor before parsing a plain Python Dag file, and 0 right after, which clears the deadline.

The value comes from the get_dagbag_import_timeout cluster policy with the same file path the importer uses, so a file the policy gives more time is not stopped early, and nothing is sent when the policy disables the timeout. Since the message now covers both phases, I renamed SetExecutionTimeout to SetTimeout. It is not released yet, so no schema migration is needed.

Zipped Dags are not armed. Each member is imported under its own timeout, so one deadline for the whole archive could be too short.

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants