1fanwang opened a new pull request, #72413:
URL: https://github.com/apache/airflow/pull/72413
Synchronous `BatchOperator` tasks always submit a new AWS Batch job when a
worker retry starts. If the first worker dies after submission, the retry can
run the same workload twice.
This change uses AIP-103 task state to persist the Batch job ID before
polling. A retry reconnects to active jobs, finalizes successful jobs without
resubmitting, and submits a new job after a terminal failure. Deferrable tasks
and `wait_for_completion=False` keep their existing submission paths.
## Testing
`providers/amazon/tests/unit/amazon/aws/operators/test_batch.py`: 44 passed.
<details>
<summary>Crash/retry proof with task state</summary>
The temporary proof script loaded the operator from `upstream/main` and the
updated operator, then ran each twice with the real `TaskStateStoreAccessor`,
local supervisor communication, and local AWS hook/waiter stand-ins.
```console
$ AIRFLOW_HOME="$PWD/.build/airflow-batch-tests" uv run --project
providers/amazon python dev/batch_resumability_live.py
2026-09-02T04:09:47.893031Z [warning ] BatchOperator.execute cannot be
called outside of the Task Runner!
[airflow.task.operators.batch_before.BatchOperator] loc=operator.py:439
2026-09-02T04:09:47.895223Z [info ] Running AWS Batch job - job
definition: proof:1 - on queue proof
[airflow.task.operators.batch_before.BatchOperator]
loc=batch_operator_before.py:308
2026-09-02T04:09:47.895396Z [info ] AWS Batch job (before-job-1)
started: {'jobId': 'before-job-1'}
[airflow.task.operators.batch_before.BatchOperator]
loc=batch_operator_before.py:355
2026-09-02T04:09:47.895503Z [info ] AWS Batch job (before-job-1) Job
Definition ARN: 'arn:aws:batch:us-east-1:123456789012:job-definition/proof:1',
Job Queue ARN: 'arn:aws:batch:us-east-1:123456789012:job-queue/proof'
[airflow.task.operators.batch_before.BatchOperator]
loc=batch_operator_before.py:385
2026-09-02T04:09:47.896036Z [warning ] BatchOperator.execute cannot be
called outside of the Task Runner!
[airflow.task.operators.batch_before.BatchOperator] loc=operator.py:439
2026-09-02T04:09:47.896102Z [info ] Running AWS Batch job - job
definition: proof:1 - on queue proof
[airflow.task.operators.batch_before.BatchOperator]
loc=batch_operator_before.py:308
2026-09-02T04:09:47.896258Z [info ] AWS Batch job (before-job-2)
started: {'jobId': 'before-job-2'}
[airflow.task.operators.batch_before.BatchOperator]
loc=batch_operator_before.py:355
2026-09-02T04:09:47.896389Z [info ] AWS Batch job (before-job-2) Job
Definition ARN: 'arn:aws:batch:us-east-1:123456789012:job-definition/proof:1',
Job Queue ARN: 'arn:aws:batch:us-east-1:123456789012:job-queue/proof'
[airflow.task.operators.batch_before.BatchOperator]
loc=batch_operator_before.py:385
2026-09-02T04:09:47.896517Z [info ] AWS Batch job (before-job-2)
succeeded [airflow.task.operators.batch_before.BatchOperator]
loc=batch_operator_before.py:477
before: submissions=['before-job-1', 'before-job-2'] stored_job_id=None
retry_result='before-job-2'
2026-09-02T04:09:47.897154Z [warning ] BatchOperator.execute cannot be
called outside of the Task Runner!
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=operator.py:439
2026-09-02T04:09:47.948536Z [info ] Running AWS Batch job - job
definition: proof:1 - on queue proof
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=batch.py:354
2026-09-02T04:09:47.948675Z [info ] AWS Batch job (after-job-1) started:
{'jobId': 'after-job-1'}
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=batch.py:402
2026-09-02T04:09:47.972051Z [info ] AWS Batch job (after-job-1) Job
Definition ARN: 'arn:aws:batch:us-east-1:123456789012:job-definition/proof:1',
Job Queue ARN: 'arn:aws:batch:us-east-1:123456789012:job-queue/proof'
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=batch.py:466
2026-09-02T04:09:47.976298Z [warning ] BatchOperator.execute cannot be
called outside of the Task Runner!
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=operator.py:439
2026-09-02T04:09:47.976632Z [info ] AWS Batch job (after-job-1) Job
Definition ARN: 'arn:aws:batch:us-east-1:123456789012:job-definition/proof:1',
Job Queue ARN: 'arn:aws:batch:us-east-1:123456789012:job-queue/proof'
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=batch.py:466
2026-09-02T04:09:47.976871Z [info ] Reconnecting to existing job
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
external_id=after-job-1 external_id_key=batch_job_id
loc=resumablejobmixin.py:161 status=RUNNING
2026-09-02T04:09:47.976966Z [info ] AWS Batch job (after-job-1) Job
Definition ARN: 'arn:aws:batch:us-east-1:123456789012:job-definition/proof:1',
Job Queue ARN: 'arn:aws:batch:us-east-1:123456789012:job-queue/proof'
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=batch.py:466
2026-09-02T04:09:47.977017Z [info ] AWS Batch job (after-job-1)
succeeded
[airflow.task.operators.airflow.providers.amazon.aws.operators.batch.BatchOperator]
loc=batch.py:558
after: submissions=['after-job-1'] stored_job_id='after-job-1'
retry_result='after-job-1'
```
</details>
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (GitHub Copilot CLI, GPT-5.6 Sol)
Generated-by: GitHub Copilot CLI (GPT-5.6 Sol) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
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]