You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ChickenBenny (via GitHub)" <gi...@apache.org> on 2026/10/16 16:28:34 UTC
[PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
ChickenBenny opened a new pull request, #74869:
URL: https://github.com/apache/airflow/pull/74869
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
* closes: #74716
* related: #74717
---
## Why
Tasks run by a language SDK (Go, TypeScript, Java) ignore `execution_timeout`. A Python task reads the timeout from its parsed Dag and sends `SetExecutionTimeout` to the supervisor, but a language-SDK runtime cannot parse the Python Dag, so the supervisor never arms its deadline. A Go task with a 10s timeout that sleeps 90s ends in `success`.
## What
- For tasks with `is_stub=True` (`@task.stub` and native language-SDK Dags), the API server now sends the timeout in `TIRunContext.execution_timeout` (seconds). A zero timeout means no timeout, as in the Python task runner.
- The supervisor arms its existing deadline from it when the runtime starts: SIGTERM at `execution_timeout` + `killed_task_cleanup_time`, then SIGKILL. This also works for runtimes on an older supervisor schema, since the supervisor reads the field before downgrading the message.
- Python tasks are unchanged: they don't get the field and still send `SetExecutionTimeout` right before `execute()`.
For a language-SDK task the clock starts when the runtime starts, not right before the task runs. A runtime that later sends `SetExecutionTimeout` re-arms it. Cancelling the task inside the runtime (e.g. Go's context) is left to #74717.
The field is added at `2026-10-30` in both the Execution API and the supervisor schema, so this needs `backport-to-v3-4-test` before 3.4.0. Happy to move it to `2027-02-28` instead if preferred (see #74755).
Commits are split for review. The first is a refactor with no behavior change. Most of the `models.gen.go` diff is the generator reordering types; the only new field is `ExecutionTimeout`.
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR, please
change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
-->
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Opus 5.5) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on code in PR #74869:
URL: https://github.com/apache/airflow/pull/74869#discussion_r4302690565
##########
airflow-core/src/airflow/api_fastapi/execution_api/services/task_instances.py:
##########
@@ -44,18 +45,42 @@ def client_supports_arg_bindings() -> bool:
return AddArgBindingsToTIRunContext.is_applied
-def get_arg_bindings(dag_bag: DBDagBag, ti: Any, *, session: Session) -> list | None:
+def get_stub_task(dag_bag: DBDagBag, ti: Any, *, session: Session) -> SerializedOperator | None:
"""
- Extract the stub task's TaskFlow arg spec from its Dag version.
+ Return the task of *ti* from its Dag version if a language SDK runs it, else ``None``.
- Mapped (``.expand()``) stubs never capture a parse-time spec, so they resolve to
- ``None`` here and keep the legacy ignored-args behavior; per-map-index delivery
- lands in a follow-up.
+ Both ``@task.stub`` tasks and the tasks of a Dag defined natively in a language SDK
+ serialize with ``is_stub=True``.
"""
if ti.dag_version_id is None:
return None
if (dag := dag_bag.get_dag(ti.dag_version_id, session=session)) is None:
return None
if (task := dag.task_dict.get(ti.task_id)) is None or not task.is_stub:
return None
+ return task
+
+
+def get_arg_bindings(dag_bag: DBDagBag, ti: Any, *, session: Session) -> list | None:
+ """
+ Extract the stub task's TaskFlow arg spec from its Dag version.
+
+ Mapped (``.expand()``) stubs never capture a parse-time spec, so they resolve to
+ ``None`` here and keep the legacy ignored-args behavior; per-map-index delivery
+ lands in a follow-up.
+ """
+ if (task := get_stub_task(dag_bag, ti, session=session)) is None:
+ return None
return task.arg_bindings
+
+
+def get_language_sdk_execution_timeout(dag_bag: DBDagBag, ti: Any, *, session: Session) -> float | None:
Review Comment:
`get_language_sdk_execution_timeout` uses a falsy check, so a negative
`execution_timeout` passes through: `timedelta(seconds=-1)` is truthy, returns
`-1.0`, and `_arm_execution_timeout` lands the deadline at
`monotonic() - 1 + KILLED_TASK_CLEANUP_TIME` SIGTERM 59s later rather than at
once. `bases/operator.py` only type-checks the field, so this is reachable.
The Python task runner fast-fails instead (`if timeout_seconds <= 0: raise
AirflowTaskTimeout()`, right before it sends `SetExecutionTimeout`), which is why
the supervisor never sees a non-positive value today.
- Treat non-positive as no timeout, which keeps the fix inside the helper and
matches what the docstring already says about zero:
```python
if (task := get_stub_task(dag_bag, ti, session=session)) is None:
return None
timeout_seconds = task.execution_timeout.total_seconds() if task.execution_timeout else 0
if timeout_seconds <= 0:
return None
return timeout_seconds
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on code in PR #74869:
URL: https://github.com/apache/airflow/pull/74869#discussion_r4326649695
##########
airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py:
##########
@@ -512,6 +512,13 @@ class TIRunContext(BaseModel):
``None`` for regular tasks and for stub tasks that declare no parameters.
"""
+ execution_timeout: float | None = None
Review Comment:
Fix with [2bb4a67](https://github.com/apache/airflow/pull/74869/commits/2bb4a673bffcdec404c1dccd4701fca8b2b0da82)
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -409,6 +410,9 @@ def ti_run(
},
)
+ if (execution_timeout := get_execution_timeout(dag_bag, ti, session=session)) is not None:
Review Comment:
Fix with [5c03237](https://github.com/apache/airflow/pull/74869/commits/5c03237bd599cd401a14c7605f6430c544b1e189)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6334472030
### Backport successfully created: v3-4-test
Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>✅</td>
<td>v3-4-test</td>
<td><a href="https://github.com/apache/airflow/pull/75376"><img src="https://img.shields.io/badge/PR-75376-blue" alt="PR Link"></a></td>
</tr>
</table>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on code in PR #74869:
URL: https://github.com/apache/airflow/pull/74869#discussion_r4335431324
##########
task-sdk/src/airflow/sdk/coordinators/_subprocess.py:
##########
@@ -435,6 +438,8 @@ def _prepare_ti_context(self, ti: TaskInstance, ti_context: TIRunContext) -> TIR
)
self.kill(signal.SIGKILL)
return None
+ if ti_context.execution_timeout is not None:
+ self._arm_execution_timeout(ti_context.execution_timeout)
Review Comment:
Fix with 4f732e1e57c00d671030365a6db7147a7a6556d3
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -2146,13 +2151,17 @@ def _handle_skip_downstream_tasks(
self.client.task_instances.skip_downstream_tasks(self.id, msg)
return None, {}
- def _handle_set_execution_timeout(
- self, msg: SetExecutionTimeout, log: FilteringBoundLogger, req_id: int
+ def _handle_start_execution_timeout(
+ self, msg: StartExecutionTimeout, log: FilteringBoundLogger, req_id: int
) -> RequestResult:
- self._execution_timeout_seconds = msg.timeout_seconds
- self._execution_timeout_enforce_at = time.monotonic() + msg.timeout_seconds + KILLED_TASK_CLEANUP_TIME
+ if self._run_context_execution_timeout is not None:
+ self._arm_execution_timeout(self._run_context_execution_timeout)
return None, {}
+ def _arm_execution_timeout(self, timeout_seconds: float) -> None:
+ self._execution_timeout_seconds = timeout_seconds
+ self._execution_timeout_enforce_at = time.monotonic() + timeout_seconds + KILLED_TASK_CLEANUP_TIME
Review Comment:
Fix with 4f732e1e57c00d671030365a6db7147a7a6556d3
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1726,6 +1727,7 @@ def _on_child_started(
# tell us "no, stop!" for any reason)
ti_context = self.client.task_instances.start(ti.id, self.pid, datetime.now(tz=UTC))
self._should_retry = ti_context.should_retry
+ self._run_context_execution_timeout = ti_context.execution_timeout
Review Comment:
Fix with 4f732e1e57c00d671030365a6db7147a7a6556d3
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1664,6 +1664,7 @@ class ActivitySubprocess(WatchedSubprocess):
_task_end_time_monotonic: float | None = attrs.field(default=None, init=False)
_rendered_map_index: str | None = attrs.field(default=None, init=False)
+ _run_context_execution_timeout: float | None = attrs.field(default=None, init=False)
_execution_timeout_seconds: float | None = attrs.field(default=None, init=False)
Review Comment:
Fix with 4f732e1e57c00d671030365a6db7147a7a6556d3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "Andrushika (via GitHub)" <gi...@apache.org>.
Andrushika commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6261339233
> Additionally, for the `SetExecutionTimeout` introduced in https://github.com/apache/airflow/pull/73806: would it be better to rename as `StartExecutionTimeout` and remove the `execution_timeout` field? -- cc @Andrushika
Agree that it will be cleaner -- task runners in all SDKs don't need to work out the timeout by themselves anymore. But we still need to handle users' custom cleanup logic after the timeout.
To be more specific, make all lang SDKs signal-aware (like what #74690 is doing for Java), so that lang SDKs only need to listen to the signal and handle their own cleanup.
> So if a Python task's bundle loading + Dag parsing takes too long, it might get killed before execute() even runs (right now that time isn't counted). Is that OK?
Hmmm I think a better solution could be making the supervisor only start the clock on the start message for Python tasks (the task runner sends it right before `execute()`), since the Dag file import already has its own timeout (see `[core] dagbag_import_timeout`, PR #74571, and the comment here: https://github.com/apache/airflow/pull/73806#issuecomment-6016640315).
For lang SDK tasks, starting it when the runtime starts looks fine to me.
> Item 3 touches Andrushika's SetExecutionTimeout. Should that be a separate PR, or just keep it in this one?
Thanks @ChickenBenny, I think it's fine to handle that in this PR. Since `SetExecutionTimeout` is already in 3.4.0b1, it would be nice to get the rename in before 3.4.0 together with the backport.
Also, two more things I want to mention:
1. The grace period semantics: Currently the supervisor side's timeout acts like a last resort, it lets the task runner have enough time to finish their cleanup first, and only sends the `SIGTERM` if the task runner itself cannot terminate properly. But lang SDK tasks have no timer of their own, so nothing tells them about the timeout during that grace period. They actually get `SIGTERM` at `execution_timeout` + `killed_task_cleanup_time` seconds.
2. If we finally decide to use the signal-cleanup shape I mentioned above: the Python side task runner still has its own timer (SIGALRM), so the timeout logic is not decoupled there yet. It might be a good fit to decouple it, same as the lang SDKs.
But these should be separate follow-up PRs. Just put it here as a reminder. I think we can first get the timeout working here and try to make it for 3.4.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on code in PR #74869:
URL: https://github.com/apache/airflow/pull/74869#discussion_r4303016744
##########
airflow-core/src/airflow/api_fastapi/execution_api/services/task_instances.py:
##########
@@ -44,18 +45,42 @@ def client_supports_arg_bindings() -> bool:
return AddArgBindingsToTIRunContext.is_applied
-def get_arg_bindings(dag_bag: DBDagBag, ti: Any, *, session: Session) -> list | None:
+def get_stub_task(dag_bag: DBDagBag, ti: Any, *, session: Session) -> SerializedOperator | None:
"""
- Extract the stub task's TaskFlow arg spec from its Dag version.
+ Return the task of *ti* from its Dag version if a language SDK runs it, else ``None``.
- Mapped (``.expand()``) stubs never capture a parse-time spec, so they resolve to
- ``None`` here and keep the legacy ignored-args behavior; per-map-index delivery
- lands in a follow-up.
+ Both ``@task.stub`` tasks and the tasks of a Dag defined natively in a language SDK
+ serialize with ``is_stub=True``.
"""
if ti.dag_version_id is None:
return None
if (dag := dag_bag.get_dag(ti.dag_version_id, session=session)) is None:
return None
if (task := dag.task_dict.get(ti.task_id)) is None or not task.is_stub:
return None
+ return task
+
+
+def get_arg_bindings(dag_bag: DBDagBag, ti: Any, *, session: Session) -> list | None:
+ """
+ Extract the stub task's TaskFlow arg spec from its Dag version.
+
+ Mapped (``.expand()``) stubs never capture a parse-time spec, so they resolve to
+ ``None`` here and keep the legacy ignored-args behavior; per-map-index delivery
+ lands in a follow-up.
+ """
+ if (task := get_stub_task(dag_bag, ti, session=session)) is None:
+ return None
return task.arg_bindings
+
+
+def get_language_sdk_execution_timeout(dag_bag: DBDagBag, ti: Any, *, session: Session) -> float | None:
Review Comment:
I fixed it in 658b8147ed, but went a slightly different way from your suggestion: a negative value is clamped to `0.0` instead of returning `None`. This aligns with how the Python task runner handles it, where a negative timeout fails the task right away rather than disabling the timeout: https://github.com/apache/airflow/blob/f3784d2e9e10c175ba4421e2afbb14b61feb3519/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L2318-L2326
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6219989767
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our [Contributors' Guide](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-prek-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 merged PR #74869:
URL: https://github.com/apache/airflow/pull/74869
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6259369970
Thanks Jason for taking a look!
Quick update on where the PR is: killing a timed-out process is already handled in one place by the supervisor. The language SDK coordinators go through ActivitySubprocess too, so Go / TS / Java don't need any changes. The only thing that's still different is where the value comes from: Python still works it out itself and sends it to the supervisor.
Here's roughly what I'm planning to change:
1. Drop the is_stub-only check and send execution_timeout for all tasks
2. Have the Python task runner read the value from TIRunContext instead of working it out again
3. Rename SetExecutionTimeout to StartExecutionTimeout and drop timeout_seconds
A couple of things I'd like to check first:
- When the clock starts: after this change, the supervisor starts the clock as soon as the task starts and restarts it on the Start message. So if a Python task's bundle loading + Dag parsing takes too long, it might get killed before execute() even runs (right now that time isn't counted). Is that OK?
- Item 3 touches Andrushika's SetExecutionTimeout. Should that be a separate PR, or just keep it in this one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #74869:
URL: https://github.com/apache/airflow/pull/74869#discussion_r4332709268
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1726,6 +1727,7 @@ def _on_child_started(
# tell us "no, stop!" for any reason)
ti_context = self.client.task_instances.start(ti.id, self.pid, datetime.now(tz=UTC))
self._should_retry = ti_context.should_retry
+ self._run_context_execution_timeout = ti_context.execution_timeout
Review Comment:
```suggestion
self._execution_timeout_seconds = ti_context.execution_timeout
```
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1664,6 +1664,7 @@ class ActivitySubprocess(WatchedSubprocess):
_task_end_time_monotonic: float | None = attrs.field(default=None, init=False)
_rendered_map_index: str | None = attrs.field(default=None, init=False)
+ _run_context_execution_timeout: float | None = attrs.field(default=None, init=False)
_execution_timeout_seconds: float | None = attrs.field(default=None, init=False)
Review Comment:
Not needed once `_execution_timeout_seconds` holds the run-context value.
```suggestion
_execution_timeout_seconds: float | None = attrs.field(default=None, init=False)
```
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -2146,13 +2151,17 @@ def _handle_skip_downstream_tasks(
self.client.task_instances.skip_downstream_tasks(self.id, msg)
return None, {}
- def _handle_set_execution_timeout(
- self, msg: SetExecutionTimeout, log: FilteringBoundLogger, req_id: int
+ def _handle_start_execution_timeout(
+ self, msg: StartExecutionTimeout, log: FilteringBoundLogger, req_id: int
) -> RequestResult:
- self._execution_timeout_seconds = msg.timeout_seconds
- self._execution_timeout_enforce_at = time.monotonic() + msg.timeout_seconds + KILLED_TASK_CLEANUP_TIME
+ if self._run_context_execution_timeout is not None:
+ self._arm_execution_timeout(self._run_context_execution_timeout)
return None, {}
+ def _arm_execution_timeout(self, timeout_seconds: float) -> None:
+ self._execution_timeout_seconds = timeout_seconds
+ self._execution_timeout_enforce_at = time.monotonic() + timeout_seconds + KILLED_TASK_CLEANUP_TIME
Review Comment:
```suggestion
def _handle_start_execution_timeout(
self, msg: StartExecutionTimeout, log: FilteringBoundLogger, req_id: int
) -> RequestResult:
self._arm_execution_timeout()
return None, {}
def _arm_execution_timeout(self) -> None:
if self._execution_timeout_seconds is None:
return
self._execution_timeout_enforce_at = (
time.monotonic() + self._execution_timeout_seconds + KILLED_TASK_CLEANUP_TIME
)
```
##########
task-sdk/src/airflow/sdk/coordinators/_subprocess.py:
##########
@@ -435,6 +438,8 @@ def _prepare_ti_context(self, ti: TaskInstance, ti_context: TIRunContext) -> TIR
)
self.kill(signal.SIGKILL)
return None
+ if ti_context.execution_timeout is not None:
+ self._arm_execution_timeout(ti_context.execution_timeout)
Review Comment:
How about arming in an `_on_child_started` override instead? Then `_prepare_ti_context` only clears XComs, as its docstring says.
```suggestion
```
```python
def _on_child_started(
self,
*,
ti: TaskInstance,
dag_rel_path: str | os.PathLike[str],
bundle_info,
sentry_integration: str,
) -> None:
super()._on_child_started(
ti=ti,
dag_rel_path=dag_rel_path,
bundle_info=bundle_info,
sentry_integration=sentry_integration,
)
# Language runtimes do not send StartExecutionTimeout, so the clock starts once they have the task.
self._arm_execution_timeout()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on code in PR #74869:
URL: https://github.com/apache/airflow/pull/74869#discussion_r4326646757
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1726,6 +1726,7 @@ def _on_child_started(
# tell us "no, stop!" for any reason)
ti_context = self.client.task_instances.start(ti.id, self.pid, datetime.now(tz=UTC))
self._should_retry = ti_context.should_retry
+ self._execution_timeout_seconds = ti_context.execution_timeout
Review Comment:
Fix with [0589fa1](https://github.com/apache/airflow/pull/74869/commits/0589fa121f9e46e83edca76fff9451cf9ebc0af8)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6333597477
No problem, I've rebased it. The previous CI failure was a mypy error: after the rebase, ti_run assigned two different values to the same task variable. I've renamed mine to fix it. Fix with 287202e
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "Andrushika (via GitHub)" <gi...@apache.org>.
Andrushika commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6261620383
FYI @ChickenBenny, this graph helps me understand the architecture between coordinators, executors, and the task runner a lot. I hope this can help you as well :)
```mermaid
flowchart LR
subgraph SP["Scheduler OS process"]
subgraph LE["LocalExecutor object"]
AQ["activity_queue<br/>IPC"]
RQ["result_queue<br/>IPC"]
WH["workers<br/>Process handles"]
end
end
subgraph WP["Local worker OS process|可重用"]
LOOP["_run_worker()<br/>get loop"]
CM["CoordinatorManager.for_queue()<br/>[sdk] queue_to_coordinator"]
PYC["_PythonCoordinator<br/>queue 沒對應時的 fallback"]
LSC["SubprocessCoordinator<br/>Executable/Java/Node"]
subgraph SV["Supervisor|supervise_task()"]
SUP["ActivitySubprocess object<br/>WatchedSubprocess subtype"]
PSUP["_PopenActivitySubprocess object<br/>ActivitySubprocess subtype"]
end
end
subgraph TP["Task Runner child process|每個 Python task 一個"]
TR["task_runner.main()<br/>operator user code"]
end
subgraph LP["Lang runtime process|每個 lang SDK task 一個"]
GO["Go: bundle binary<br/>BundleRef.Serve()"]
JV["Java: java -classpath ...<br/>Server.serve()"]
TS["TS: node bundle.mjs<br/>bundle.serve()"]
end
AQ ==>|worker gets workload| LOOP
LOOP -->|supervise_task per task| CM
CM -->|queue not mapped| PYC
CM -->|queue mapped| LSC
PYC -.->|creates| SUP
LSC -.->|creates| PSUP
SUP ==>|puts outcome| RQ
PSUP ==>|puts outcome| RQ
WH -->|tracks/joins/terminates| LOOP
SUP -->|forks/starts + waits| TR
PSUP -->|launches runtime + waits| GO & JV & TS
classDef focus fill:#fff3bf,stroke:#e67700,stroke-width:3px
class SUP,PSUP focus
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6264991089
Thanks both! I've updated the PR:
1. The supervisor now takes `execution_timeout` only from `TIRunContext` (resolved from the serialized Dag), and the Execution API sends it for every task.
2. `SetExecutionTimeout` is replaced with `StartExecutionTimeout`, which no longer carries the seconds and is still sent from the same place.
3. Python tasks start the clock when the supervisor receives `StartExecutionTimeout`; language SDK tasks start it once the runtime has started, before `StartupDetails`.
Follow-ups, as discussed:
1. Grace period semantics for language SDK tasks.
2. Decoupling the Python SIGALRM timer. The runner's in-process timer still reads `task.execution_timeout` for now, so I'll move it to `TIRunContext` together with that, instead of in this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6331979737
No problem, I've already rebased it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "ChickenBenny (via GitHub)" <gi...@apache.org>.
ChickenBenny commented on PR #74869:
URL: https://github.com/apache/airflow/pull/74869#issuecomment-6313137778
Thanks ! I've updated the PR.
Follow-ups, as discussed:
1. Grace period semantics for language SDK tasks.
2. Decoupling the Python SIGALRM timer. The runner's in-process timer still reads `task.execution_timeout` for now, so I'll move it to `TIRunContext` together with that, instead of in this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce execution_timeout for tasks run by a language SDK [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #74869:
URL: https://github.com/apache/airflow/pull/74869#discussion_r4313205172
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -409,6 +410,9 @@ def ti_run(
},
)
+ if (execution_timeout := get_execution_timeout(dag_bag, ti, session=session)) is not None:
Review Comment:
nit: Let's retrieve the `SerializedOperator` via `get_task` and pass it down to arg_bindings and execution_timeout to avoid the duplicated prob overhead.
##########
airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py:
##########
@@ -512,6 +512,13 @@ class TIRunContext(BaseModel):
``None`` for regular tasks and for stub tasks that declare no parameters.
"""
+ execution_timeout: float | None = None
Review Comment:
IIUC, we need to fill the task level execution_timeout at `DagSerialization.fill_config_defaults`.
We can keep `execution_timeout` for now and follow-up for rest of the task-level default arguments.
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1726,6 +1726,7 @@ def _on_child_started(
# tell us "no, stop!" for any reason)
ti_context = self.client.task_instances.start(ti.id, self.pid, datetime.now(tz=UTC))
self._should_retry = ti_context.should_retry
+ self._execution_timeout_seconds = ti_context.execution_timeout
Review Comment:
IIUC, we don't need to set the `_execution_timeout_seconds` here. Let's keep the `_arm_execution_timeout` as single writer to mutate the attribute state.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org