{"slug": "tenant-export-retention-after-duplicate-ai-image-retry-overwrite-no-versioning", "title": "Tenant Export Retention After Duplicate AI Image Retry Overwrite (No Versioning)", "summary": "A developer outlined a design for preventing AI image generation retries from silently overwriting earlier results in object storage when versioning is disabled, by treating each generation attempt as immutable, publishing one attempt through a conditional manifest update, and building tenant exports from a pinned manifest snapshot. The approach assigns an attempt ID before generation, reuses it for transport retries, and requires a new ID for new content, with a failure matrix distinguishing missing, overwritten, and unreachable objects. The writeup also estimates retention costs, noting that keeping three complete attempts roughly triples byte-months versus current-only retention.", "body_md": "Short answer: when troubleshooting a missing AI-generated image after a retry, test for a duplicate overwrite of the same object storage key; prevent that collision, even without versioning, by treating every generation attempt as immutable, publishing exactly one attempt through a conditional manifest update, and building each tenant export from a pinned manifest snapshot. This is the least complex design that stops a delivery retry from silently replacing an earlier result while still giving deletion policy a single, auditable place to act.\n\nStart with the bill, because retention determines how much evidence remains after a collision. A useful first approximation is `stored byte-months + write operations + export reads + listings + egress`; use the rates and request classes from the actual provider invoice rather than a generic price comparison. If a hypothetical tenant has 50,000 current product images averaging 4 MB, current-only retention accounts for about 200 GB, while retaining three complete attempts accounts for about 600 GB before replicas or export copies. The important number is the 3x byte-month multiplier, not either vendor's advertised entry price.\n\nI'm not sure which term dominates a particular workload until billing dimensions are joined to object age and export-read telemetry. For an export-heavy B2B SaaS product, repeated reads or egress can outrun retained bytes; for a write-heavy generation pipeline with few downloads, old attempts can dominate. Measure both. The change that usually moves the retention term is to keep one published image for the product's required lifetime, keep superseded attempts only for a bounded diagnostic window, and delete uncommitted attempts sooner. The cost is real: once those attempts are deleted, byte-level reconstruction of a disputed generation is impossible unless an independent, policy-compliant copy exists.\n\nFirst determine whether the image is absent, overwritten, or merely unreachable through metadata. Those cases look identical in a UI but imply different repairs. Compare the export record's object key, content digest, generation attempt ID, and commit revision with the metadata returned for that exact object. Then inspect the idempotency record for the delivery operation. Do not begin by listing a prefix and choosing the newest timestamp; clocks, delayed workers, and unrelated attempts make recency a weak statement of intent.\n\nA compact failure matrix keeps the investigation honest:\n\n| Observation | Likely boundary | Evidence to inspect | Corrective direction | \n|---|---|---|---|\n| Manifest points to a key that has no object | Commit and object write were not coupled | Attempt ID, write receipt, manifest revision | Reconcile the attempt; never invent a replacement key during export | \n| Object exists but digest differs from the manifest | Same-key write replaced bytes | Stored digest, expected digest, writer operation ID | Quarantine the mismatched attempt and republish from retained evidence | \n| Two workers claim one logical attempt | Retry ownership was ambiguous | Idempotency key, lease or compare-and-swap result | Let one conditional commit win; record the other as superseded | \n| Live product view works but export misses it | Export read a moving metadata set | Export snapshot revision and tenant scope | Rebuild from a pinned snapshot, not a live listing | \n\nDo not repair yet.\n\nThe common trigger is a key derived only from tenant and product, such as `tenant/product/hero.png`. A generation retry can produce different bytes, and an upload retry can repeat the same bytes; storage cannot infer which event occurred from the reused name. With versioning disabled, the application has also discarded the most direct evidence of replacement. The remedy is not a cleverer timestamp. Assign an attempt ID before generation, reuse it for transport retries of that attempt, and require a new attempt ID when the generator is asked to produce new content.\n\nKeep attempts immutable.\n\nAn exactly-once mindset does not require pretending that networks deliver a request once. It requires an effect-once protocol: repeated delivery of the same operation either confirms the same bytes or returns a conflict, while publication changes the product manifest only if the caller still holds the expected revision. The object key encodes tenant, product, and attempt identity; the database records the digest and lifecycle state; the manifest names the one published attempt. No component gets to infer publication from object existence alone.\n\nThe following Go sketch keeps provider details behind narrow interfaces. It assumes `PutIfAbsent` verifies that an existing key has the same SHA-256 digest, and `CommitPublished` performs a compare-and-swap on the manifest revision. Those two contracts need integration tests against the chosen storage and database implementations; method names by themselves prove nothing.\n\n```\npackage images\n\nimport (\n    \"context\"\n    \"crypto/sha256\"\n    \"encoding/base64\"\n    \"fmt\"\n)\n\ntype ObjectStore interface {\n    PutIfAbsent(ctx context.Context, key string, body []byte, digest [32]byte) error\n}\n\ntype ManifestStore interface {\n    CommitPublished(\n        ctx context.Context,\n        tenantID string,\n        productID string,\n        attemptID string,\n        objectKey string,\n        digest [32]byte,\n        expectedRevision int64,\n    ) (newRevision int64, err error)\n}\n\nfunc segment(value string) string {\n    return base64.RawURLEncoding.EncodeToString([]byte(value))\n}\n\nfunc PublishAttempt(\n    ctx context.Context,\n    objects ObjectStore,\n    manifests ManifestStore,\n    tenantID string,\n    productID string,\n    attemptID string,\n    expectedRevision int64,\n    png []byte,\n) (int64, error) {\n    key := fmt.Sprintf(\n        \"tenants/%s/products/%s/attempts/%s/image.png\",\n        segment(tenantID), segment(productID), segment(attemptID),\n    )\n    digest := sha256.Sum256(png)\n\n    if err := objects.PutIfAbsent(ctx, key, png, digest); err != nil {\n        return 0, fmt.Errorf(\"store immutable attempt: %w\", err)\n    }\n\n    revision, err := manifests.CommitPublished(\n        ctx, tenantID, productID, attemptID, key, digest, expectedRevision,\n    )\n    if err != nil {\n        return 0, fmt.Errorf(\"commit published attempt: %w\", err)\n    }\n    return revision, nil\n}\n```\n\nThere are two retry classes, and collapsing them is the original design error. A transport retry reuses the operation ID and attempt ID because it is asking for the same effect. A generation retry creates a new attempt ID because it may yield different bytes. If two generation attempts race, both immutable objects may be retained briefly, but only one compare-and-swap can advance a given manifest revision. The losing attempt is not \"missing\"; it is uncommitted evidence with an explicit retention deadline.\n\nAudit records should answer who requested generation, which tenant and product were affected, which operation and attempt IDs were used, which digest was committed, what revision changed, and which policy later deleted the bytes. Avoid placing image bytes, prompts containing personal data, or reusable credentials in the audit stream. Auditability is a record of controlled effects, not an excuse to create an undeletable shadow archive.\n\nA tenant export should begin by committing an export job with a tenant ID and a manifest snapshot revision. Every selected product row is then resolved through that snapshot to a published attempt, and every fetched object is checked against the recorded digest before it enters the archive. Record the export's selection boundary and per-object outcome. If any required object is absent or mismatched, fail the export as incomplete and send the item to reconciliation; do not silently omit it, substitute the latest prefix match, or mark the archive complete.\n\nThis separation matters because an object listing answers \"what keys are visible to this request,\" while a product manifest answers \"what the application published.\" They are different questions. A listing can still be useful for garbage collection, provided the collector compares candidates with manifests, active export pins, and retention deadlines before deletion. It should never define business truth.\n\nTenant isolation belongs in every identifier and authorization decision, not just in the key prefix. The export worker receives an immutable tenant scope, the metadata query filters by that scope, object access is derived from the scoped manifest rows, and the archive path cannot be supplied by a product record. Test cross-tenant substitutions directly: a valid object key from tenant B paired with tenant A's export job must be rejected even if the bytes and digest happen to match.\n\nA managed file system can be appropriate when existing software requires shared POSIX-style file access, while an object-oriented design fits immutable blobs and explicit application manifests. The catch is that changing the storage substrate does not repair ambiguous retry identity. A shared path named only for the product can be overwritten just as readily as an object key named only for the product. Stick with a file system when shared file semantics are a real application requirement; use the same attempt identity, conditional publication, and retention ledger around it.\n\nDeletion is different.\n\nThe operational state machine should distinguish at least uncommitted, published, superseded, export-pinned, deletion-pending, and deleted records. A published image follows the product retention rule. A superseded or uncommitted attempt follows the shorter diagnostic rule. An export pin prevents collection only until the export reaches a terminal state or its lease expires. Deletion-pending blocks new exports immediately, then drives removal from primary storage and every governed derivative before the record becomes deleted.\n\nThis is where correctness and compliance can pull in opposite directions. Keeping every version makes collision analysis easier, but indefinite retention conflicts with a defensible erasure process when an image is personal data. GDPR Article 17 defines a right to erasure and also enumerates circumstances in which that right does not apply; counsel and the data owner must translate those legal conditions into system policy. Engineering still has a precise job: make retention classes explicit, associate derivatives and exports with the source image, record policy decisions, and prove that deletion completed without retaining the deleted content in an audit payload.\n\nThe practical compromise is bounded evidence. During the diagnostic window, retain immutable attempts and their digests so reconciliation can distinguish an overwrite from a stale manifest. After the deadline, remove the attempt bytes and retain only the minimum non-content audit fields permitted by policy. This deliberately gives up late visual reconstruction. It buys a smaller retention surface, predictable byte-months, and an erasure workflow that does not depend on engineers remembering every place an image may have been copied.\n\nTests should exercise the state machine, not just the happy-path upload. Run two publishers with the same expected revision and verify one commit; deliver the same upload operation repeatedly and verify the digest is stable; start an export, supersede an image, and verify the pinned revision remains repeatable; request deletion during an export and verify the documented policy decides which transition wins; inject an object whose digest differs from metadata and verify no complete export is emitted. These are invariant tests. They survive a change of storage implementation.\n\nOperationally, graph unresolved attempts by age, manifest conflicts, digest mismatches, export reconciliation counts, deletion latency, retained bytes by lifecycle state, and export reads by tenant. Logs need operation, attempt, manifest revision, export, tenant, and product identifiers, but they don't need image bodies. Alert on a growing reconciliation queue or deletion work exceeding policy deadlines. Raw request counts alone will not reveal a retry collision because both writes may have succeeded exactly as requested.\n\nStop keeping uncommitted attempts past the bounded diagnostic window, abandoned export archives past their policy deadline, and duplicate derivatives that cannot be traced to a live manifest or active export pin. Do not stop keeping the manifest revision, content digest, idempotency identity, deletion decision, and completion evidence unless the governing policy requires those metadata to go as well. This boundary should be reviewed with compliance because mileage will vary by data category, jurisdiction, and contractual retention duty.\n\nThe decision rule is compact: retain bytes only while they serve a documented product, recovery, export, or legal purpose; retain non-content evidence only while it serves a documented audit purpose; make both deadlines executable state rather than prose in a runbook. If recovery after the diagnostic window is more important than erasure speed and storage exposure, extend the window deliberately. If erasure and minimization dominate, shorten it and accept that an old collision can be proven from metadata but not visually reconstructed.\n\nThe two sources above provide the legal text for erasure boundaries and a primary description of managed file-system semantics; implementation-specific conditional-write, lifecycle, and billing behavior should be verified against the documentation for the components actually selected.", "url": "https://wpnews.pro/news/tenant-export-retention-after-duplicate-ai-image-retry-overwrite-no-versioning", "canonical_source": "https://dev.to/grahamprice3746/tenant-export-retention-after-duplicate-ai-image-retry-overwrite-no-versioning-5cpn", "published_at": "2026-11-30 22:07:35+00:00", "updated_at": "2026-11-30 22:14:45.506527+00:00", "lang": "en", "topics": ["ai-infrastructure", "mlops", "ai-products"], "entities": [], "also_reported_by": [], "takeaway": "Derive object keys from an immutable per-attempt ID rather than tenant/product alone, publish exactly one attempt via a conditional manifest update, and build exports from a pinned manifest snapshot so retries cannot overwrite prior results without versioning.", "recommendation": {"advice": "Assign an attempt ID before generation, reuse it only for transport retries, and commit one attempt through a conditional manifest update so retries cannot overwrite prior results.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/tenant-export-retention-after-duplicate-ai-image-retry-overwrite-no-versioning", "markdown": "https://wpnews.pro/news/tenant-export-retention-after-duplicate-ai-image-retry-overwrite-no-versioning.md", "text": "https://wpnews.pro/news/tenant-export-retention-after-duplicate-ai-image-retry-overwrite-no-versioning.txt", "jsonld": "https://wpnews.pro/news/tenant-export-retention-after-duplicate-ai-image-retry-overwrite-no-versioning.jsonld"}}