Skip to content

Fix workflow extraction for cross-history copied datasets - #21806

Draft
jmchilton wants to merge 6 commits into
galaxyproject:devfrom
jmchilton:fix_copied_datasets
Draft

Fix workflow extraction for cross-history copied datasets#21806
jmchilton wants to merge 6 commits into
galaxyproject:devfrom
jmchilton:fix_copied_datasets

Conversation

@jmchilton

Copy link
Copy Markdown
Member

Context

Workflow extraction has numerous open issues. One prevalent root cause is the copied dataset problem — when datasets are copied between histories, creating_job_associations still points to jobs in the source history, causing HID mismatches, broken connections, and foreign jobs pulled into the extracted workflow. I've worked around these issues in the past in small ways - this is a shot at that. I think ultimately swapping to ID-based extraction (#21722) will be needed for richer fixes but there are certain classes of dealing with copied datasets in a history that we can address currently and I think this PR does address them.

Bug Fix

Fixes #9161 — extracting workflow from history with copied datasets breaks.

Root cause: When extraction encounters a copied dataset, it follows creating_job_associations back into the source history unconditionally. If the source job's inputs don't exist in the current history, extraction produces broken connections and includes tools that were never run in the target history.

Fix: Before following a copy chain across histories, check whether the creating job's inputs all exist in the current history. When lineage is incomplete (partial copy), treat the copied dataset as an input rather than tracing back. When lineage is complete (full history copy), preserve the full job chain. Also handles collection element HDAs that mapped jobs reference as inputs.

This may also address or partially address:

  • #13823 — partial copy of multi-output collection breaks extraction
  • #12236 — Unzip Collection with copied collections

Test plan

4 new copy-scenario API tests with verify_connected=True:

  • Partial copy (only output copied, input missing)
  • Full history copy (all lineage preserved)
  • Full copy with additional work (chained tools across copy)
  • Mixed scenario (some pipelines fully copied, some partial)

Test polish

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

@jmchilton

Copy link
Copy Markdown
Member Author

None of these test failures are related. The CI suite has gotten greener since this slice in time if we want a rebase I will do that.

@jmchilton

Copy link
Copy Markdown
Member Author

Actually since 21805 was ready to be merged - I should rebase this on top of that pull it back into draft.

@jmchilton
jmchilton marked this pull request as draft February 24, 2026 14:39
jmchilton and others added 6 commits February 24, 2026 09:41
This namedtuple was migrated to populators.py as a proper NamedTuple
class with additional fields. No code imports it from this location.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When a dataset is copied from another history without its inputs,
workflow extraction would fail with broken HID mappings. Now detects
partial copies by checking if job inputs exist in current history.

- Partial copy (missing inputs): treat copied dataset as input
- Full copy (all inputs present): preserve original job lineage
- Add tests for partial/full/mixed copy scenarios

Fixes galaxyproject#9161, galaxyproject#13823, galaxyproject#12236

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The sleep was added in 2019 (9b7ff3f) with a TODO to replace it with
proper waiting. Analysis shows it's no longer needed because:

1. reimport_history() calls wait_for_job() on the __IMPORT_HISTORY__ job
2. That job runs perform_import() which creates Job records synchronously
3. perform_import() calls _flush() before the job completes
4. wait_on_history_length() (added in same 2019 work) provides additional
   synchronization for dataset count

By the time wait_for_job returns, all jobs are committed to the database.
The sleep was likely defensive coding during original development.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- test_subcollection_reduction: add assertions for current (broken) behavior
  with TODO linking to galaxyproject#21789
- test_empty_collection_map_over_extract_workflow: add explicit assertion
  for 0 steps with TODO linking to galaxyproject#21788
- Copy scenario tests: add verify_connected=True to ensure connections
  are properly verified

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added this to the 26.1 milestone Feb 24, 2026
@mvdbeek mvdbeek modified the milestones: 26.1, 26.2 May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Extracting workflow from history with copied datasets breaks

3 participants