A saved CometAPI image is not yet a durable batch acknowledgement

CometAPI’s batch-image tutorial leaves an important restart question: what should the worker do when an image is already saved, but its manifest row is missing?

The September 3 article is a useful starting point for CometAPI image automation, but its displayed Python script separates image storage from batch bookkeeping. Treating the latter as proof of whether generation happened would make recovery unsafe.

The gap in the CometAPI example

The worker sends a generation request to https://api.cometapi.com/v1/images/generations, decodes the returned b64_json or downloads the returned URL, and writes image bytes to a local path based on the job ID. It then returns a result row.

The batch collects list(pool.map(safe_generate, jobs)) before opening output/manifest.jsonl in write mode and writing the rows. That ordering creates a window in which an image has been written but the batch manifest has not.

This is a code-inspection inference, not a crash-test result. An interruption in that window can leave a saved CometAPI result without a corresponding new manifest entry. Whether those bytes survive and are complete depends on the storage behavior. The article’s prose describes temporary-file rename, but the displayed code uses path.write_bytes directly; the example should not be read as demonstrating atomic or durable storage.

The recovery implication is narrower than “never retry”: a missing manifest row alone does not establish that the CometAPI generation failed.

Make acknowledgement a separate transition

The article’s production guidance recommends durable job IDs and a durable queue, acknowledgement only after image and manifest storage, and a dead-letter queue for exhausted jobs. It also warns that replay after partial failure can duplicate spend. Those are recommendations, not guarantees implemented by the sample.

For an application built around this CometAPI worker, I would use the following recovery policy:

  • Asset and durable result record agree: verify the asset’s completeness and association with the job before completing acknowledgement.
  • Expected asset exists, but the result record is missing: reconcile that asset against the durable job identity and integrity metadata. If it can be validated, persist a recoverable result record before acknowledging; do not immediately send another generation request.
  • Asset is missing, partial, or cannot be associated confidently: hold the job for reconciliation. Local absence does not resolve an uncertain remote generation outcome. Apply an explicit retry or manual-resolution policy rather than treating it as proof that no work occurred.

This is proposed application-side design. It requires persistent storage, durable job identity, integrity metadata, and a recovery policy. It does not assume the asset store and queue share a transaction, or that CometAPI provides provider-side idempotency or exactly-once billing; the cited article establishes neither.

Before promoting the tutorial into a durable worker, the useful failure-injection test is to stop it after image storage but before result recording, then again before acknowledgement. Can a restart reconcile the same job without blindly generating another image? That is a proposed test, not a reported result—and it is the boundary a final batch manifest alone cannot cover.

A CometAPI-specific restart checklist

Keep the CometAPI request’s job ID as the key for both the expected asset and the result record. On restart, look up that key before calling /v1/images/generations again: verify the asset bytes and metadata, reconstruct and durably persist the result record when they match, and acknowledge only after both records are durable. If the asset is absent, incomplete, or cannot be tied to that CometAPI job, quarantine the job for an explicit retry or manual decision rather than issuing an automatic duplicate request. This makes the CometAPI call boundary part of the recovery decision without claiming provider-side idempotency.

The retry boundary here is similar to an inference worker that has written a checkpoint but not its job ledger: the checkpoint is useful evidence, not proof that the whole transition committed.

For an image pipeline, I would make the durable record carry the job ID, request parameters (or a safe parameter digest), asset digest, byte length, and storage-generation/version. On restart, a worker can verify that the object is complete and belongs to the same job before reconstructing the result row. A filename that merely contains the job ID is not enough; a truncated object or a stale retry could otherwise be mistaken for the completed generation.

This still does not make the provider call exactly-once. If the asset cannot be verified against durable metadata, the safe state is “needs reconciliation,” with an explicit retry policy (and ideally a human-visible cost decision), rather than silently sending a second generation request. The local record can make recovery deterministic without claiming that CometAPI deduplicates requests or that billing is idempotent.