Skip to content

How can my app recover generation jobs after a server restart?

Store approved payloads, idempotency identifiers and returned job IDs in persistent application storage before relying on an in-memory worker. After restart, reload unfinished tasks and reconcile their existing jobs. A process restart does not justify generating new identifiers or discarding uncertain work; the remote task may already be running or complete.

RECOVER AND DELIVER API JOBSAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Persist before network transmission; Reconcile on startup; Resume delivery separately.
Workflow diagram: Persist before network transmission → Reconcile on startup → Resume delivery separately. Read the article for evidence and limits.

The browser should not own the only copy

An open tab, queue message or temporary variable can disappear while generation continues. Your application needs enough state to reconnect the user to the same task and private result. Keep account ownership and spending approval alongside operational status so another worker cannot accidentally recover a job for the wrong user.

What to do next

  1. 01

    Persist before network transmission

    Write the intended request and durable identifier first. After receiving a creation response, atomically add the returned job ID and poll route to that record.

  2. 02

    Reconcile on startup

    Load local records without terminal delivery states. For a known job, poll it; for a lost response with a saved identifier, recover the original submission using the unchanged body.

  3. 03

    Resume delivery separately

    Completed remote work may still need a local download or notification. Retry that delivery step without creating another image or video, and record when your user actually receives it.

A concrete example

Illustrative crash window: the app records its approved body and request identifier, sends creation, then crashes before saving the response. On restart the absence of remote_job_id is not proof that dispatch never happened. The worker uses the saved original identifier and unchanged request to recover the accepted task. In a different case where the job ID was saved but the browser update was lost, it polls that known job directly.

Restart reconciliation matrix

Durable evidence after restartRecovery operationDo not do
Waiting record; no send attemptResume the approved local queue itemClaim remote acceptance without a response
Send attempted; response/job ID absentRecover unchanged original submission with saved identityGenerate a fresh identifier to make the item look new
Known remote job; local file missingPoll or retrieve existing work as appropriateSubmit a new paid generation to repair delivery

Before you call it ready

  • Task identity survives restarts.
  • Ownership survives worker reassignment.
  • Delivery retries do not recreate media.

When to stop or choose another method

If accepted tasks exist only in memory, pause new submissions and implement persistence before launch. Otherwise an ordinary restart can become lost output or duplicate spending.

Sources

One task. A recoverable workflow.

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

Open API documentation