Skip to content

How can my app keep batch results attached to the correct input when jobs finish in a different order?

Assign every application batch item a stable ID before dispatch and attach results through that ID and its action association. Never pair the first completed result with the first input merely because their positions match. AISwapLab jobs complete independently, and your application's batch ordering is separate from completion order.

PRESERVE API DATA ACCURATELYAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Create item identities first; Carry identity through every stage; Test reordering and duplicates.
Workflow diagram: Create item identities first → Carry identity through every stage → Test reordering and duplicates. Read the article for evidence and limits.

Position is a presentation choice

A sortable grid, filtered list or asynchronous map can change item order while work runs. Filenames and prompts can also repeat. Correlation must remain stable even if a user reorders cards or several items have identical descriptions.

What to do next

  1. 01

    Create item identities first

    Persist an item ID, approved input snapshot and display-order field for each batch member before dispatch. Keep the display order editable without making it the key used to associate remote jobs and completed assets.

  2. 02

    Carry identity through every stage

    Pass the item and action identity through dispatch, observation, delivery and review records. Resolve results from the saved association, not from array indexes, returned model names or the order promises settle.

  3. 03

    Test reordering and duplicates

    Use identical prompts on several items, reorder the grid and release completions in reverse order. Verify every result remains attached to its original item and any export preserves the chosen presentation order deliberately.

A concrete example

Illustrative example: items A, B and C finish C, A, B. The gallery can still display A, B, C because results join by item ID. Reordering the cards to C, B, A changes presentation without reassigning any result.

Run the local counterexample

Local runtime fixture, executed November 16, 2026. No AISwapLab request, payment or model generation was made.

Recorded runtime: v24.16.0. Run the complete script below using that runtime or record the version and changed behavior in your own environment. The script uses synthetic data and temporary resources only.

javascript
const release = {};
const completionOrder = [];
const inputIds = ['A','B','C'];
const tasks = inputIds.map(id => new Promise(resolve => {release[id]=resolve;})
  .then(() => {completionOrder.push(id);return {itemId:id};}));
const aggregate = Promise.all(tasks);
release.C();release.A();release.B();
const values = await aggregate;
console.log(JSON.stringify({inputIds,completionOrder,
  promiseAllOrder:values.map(x=>x.itemId),
  completionIndexPairing:inputIds.map((id,i)=>[id,completionOrder[i]])}));

Actual output from this run

json
{
  "inputIds": [
    "A",
    "B",
    "C"
  ],
  "completionOrder": [
    "C",
    "A",
    "B"
  ],
  "promiseAllOrder": [
    "A",
    "B",
    "C"
  ],
  "completionIndexPairing": [
    [
      "A",
      "C"
    ],
    [
      "B",
      "A"
    ],
    [
      "C",
      "B"
    ]
  ]
}

Use the result within its scope

Completion occurred C, A, B, but Promise.all returned values in its original input order A, B, C. Pairing the first completion with the first input was wrong; claiming Promise.all itself returns completion order would also be wrong. Persist stable IDs because UI reordering, filtering, retries and partial delivery can break an application's positional assumptions even when this particular aggregate retains order.

These are manually released local promises, not AISwapLab jobs, network responses or an application persistence test.

Before you call it ready

  • Every item has a stable persisted ID.
  • Completion order never drives pairing.
  • Repeated prompts do not collapse distinct items.

When to stop or choose another method

Stop using list indexes or filenames as the authoritative correlation key for independently completing generation tasks.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation