PranavNayal opened a new pull request, #77790: URL: https://github.com/apache/airflow/pull/77790
When `scheduler_dag_bag.get_dag_for_run()` returns `None` inside `SchedulerJobRunner._task_concurrency_allows_execution()`, the scheduler currently fails every `SCHEDULED` task instance across all runs of that Dag on the first miss, bypassing retries and failure callbacks. ### Root Cause In `airflow-core/src/airflow/jobs/scheduler_job_runner.py`, `_task_concurrency_allows_execution()` immediately issues an `UPDATE` failing all `SCHEDULED` task instances for `dag_id` whenever `get_dag_for_run()` returns `None`, without adding `(dag_id, run_id)` to `starved_dag_runs` or allowing transient misses to recover. `_executable_task_instances_to_queued()` also continues checking remaining tasks of that same run in the batch, causing redundant DB lookups and error logs. ### Changes - Track consecutive missing-serialized-Dag misses per `(dag_id, run_id)` in a bounded in-memory mapping (`_MAX_TRACKED_MISSING_DAG_RUNS = 1024`) on `SchedulerJobRunner`. - On a miss, add `(dag_id, run_id)` to `starved_dag_runs` immediately and short-circuit on `dag_run_key in starved_dag_runs` in `_executable_task_instances_to_queued()`, so healthy runs of the same Dag and other Dags continue scheduling in the same pass without redundant lookups or log spam. - Keep `SCHEDULED` task instances intact for transient misses and reset the counter once `get_dag_for_run()` succeeds again. - Escalate after `MAX_MISSING_SERIALIZED_DAG_MISSES` (`3`) consecutive misses by failing only the `SCHEDULED` task instances of the affected `(dag_id, run_id)` so permanently missing serialized Dags cannot loop indefinitely. ### Tests - Updated `test_queued_task_instances_fails_with_missing_dag` to verify tasks stay `SCHEDULED` across transient misses and escalate to `FAILED` after `MAX_MISSING_SERIALIZED_DAG_MISSES` consecutive misses. - Added `test_queued_task_instances_transient_missing_dag_recovers` to verify recovery queues tasks and resets the miss counter. - Added `test_queued_task_instances_missing_dag_starves_only_affected_run` to verify single-lookup/single-warning batch behavior, no cluster starvation, and run-scoped escalation isolation. - Added `test_missing_serialized_dag_tracking_is_bounded` to verify bounded eviction. Checks executed locally: - `uv run --project airflow-core --no-sync pytest airflow-core/tests/unit/jobs/test_scheduler_job.py -x`: `670 passed, 20 skipped` (SQLite; Postgres/MySQL row-locking and `long_running` tests skipped) - `uv run --no-sync ruff format --check` and `ruff check` on modified files: passed - `uv run --no-sync mypy --config-file pyproject.toml airflow-core/src/airflow/jobs/scheduler_job_runner.py`: passed - `uvx prek run --files ... --stage pre-commit`: passed all applicable hooks except `mypy-airflow-core` isolated venv sync (missing host `libkrb5-dev` headers for `pykerberos`) closes: #62050 --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes — Gemini 4 Hydrogen Generated-by: Gemini 4 Hydrogen 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]
