Skip to content

Prevent DagModel split-brain from cross-bundle dag_id collisions - #76556

Open
meel-ayush wants to merge 1 commit into
apache:mainfrom
meel-ayush:fix-bundle-dag-collision
Open

meel-ayush wants to merge 1 commit into
apache:mainfrom
meel-ayush:fix-bundle-dag-collision

Conversation

@meel-ayush

@meel-ayush meel-ayush commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes: #76551
In Airflow 3, dag_id is the primary key for DagModel across all bundles. If two configured bundles define a Dag with the same dag_id, parsing the second bundle overwrote DagModel.bundle_name and relative_fileloc.
When the first bundle had active DagRuns or queued tasks, workers received tasks with the first bundle's commit SHA but the second bundle's name, failing with Version '<sha>' not found in repository for bundle '<secondary>' (or HTTP 403 under multi-team isolation).
Changes in this PR:

  • Rejects incoming Dags in _reject_cross_bundle_dag_id_collisions if their dag_id is already registered by another actively configured bundle, keeping the existing DagModel row intact.
  • Records an import error on the colliding file pointing to where the Dag is already registered.
  • Allows adoption if the existing Dag is marked stale, or if its owning bundle is no longer in the active bundle configuration (get_configured_bundle_names()).
  • Unconfigured bundles and test fixtures bypass the check so they don't produce false collisions.

Tests

  • Added TestRejectCrossBundleDagIdCollisions in airflow-core/tests/unit/dag_processing/test_collection.py covering duplicate rejection, batch filtering, stale Dag adoption, and adoption from unconfigured/ghost bundles.

AI Usage

  • Yes (please specify the tool below)

@meel-ayush
meel-ayush force-pushed the fix-bundle-dag-collision branch 2 times, most recently from a608b7d to 4979ec9 Compare November 5, 2026 22:19

@yuseok89 yuseok89 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the DagModelOperation.update_dags change mentioned in the description still to come?
CI also needs to go green.

@meel-ayush
meel-ayush force-pushed the fix-bundle-dag-collision branch from 4979ec9 to 55fd9e6 Compare November 6, 2026 08:04
@meel-ayush

Copy link
Copy Markdown
Contributor Author

Is the DagModelOperation.update_dags change mentioned in the description still to come? CI also needs to go green.

Dropped the update_dags() change, handling it in _reject_cross_bundle_dag_id_collisions was enough and much cleaner. Updated the PR description to match.

Also swapped the dag_maker check for get_configured_bundle_names(), which was what caused the DAG.test() failure in CI. Tests are passing locally now.

In Airflow 3, dag_id is the primary key of DagModel across all bundles. When two DAG bundles declare a Dag with the identical dag_id, parsing the secondary bundle unconditionally overwrote DagModel.bundle_name and relative_fileloc. If the primary bundle had already created scheduled DagRuns and queued TaskInstances, the scheduler subsequently generated execution workloads with the primary bundle's commit version but the secondary bundle's name. This caused workers to crash when attempting to check out the primary commit from the secondary repository, and caused the Execution API to reject worker JWT tokens under multi-team isolation.

Resolve this by rejecting incoming Dags whose dag_id is already registered by another active bundle during database collection, logging a warning and recording a user-facing parse import error stating that DAG IDs must be unique across all bundles. Stale Dags remain eligible for adoption if decommissioned from their original bundle, and internal DAG renames within the same bundle continue to function normally.
@meel-ayush

Copy link
Copy Markdown
Contributor Author

@amoghrajesh Following up on your comment in #76551, CI is green here implementing the collision check. A user in #77241 just reported this in production on 3.4.0, so ready for review whenever you have a moment.

@Dev-iL Dev-iL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently (or at least on 2.11), if there are multiple dags with the same dag_id, one of them is selected at random. Assuming this is the case in 3.x, it means the behavior for bundles becomes different - one of dags is parsed and the other errors.

While this turns a runtime error into a parsing error (which is good imho), it departs from the expected behavior. I wonder - would it make more sense to internally qualify dag_ids with the bundle identifier so that collisions are avoided, and either raise a warning or treat this as an acceptable scenario?

Imagine two independent bundles, possibly belonging to different teams, each having a "load_data" id - each one does (and perhaps should) not know/care about the other. Making one of them fail parsing means the solution is possibly upstream of what the Airflow administrator has control over.

To me, it makes more sense to find a way for such dags to work side by side rather than failing to import.

@meel-ayush

Copy link
Copy Markdown
Contributor Author

@Dev-iL

I really like this idea. Having proper DAG namespacing (or composite keys) would be a great feature for multi-team, and I'd love to team up with you and co-author an AIP or start a dev list thread to design that properly.

The catch is that we can't do it inside this bugfix:

  • If we internally prefix the ID (like bundle:dag_id), user code breaks. TriggerDagRunOperator, the CLI, and the Task SDK runner all expect the exact dag_id defined in the Python file. If the file has @dag("load_data"), the worker can't find bundle:load_data.
  • If we change the database schema, dag_id is currently the single primary key across DagModel, DagRun, TaskInstance, DagVersion, REST API routes, and the UI. That requires a full schema migration and an approved AIP.

Right now, two bundles sharing a dag_id don't work side-by-side. The parser loops and constantly overwrites DagModel.bundle_name back and forth. Because each bundle has its own Git commit SHA, workers crash trying to fetch bundle A's commit from bundle B's repository (#77241).

This PR is just the immediate stopgap to prevent that split-brain today. I'd be very happy to work together with you on the broader namespacing AIP after this lands.

@meel-ayush
meel-ayush requested a review from Dev-iL November 24, 2026 13:00
Dev-iL

This comment was marked as off-topic.

@Dev-iL
Dev-iL self-requested a review November 25, 2026 20:08

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DAG Bundles: Duplicate dag_id across bundles causes DagModel overwrite and split-brain workload execution

3 participants