Skip to content

Reconnect AWS Batch jobs after worker crashes - #72413

Closed
1fanwang wants to merge 2 commits into
apache:mainfrom
1fanwang:aws-batch-resumability
Closed

1fanwang wants to merge 2 commits into
apache:mainfrom
1fanwang:aws-batch-resumability

Conversation

@1fanwang

@1fanwang 1fanwang commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

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. If AWS no longer returns the stored job, the retry submits a replacement after the existing status retries are exhausted. Other AWS API errors still propagate. Deferrable tasks and wait_for_completion=False keep their existing submission paths.

Testing

Crash/retry proof with task state

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.

$ 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'
Aged-out job regression
$ AIRFLOW_HOME="$PWD/.build/airflow-batch-tests" uv run --project providers/amazon pytest providers/amazon/tests/unit/amazon/aws/hooks/test_batch_client.py::TestBatchClient::test_get_job_description_raises_not_found_after_retries providers/amazon/tests/unit/amazon/aws/operators/test_batch.py::TestBatchOperator::test_resubmits_when_stored_job_not_found providers/amazon/tests/unit/amazon/aws/operators/test_batch.py::TestBatchOperator::test_stored_job_status_propagates_client_error -xvs

# Before
AirflowException: AWS Batch job (...) description error:
exceeded status_retries (3)
1 failed, 1 warning

# After
Prior job in terminal state, resubmitting fresh
external_id=... status=NOT_FOUND
AWS Batch job (new-job-id) started
3 passed, 1 warning

Was generative AI tooling used to co-author this PR?
  • Yes (GitHub Copilot CLI, GPT-5.6 Sol)

Generated-by: GitHub Copilot CLI (GPT-5.6 Sol) following the guidelines


  • Read the 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) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Synchronous Batch tasks can submit a duplicate remote job when a worker crashes after submission but before completion. Reconnecting from task state keeps retries attached to the original job.

Generated-by: GitHub Copilot CLI (GPT-5.6 Sol)
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@boring-cyborg boring-cyborg Bot added area:providers provider:amazon AWS/Amazon - related issues labels Sep 2, 2026
Aged-out AWS Batch jobs otherwise leave every Airflow retry failing before a replacement can be submitted.

Generated-by: GitHub Copilot CLI (GPT-5.6 Sol)
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@potiuk

potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

Hello @1fanwang - thank you for your contributions to Apache Airflow!

The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 34 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:

These pull requests stay open because maintainers are already engaged in them - they count towards your limit:

This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.

What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or gh pr reopen <PR_NUMBER> --repo apache/airflow. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.

While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.

Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

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

Labels

area:providers closed because of open PR limit Closed as a one-time step of introducing the open pull request limit provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants