Skip to content

Fix: Flux.2 reference images presented in random order#96

Merged
lstein merged 2 commits intolstein/feature/reorder-ref-imagesfrom
copilot/fix-flux2-reference-images-order
Feb 27, 2026
Merged

Fix: Flux.2 reference images presented in random order#96
lstein merged 2 commits intolstein/feature/reorder-ref-imagesfrom
copilot/fix-flux2-reference-images-order

Conversation

Copy link

Copilot AI commented Feb 27, 2026

Summary

CollectInvocation items were sorted by (iteration_path, source_node_id) when building the collection. For non-iterated direct connections (the common case for Flux.2 reference images), all items share the same empty iteration path, making the secondary sort fall back to source_node_id — a random UUID — producing non-deterministic ordering on every run.

Fix: Replace source_node_id as the tiebreaker with the edge's insertion index in input_edges. Edges are appended in the order they're added to the graph, which reflects left-to-right visual order from the frontend.

# Before — random order when iteration paths are equal (source_node_id is a UUID)
item_edges.sort(key=lambda e: (self._get_iteration_path(e.source.node_id), e.source.node_id))

# After — ties broken by insertion order, preserving frontend visual order
item_edges_indexed = list(enumerate(e for e in input_edges if e.destination.field == ITEM_FIELD))
item_edges_indexed.sort(key=lambda t: (self._get_iteration_path(t[1].source.node_id), t[0]))
item_edges = [e for _, e in item_edges_indexed]

Related Issues / Discussions

QA Instructions

  1. Set up a Flux.2 Klein generation with 3+ reference images arranged left-to-right (e.g. labeled A, B, C).
  2. Use a prompt that refers to images by position (e.g. "image 1", "image 2").
  3. Run multiple generations and confirm the reference images are consistently passed to the denoiser in the same left-to-right order.

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)
Original prompt

This section details on the original issue you should resolve

<issue_title>[bug]: Flux.2 reference images are presented in random order</issue_title>
<issue_description>### Is there an existing issue for this problem?

  • I have searched the existing issues

Install method

Invoke's Launcher

Operating system

Linux

GPU vendor

Nvidia (CUDA)

GPU model

No response

GPU VRAM

No response

Version number

main branch

Browser

No response

System Information

No response

What happened

When using the Flux.2 Klein models, which accept more than one reference image, the reference images seem to be presented to the denoiser in random order. That is, if I have images named A, B, C and they are ordered that way from left to right in the frontend's reference image list, the backend sometimes receives A, B, C, sometimes C, A, B, and so forth. This makes it impossible to refer to each image by its order in the way that's documented, such as "image 1"

What you expected to happen

I expect the images to be presented to the conditioning and denoising steps in exactly the order they appear in the frontend, ordered from left to right.

How to reproduce the problem

No response

Additional context

No response

Discord username

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Items directly connected to a CollectInvocation were previously sorted by
(iteration_path, source_node_id). Since source_node_id is a random UUID, this
caused non-deterministic ordering for non-iterated direct connections (e.g.
Flux.2 reference images).

Fix: use insertion index as the secondary sort key instead of source_node_id,
preserving the left-to-right visual order from the frontend.

Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix random order of reference images in Flux.2 models Fix: Flux.2 reference images presented in random order Feb 27, 2026
@lstein lstein changed the base branch from lstein/bugfix/flux2-reference-image-order to lstein/feature/reorder-ref-images February 27, 2026 03:27
@lstein lstein marked this pull request as ready for review February 27, 2026 03:27
@lstein lstein self-requested a review as a code owner February 27, 2026 03:27
@lstein lstein merged commit c317e5a into lstein/feature/reorder-ref-images Feb 27, 2026
12 checks passed
@lstein lstein deleted the copilot/fix-flux2-reference-images-order branch February 27, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants