Skip to content

Fix nested collector iteration scope#9343

Open
JPPhoto wants to merge 2 commits into
invoke-ai:mainfrom
JPPhoto:fix-nested-collector-iteration-scope
Open

Fix nested collector iteration scope#9343
JPPhoto wants to merge 2 commits into
invoke-ai:mainfrom
JPPhoto:fix-nested-collector-iteration-scope

Conversation

@JPPhoto

@JPPhoto JPPhoto commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes nested collector scoping in graph execution.

Collectors nested under iterators now group prepared parent exec nodes by iteration path. A collector collapses the immediate iterator feeding its item input while preserving enclosing iterator paths, preventing collections from unrelated outer iterations from being mixed before downstream consumers run.

This fixes workflows where an outer item is decomposed into a per-item collection, that collection is iterated, and the results are collected again. The observed case was an XYImage tiling workflow where tiles from separate source images could be combined into the same collected input.

Also updates the execution engine README to document collector grouping, preserved iteration paths, runtime rehydration, and ready queue ordering.

Related Issues / Discussions

N/A

QA Instructions

I verified this fix against current main (9152232189c02d0a3807e18af682e0fc2bccaffa) by applying only the updated tests/test_graph_execution_state.py to a temporary main worktree and running the new tests.

Key failures:

test_graph_collector_nested_under_outer_iterator_collects_only_current_outer_iteration_items

Expected:
[[0, 1], [10, 11]]

Actual on main:
[[0, 1, 10, 11]]
test_graph_collector_reuses_outer_collection_input_for_each_nested_iterator_group

Expected:
[[100, 0, 1], [100, 10, 11]]

Actual on main:
[[100, 0, 1, 10, 11]]

The test_graph_collector_nested_under_three_iterators_preserves_outer_iteration_paths test also fails in similar fashion.

The helper-level test also fails on main because _get_collect_iteration_mapping_groups() does not exist before this branch.

Manual QA, if the XYGrid community node pack is available:

  1. Create a workflow with this shape:
Image Collection (2 visually distinct larger images)
  -> Iterate
  -> Image To XYImage Tiles
  -> Iterate
  -> XYImage Expand
  -> image-processing or pass-through step
  -> XYImage Collect
  -> Collect
  -> XYImage Tiles To Image
  -> Save Image
  1. Configure tiling so each source image produces multiple tiles.

  2. Run the workflow before and after this fix.

Before this fix:

  • The final Collect can mix XYImage Collect outputs from different source images.
  • XYImage Tiles To Image may receive tiles from more than one source image at once.
  • The output can show cross-image composition, for example one source image's tile(s) combined with another's.

After this fix:

  • Each outer source image gets its own collected tile set.
  • XYImage Tiles To Image runs separately per source image.
  • Outputs reconstruct each source image independently, with no cross-image tile mixing.

Note: I checked simpler built-in-only primitive and built-in tile workflows, and they did not reproduce the pre-fix issue. The manual repro needs a workflow shape where a node under the outer iterator produces a fresh per-outer-item collection that is then iterated and collected downstream.

Merge Plan

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@JPPhoto JPPhoto requested a review from blessedcoolant as a code owner July 8, 2026 00:06
@JPPhoto JPPhoto requested review from dunkeroni and lstein as code owners July 8, 2026 00:06
@JPPhoto JPPhoto added the 6.14.x label Jul 8, 2026
@JPPhoto JPPhoto moved this to 6.14.x Theme: USER EXPERIENCE in Invoke - Community Roadmap Jul 8, 2026
@github-actions github-actions Bot added python PRs that change python files services PRs that change app services python-tests PRs that change python tests labels Jul 8, 2026
@JPPhoto JPPhoto requested a review from Pfannkuchensack July 8, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.14.x python PRs that change python files python-tests PRs that change python tests services PRs that change app services

Projects

Status: 6.14.x Theme: USER EXPERIENCE

Development

Successfully merging this pull request may close these issues.

3 participants