Add durable task instance launch records (RFC) - #70931
Open
wolvery wants to merge 1 commit into
Open
Conversation
wolvery
force-pushed
the
fix-durable-executor-launch-records
branch
2 times, most recently
from
August 2, 2026 15:25
420e3c3 to
1f13421
Compare
wolvery
force-pushed
the
fix-durable-executor-launch-records
branch
from
August 9, 2026 20:23
1f13421 to
60db0de
Compare
wolvery
marked this pull request as ready for review
August 12, 2026 21:45
wolvery
requested review from
XD-DENG,
amoghrajesh,
ashb,
dheerajturaga,
ephraimbuddy,
hussein-awala,
jedcunningham,
jscheffl,
kaxil,
o-nikolas and
pierrejeambrun
as code owners
August 12, 2026 21:45
wolvery
force-pushed
the
fix-durable-executor-launch-records
branch
6 times, most recently
from
August 18, 2026 18:06
8dad4d9 to
d075ecb
Compare
Persist immutable executor launch tokens independently of mutable or deleted TaskInstance rows so that expected stale executor launches return a typed 409 stale_executor_launch instead of an opaque 404. Refs apache#69760
wolvery
force-pushed
the
fix-durable-executor-launch-records
branch
from
August 19, 2026 12:57
d075ecb to
d4aa44e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a draft/RFC vertical slice that prevents expected stale executor launches from surfacing as opaque
/run404failures. It introduces durable executor launch records and a typed409 stale_executor_launchresponse, so that a launch attempt from an executor whose task instance row has already been superseded (reset, rescheduled, cleared, or re-adopted) can be distinguished from a genuinely unknown task.Refs #69760.
Motivation
When a task instance transitions out of its original launch (scheduler failover, adoption, stuck-queued reschedule, orphan reset, or a manual clear), the executor that was originally assigned may still attempt to
/runthe task. Because the launch identity lived only on the mutableTaskInstancerow, that late launch produced an opaque404 not_found, which is indistinguishable from a truly unknown task and consumes a retry / blocks clean requeueing.Approach
TaskInstanceLaunchORM persists an immutable executor launch token independently of the mutable/deletedTaskInstancerow, with anactive -> consumed | supersededlifecycle, guarded state transitions, lookup helpers, indexes, and a state check constraint.SCHEDULED -> QUEUEDtransition in the scheduler./runvalidates the launch token:409 stale_executor_launch.404 not_found(legacy tokens predating this change still return404)./runguarded-consumes the launch; duplicate-running remains idempotent.TaskInstanceSupersededErrorin the Task SDK; a superseded worker logs once and exits successfully instead of failing.Changes
airflow/models/task_instance_launch.py+ migration3c5f8e9a1d2b(down-revision7a98f1b7dbd3), registered with DB cleanup.TaskInstanceclear/next-try: supersede active launch./run: durable-token validation + typed409; Cadwyn version adds optionalexternal_executor_id.409 stale_executor_launchtoTaskInstanceSupersededError; supervisor exits0on supersession.KubernetesExecutor.pre_assigns_external_executor_id = Trueso the scheduler pre-assigns a durable launch token (UUID) atQUEUEDtime and writes theTaskInstanceLaunchrow. Without this the launch table stayed empty under K8s and the whole mechanism was inert (Celery-only).exclude=Truefromexternal_executor_idon the executor→worker workload DTO (airflow/executors/workloads/task.py) so the token survivesmodel_dump_json()into the pod's--json-stringand the worker can echo it back on/run. Previously the field was silently dropped for every containerized executor; Celery only worked because it re-injects the token out-of-band as the Celerytask_id.Rollout / compatibility
404— behavior only changes for tokens that have a durable record.Testing
Automated tests
test_task_instance_launch.pyandtest_0128_task_instance_launch_table.py(5 passed) — lifecycle, guarded transitions, and the additive migration (revision3c5f8e9a1d2b, down-revision7a98f1b7dbd3)./rundurable-token validation, typed409 stale_executor_launch, unknown-token404, guarded consume, and clear/next-try supersession.test_failed_adoption_marks_launch_record_supersededcovers the failed-adoption path (successful adoption preserves the token).test_task_instance_start_maps_409_stale_executor_launch(client maps409→TaskInstanceSupersededError) andtest_supervise_handles_superseded_task(superseded worker logs once and exits0).TestExternalExecutorIdFieldBackwardCompatasserts the new behavior is opt-in per Cadwyn version — a pre-v2026_06_30client (noexternal_executor_idin its request schema) still gets404 not_foundfor a stale launch, while a head-version client gets409 stale_executor_launch.-r 7a98f1b7dbd3) → upgrade verified against Postgres;task_instance_launchis cleanly dropped and recreated (matches CI'smigration_testsaction).Validation on a live KubernetesExecutor cluster
The end-to-end path was validated on a local
kindcluster (Airflow Helm chart,--executor KubernetesExecutor, image built from this branch, migration head3c5f8e9a1d2b) driven by a synthetic high-fan-out DAG load (~131 DAGs):task_instance_launchstayed at 0 rows while K8s tasks ran — the mechanism was inert under KubernetesExecutor (token never pre-assigned; and even if it were, it was dropped byexclude=Truebefore reaching the worker).--json-stringargument was confirmed to carryexternal_executor_id=<uuid>, and the same token was traced end-to-end: scheduler pre-assign atQUEUED→ serialized into the pod → echoed back on/run→ guarded-consumed (state=consumed, which only fires on a token match).active → supersededsucceeds; a subsequentconsumeon the now-terminal token is refused by theWHERE state == ACTIVEguard;get_by_tokenstill returns the terminal row (this is what lets/runreturn the typed409 stale_executor_launchinstead of404); repeated supersession is idempotent.Status
Draft / RFC for review of the approach before hardening. Feedback welcome on the launch-record lifecycle and the
409contract.AI disclosure
This change was developed with AI assistance (Anthropic Claude). The design, implementation, migration, tests, and the live-cluster validation were authored with an AI coding agent and reviewed by the submitter, who takes responsibility for the contents.