jason810496 opened a new pull request, #71102:
URL: https://github.com/apache/airflow/pull/71102
## Why
A planned follow-up will let subprocess coordinators heartbeat while
materializing a Dag bundle, before the task subprocess exists. That requires
the heartbeat state to live outside `ActivitySubprocess`, especially the pid
presented to the server: it must stay identical for the whole task instance
lifetime, otherwise the server rejects the heartbeat with 409
`running_elsewhere` and the task is killed. This PR is the purely mechanical
foundation with no behavior change.
## What
- Add a `Heartbeater` class in `supervisor.py` owning the heartbeat state
(`_last_successful_heartbeat`, `_last_heartbeat_attempt`, `failed_heartbeats`)
and a fixed `pid`, with the moved methods:
- `send_heartbeat_if_needed()` and `_handle_heartbeat_failures()` (moved
from `ActivitySubprocess`)
- `compute_max_wait_time()` (the select-timeout formula moved from
`_monitor_subprocess`)
- `record_successful_heartbeat()` (the task-start call already counts as a
beat on the server)
- Rewire `ActivitySubprocess` to compose a `Heartbeater`, injecting its
reactions as callbacks:
- `on_server_terminated`: terminate the process and record
`SERVER_TERMINATED`
- `on_fatal_failures`: kill the process after `MAX_FAILED_HEARTBEATS`
- `_send_heartbeat_if_needed` stays as a thin wrapper keeping the overtime
guard
- Constants (`HEARTBEAT_TIMEOUT`, `MIN_HEARTBEAT_INTERVAL`,
`MAX_FAILED_HEARTBEATS`) stay module level, so existing config handling and
test monkeypatching are unaffected
- Update `test_supervisor.py` references to the moved attributes; the
behavior tests (`test_regular_heartbeat`, `test_no_heartbeat_in_overtime`,
`test_state_conflict_on_heartbeat`) pass unchanged
---
##### Was generative AI tooling used to co-author this PR?
- [x] Yes, with help of Claude Code Opus 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]