Spring Builders

john clsads
john clsads

Posted on

Handling Interrupted AI Image Requests Without Starting Over

A user requests several AI kitchen concepts. One image finishes, another is still generating, and the browser loses contact with the application. The next interaction matters: does the interface recover the existing work, or encourage the user to submit the entire request again?

AI Kitchen Design is an online tool for exploring kitchen styles, colors, and materials from a room photo. Its task workflow helps users track and recover kitchen design requests while keeping completed concepts available for review. The implementation offers a concrete example of managing uncertainty around an external image-generation service.

This article comes from the AI Kitchen Design team and was prepared with AI assistance. It describes the product's TypeScript implementation; the recovery boundaries are also relevant when designing a Spring service around an external provider. The discussion is based on source review, with no reliability benchmark or failure-injection measurements reported.

What does a timed-out AI request actually tell you?

A timeout tells the application that a response was not received within the expected interval. The remote operation may still have been accepted. Recovery therefore needs evidence about the existing request before deciding whether another submission is appropriate.

There are two useful boundaries to distinguish. The browser may lose the application's response after a batch was created. Separately, the application may lose the provider's response after dispatching an image job. The first can be investigated using the application request identifier; the second needs provider confirmation or reconciliation.

Give the submission an identity before sending it

AI Kitchen Design creates a batch UUID before submitting generation and remembers the pending request. When recovering an interrupted submission, the client first looks up that same batch. If it exists, the interface can resume observing its progress instead of creating another batch.

The client only proceeds toward resubmission after an authoritative not-found response, and it retains the original UUID. On the server, batch creation checks the identifier and its owner; database conflict handling prevents an existing identifier from creating another batch.

  1. Prepare the request. Upload the required images and assign the generation batch its identifier.
  2. Remember the pending submission. Keep the request identity available before the submission begins.
  3. Recover by checking that identity. Treat a network error during lookup as continuing uncertainty.
  4. Reuse the identity when recovery permits submission. Let the server recognize an already-created batch.

The pending marker uses session storage when available, with an in-memory fallback. That helps explain its scope: a marker can support recovery within the current browser session, while the fallback has a shorter lifetime. This mechanism does not establish cross-device recovery or unlimited persistence.

Separate preparation failures from uncertain dispatch

The job implementation tracks whether submission has crossed the provider-dispatch boundary. An input-preparation failure can be classified before that boundary. A lost confirmation after dispatch leaves a different question: did the provider accept the job?

Those situations receive different states and next actions:

Evidence or state Meaning for recovery Next action
Confirmed preparation failure The request failed before dispatch Retain inputs and offer an explicit retry
Unknown submission outcome Provider acceptance is unresolved Continue confirmation and avoid automatic resubmission
Generating An accepted job remains in progress Keep the existing job visible and refresh its status
Saving The provider produced an image that still needs storing Retry the saving stage without requesting another image

AI Kitchen Design includes an unknown state for unresolved submission outcomes. Its interface labels that condition as Confirming progress and asks the user to wait. A generation loop reaching that state directs attention to the saved task rather than silently generating another candidate.

Keep successful candidates available during partial failure

A batch can contain candidates in different states. AI Kitchen Design returns per-job status and available results, allowing the interface to display completed designs while other candidates remain unresolved or have failed.

The task panel also handles partial image-loading failures. It loads available result assets with Promise.allSettled, forwards the successfully opened designs, and records those successes as seen. An image that could not be opened remains eligible for a later loading attempt.

That separates three operations: generating an image, saving the image, and loading it into the browser. A problem in the last operation should not automatically restart the first. For the person comparing kitchen concepts, this means an available design can remain useful while the application checks the missing result.

Make retry a separate, identifiable command

AI Kitchen Design's retry path selects candidates whose state is confirmed as failed. It also gives the retry command its own request UUID. If a retry response is interrupted, the client checks whether that retry identifier was already accepted before issuing the command again.

The server records the retry receipt against its owner and batch. Its selection excludes completed and unresolved candidates. This separates recovering the original submission from intentionally attempting a failed candidate again.

Consider an illustrative three-candidate batch: one design is ready, one has a confirmed failure, and one has an unknown submission outcome. The retry operation addresses the failed candidate. The ready design stays available, while the unknown candidate remains in confirmation. This is a state-handling example, not a measured incident or customer story.

What can a Spring service take from this design?

Carry request identity and job state across the boundaries where uncertainty appears. For a Spring application calling an external AI service, the useful design questions concern persistence, dispatch, reconciliation, and the exact operation a retry should repeat.

  • At request acceptance: Can the client look up the operation after losing the response?
  • At provider dispatch: Can the service distinguish local preparation from uncertain remote acceptance?
  • At result storage: Can storing an existing provider result be retried independently?
  • At explicit retry: Can the service identify the retry command and select only eligible failed work?

These are design questions for a Spring implementation to answer with its own persistence and execution model. The example demonstrates why they matter without prescribing a particular Spring configuration or claiming an exactly-once guarantee across an external provider.

Frequently asked questions

Should every timeout enable a retry button?

A retry action should reflect the operation's known state. If provider acceptance is unresolved, first recover or reconcile the existing request. A confirmed failure supports a different action from a missing response.

Does retrying require all kitchen designs to be regenerated?

AI Kitchen Design's explicit retry operation targets failed candidates within the batch. Completed results and candidates awaiting confirmation are excluded from that selection.

Does a saving error mean image generation failed?

The saving stage can fail after the provider has produced an image. The task interface distinguishes that condition and explains that saving can be retried without asking for another generation.

Design the next action around what is known

AI Kitchen Design connects image generation to visible task status and recovery controls. The broader engineering lesson is to preserve useful results, keep uncertain work identifiable, and make each retry repeat a clearly defined operation. That gives users a more informed next step when a long-running request is interrupted.

Top comments (0)