Repository navigation
Description
Background
Subprocess coordinators can now locate language-SDK artifacts through a Dag bundle instead of
an explicit filesystem root (#70805). In the co-located default — no explicit root, no
dag_bundle_name — the coordinator scans the task's own Dag bundle.
For JavaCoordinator that makes an existing ambiguity the normal case rather than an edge case.
With main_class unset, _JarInfo.find returns the first JAR carrying a Main-Class in walk
order, and _calculate_classpath puts every JAR it found on the classpath:
airflow/task-sdk/src/airflow/sdk/coordinators/java/coordinator.py
Lines 126 to 144 in 3a08a3d
| @classmethod | |
| def find(cls, roots: Sequence[pathlib.Path], main_class: str) -> _JarInfo: | |
| log.debug("Finding JARs recursively", roots=roots) | |
| progress = cls._Progress() | |
| for p in _find_jars(roots): | |
| if (metadata := _JarMetadata.from_jar(p)) is None: | |
| continue | |
| if metadata.main_class and ((main_class == metadata.main_class) or not main_class): | |
| log.debug("JAR located with Main-Class metadata", path=p, main_class=metadata.main_class) | |
| progress.main_class = metadata.main_class | |
| if metadata.schema_version: | |
| log.debug( | |
| "JAR located with Airflow-Supervisor-Schema-Version metadata", | |
| path=p, | |
| schema_version=metadata.schema_version, | |
| ) | |
| progress.schema_version = metadata.schema_version | |
| if (result := progress.collect()) is not None: |
So a deployment that ships more than one executable JAR in a bundle gets a non-deterministic
entrypoint, and if two of those JARs declare the same dag_id, which definition actually runs
is decided by directory walk order. Nothing warns the user; the task simply runs whichever one
was reached first.
The Python path already handles the equivalent case: _build_duplicate_dag_id_warnings in
airflow-core/src/airflow/dag_processing/collection.py:327 detects a dag_id registered from
more than one file and emits a DagWarning(DUPLICATE_DAG_ID). Language-SDK Dags have no
equivalent, because parsing happens inside the subprocess and there is no import-stage channel
to report into.
#70805 documents the gap rather than closing it — it adds a TODO in
_build_execute_task_command (task-sdk/src/airflow/sdk/coordinators/java/coordinator.py) and a
note in airflow-core/docs/authoring-and-scheduling/language-sdks/java.rst telling users to set
main_class explicitly:
# TODO: Scanning a whole Dag bundle without an explicit main_class lets
# _JarInfo.find pick the first executable JAR in walk order, so duplicate
# entrypoints across bundles resolve non-deterministically — the same
# duplicate-dag_id ambiguity the Python Dag path has. Reject it at the
# IMPORT_ERROR stage once AIP-85 exposes an interface to raise there.
jar = _JarInfo.find(roots, self.main_class)Why this is on hold
The right place to report this is at parse/import time, not at task launch — by the time
_build_execute_task_command runs, the Dag is already scheduled and the user gets, at best, a
task failure with no explanation of the ambiguity.
AIP-85's importer layer is where that reporting belongs.
airflow-core/src/airflow/dag_processing/importers/base.py already models DagImportError,
DagImportWarning, and DagImportResult, but DagImporterRegistry currently only registers
PythonDagImporter, and there is no path for a coordinator-backed parse to raise into the
import-error stage. There is nothing to build against until AIP-85 lands the non-Python importer
path, so this is deliberately parked rather than worked around further.
What needs to happen
- Wait for AIP-85 to land a language-SDK importer path and an interface that lets a
coordinator-backed parse reportDagImportError/DagImportWarning. - During the bundle scan, detect ambiguous entrypoints: more than one artifact declaring an
entrypoint (Main-Classfor Java) whilemain_classis unset. - During the bundle scan, detect duplicate
dag_ids: the samedag_iddeclared by more
than one artifact under the resolved scan root. - Decide the severity for each and keep it consistent with the Python path — duplicate
dag_id
is aDagWarning(DUPLICATE_DAG_ID)there, whereas an unresolvable entrypoint is arguably a
hardDagImportError. - Apply the same detection to the other subprocess coordinators (
ExecutableCoordinator,
NodeCoordinator). The walk-order ambiguity is not Java-specific once co-located mode scans a
whole bundle; Java is only the loudest case because it also affects the classpath. - Remove the TODO in
_build_execute_task_commandand tighten thejava.rstnote once the
check exists.
Acceptance criteria
- Deploying two JARs that declare the same
dag_idinto one bundle surfaces a visible
import-time error/warning in the UI instead of silently resolving to one of them. - With
main_classunset and multiple executable JARs in the resolved scan root, the ambiguity is
reported at parse time rather than resolved arbitrarily at task launch. - The reported severity and message are consistent with the Python duplicate-
dag_idbehaviour. - The TODO in
task-sdk/src/airflow/sdk/coordinators/java/coordinator.pyis removed and the
java.rstwarning updated to describe the enforced behaviour. - Tests cover both the duplicate-entrypoint and duplicate-
dag_idcases.
Context
- Review thread that raised this: Support DagBundle based deployment for Coordinator #70805 (comment)
- PR that introduced the co-located bundle scan: Support DagBundle based deployment for Coordinator #70805
- Related: Java-SDK artifact deployment strategies #66334 (Java-SDK artifact deployment strategies)
- AIP-85: https://cwiki.apache.org/confluence/spaces/AIRFLOW/pages/315494137/AIP-85+DAG+importer
Activity