Skip to content

How should my app represent a batch when only some generations succeed?

Represent an application batch as a collection of independent approved actions with per-item states. Define whether the batch is finished when every item is terminal or when a deadline is reached. AISwapLab does not provide an atomic multi-generation transaction that can roll back successful creative outputs.

MAKE API WORK RECOVERABLEAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Define aggregate states; Preserve each item's identity; Offer targeted recovery.
Workflow diagram: Define aggregate states → Preserve each item's identity → Offer targeted recovery. Read the article for evidence and limits.

A batch is an application aggregate

Users may think a batch is one operation, while its individual requests finish differently. A single failed batch label hides usable outputs; a successful label can hide missing ones. The aggregate should summarize actual outcomes without flattening them.

What to do next

  1. 01

    Define aggregate states

    Choose application states such as active, finished with issues and finished, with counts for completed, failed and unresolved items. Keep unknown remote outcomes unresolved rather than counting them as confirmed failures.

  2. 02

    Preserve each item's identity

    Attach its approved snapshot, remote task evidence and result to the batch item. Do not restart successful items when another item fails, and require deliberate approval for any new creative attempt.

  3. 03

    Offer targeted recovery

    Let users inspect the failed or unresolved subset and retain successful outputs. A retry action should identify exactly which new work will be requested and which existing results will remain part of the batch.

A concrete example

Illustrative example: a batch of five posters returns three completed images, one confirmed failure and one uncertain task. The summary reads Three ready, one failed, one awaiting confirmation, with individual actions instead of an all-or-nothing Regenerate button.

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
let releaseC;
let cFinished=false;
const tasks=[Promise.resolve({id:'A'}),Promise.reject(new Error('B failed')),
  new Promise(resolve=>{releaseC=()=>{cFinished=true;resolve({id:'C'});};})];
let allError;
try {await Promise.all(tasks);} catch(error) {allError=error.message;}
const cFinishedWhenAllRejected=cFinished;
releaseC();
const settled=await Promise.allSettled(tasks);
console.log(JSON.stringify({allError,cFinishedWhenAllRejected,
  allSettled:settled.map((r,i)=>({input:['A','B','C'][i],status:r.status,
    value:r.status==='fulfilled'?r.value.id:r.reason.message}))}));

Actual output from this run

json
{
  "allError": "B failed",
  "cFinishedWhenAllRejected": false,
  "allSettled": [
    {
      "input": "A",
      "status": "fulfilled",
      "value": "A"
    },
    {
      "input": "B",
      "status": "rejected",
      "value": "B failed"
    },
    {
      "input": "C",
      "status": "fulfilled",
      "value": "C"
    }
  ]
}

Use the result within its scope

Promise.all rejected while C was still pending. C could still finish afterward, and allSettled retained A's success, B's rejection and C's success. An aggregate error therefore did not establish that every item failed or that outstanding work was cancelled. Keep per-item evidence and authorization for retrying the failed member; do not turn one rejection into a new paid request for all members.

The promises contain synthetic values and one deliberate Error. This does not test upstream batch support, billable outcomes or cancellation of actual generation.

Before you call it ready

  • Counts equal the underlying item states.
  • Successful outputs survive partial failure.
  • Unknown remains distinct from failed.

When to stop or choose another method

Stop describing an application batch as atomic unless your own business operation truly provides that guarantee without pretending remote generations can be undone.

Sources

One task. A recoverable workflow.

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

Open API documentation