Skip to content

bug(platform): replacing or deleting a product's image deletes bytes a task lists #4110

Closed

Description

@yannickmonney

Summary

Replacing a product's image, or deleting the product, deletes the old image's stored bytes even when a task lists that image as an attachment. The task keeps showing the file, but its bytes are gone. Per #4085, every run start for that task then fails as input_missing.

This is the class of #4104 in one more lane. #4109 moved deleteFile, the abandoned-upload sweep and the rejected-upload reclaim onto one holder rule, blobRefHeld, whose docstring says it is "ONE predicate for every lane that deletes bytes outside the release seam". The product image release still keeps its own copy, which knows file rows and documents only, not tasks.

Agent #2 found this from source in the #4109 review (TALE-487, MEDIUM follow-up, "UI reach unverified"). This issue confirms it on a native local stack and shows an API reach path.

Source and environment

  • Source: origin/main 3b23bd2cb3bc5a247895c7e7423c82deceefc901 (fix(platform): reclaim a rejected upload only when nothing holds it #4109).
  • Local native stack, owned by the TALE-358 local-qa occurrence 2026-10-03 08:15 Zurich, run bab9f790-2159-4a21-88a7-4b46daffdf28:
    • Database: PostgreSQL 16.15 (PGDG bookworm) with pg_search 0.22.6 and pgvector 0.8.6, initialized like tale-db, on 127.0.0.1:55372.
    • App: bun scripts/dev.ts (backend 127.0.0.1:3676, Vite localhost:3671), with egress to a dead proxy.
    • Object store: a local S3 test double on 127.0.0.1:59072 that logs every request, so each DELETE the backend sends is visible.
    • Data: synthetic owner and organization proof-e1-mus07drs.

Root cause

All references are to services/platform at 3b23bd2cb.

  • The product release keeps its own holder copy. releaseManagedImage (backend/domains/products/service.ts:292-337) returns the old image's ref for deletion unless another file row or a document still serves it (:325-336). It never asks blobRefHeld (backend/domains/files/blob-holders.ts:29), so it also misses taskHoldsBlobRef and a document's retained history_files.
  • Both product routes then delete what it returns. POST /products/:productId and DELETE /products/:productId call deleteOrgBlobRefs on the released refs (backend/domains/products/routes.ts:276, :289).
  • A task can hold the image's ref. The task door's ownership proof (ownsUploadedBlob, file-row arm) accepts a ref whose file row names the caller as uploader. The product image upload registers exactly such a row.

Reach

The path is API-only. The product image URL names the image's file ID, and GET /api/app/files/:fileId returns {file: {storageRef}} to the uploader (backend/domains/files/access.ts:82). POST /api/app/tasks then accepts that ref as an attachment.

The shipped task UI uploads fresh files rather than picking existing ones, and REST v1 carries no task attachments. So no UI path was observed.

Deterministic reproduction

The probe is scripts/e1-product-image-holder.ts, retained in the TALE-358 evidence archive TALE-358-local-qa-r20261003T0815-evidence.tar.gz with its log and the S3 double's request log. All steps go through the session doors under /api/app, as one synthetic owner.

Case Steps DELETEs of the old image's key Bytes after Task still lists the ref
C, control POST products/images → product with that image → upload another image → POST products/:id {imageUrl: new} 1 gone (expected: nothing else holds it) —
H as C, but before the replace: GET files/:fileId → storageRef (200), then POST tasks with it as an attachment (200) 1 gone yes
H2 as H, but DELETE products/:id instead of the replace 1 gone yes

On the same build, DELETE files/:fileId on a task-held ref keeps the bytes (#4109's deleteFile lane; case C4 of TALE-358's #4104 recheck, run bab9f790). Only the product lane still deletes them.

Expected

A product image's bytes go only when nothing holds them, by the same blobRefHeld rule the files lanes use. In H and H2 the bytes stay while the task lists the ref.

Observed

In H and H2, the store receives DELETE /tale358-r0815/proof-e1-mus07drs/<key> for a key the task's attachments still lists.

Acceptance checks

  1. One rule: releaseManagedImage decides with blobRefHeld, covering file rows, documents (file_ref and history_files) and tasks, instead of its own copy. The "ONE predicate" docstring then holds.
  2. Regression lanes: H and H2 keep the bytes (backend:integration, with an object store so a DELETE would be seen), and control C still reclaims an image nothing holds.
  3. No other lanes left: sweep the remaining deleteOrgBlobRefs callers, for example documents/project-text.ts, connectors blob-sink.ts and video links. Each either holds a ref nothing else can name, or asks the shared rule.

Limits

  • Object store: a test double that ignores authentication, not MinIO.
  • Database differences from tale-db: bookworm PostgreSQL 16.15 vs the image's trixie build, and pgvector 0.8.6 vs 0.8.1.
  • Not exercised: the history_files arm and a document holder (both from source only).
  • No UI path observed.

Activity

  1. yannickmonney commented on Oct 3, 2026

    @yannickmonney
    ContributorAuthor

    QA recheck of the product-image lane after #4115 (TALE-358 local-qa, run dd5617f2-d498-4388-8c13-d636315118b7, main a7efe1c51). This replays this issue's own probe e1 natively, with a logging S3 test double; I didn't write #4115.

    Case Before (3b23bd2cb) Now (a7efe1c51)
    H: the image's ref attached to a task, then the product's image replaced 1 DELETE, bytes gone, the task still lists it 0 DELETEs, bytes kept, the task still lists it
    H2: the same, then the product deleted 1 DELETE, bytes gone 0 DELETEs, bytes kept
    C: a replace with no holder (control) 1 DELETE, gone 1 DELETE, gone (the reclaim still works)

    The product lane is fixed. This issue stays open for its other lanes (video-link cleanups, staged skill and automation bundles), per the manager; those weren't exercised here.

  2. yannickmonney commented on Oct 4, 2026

    @yannickmonney
    ContributorAuthor

    Post-merge recheck of #4110's remaining lanes (#4129) on main 74758294b: passes for the two lanes driven live. The other two hold by CI and source. #4129 closed #4110 on 2026-10-03 at 13:54:57Z. The product-image lane (#4115) was already rechecked in issuecomment-5968305304.

    Live, against this occurrence's own stack

    Each case lists its controls.

    1. Task release keeps a product's image (tasks/retire.ts releaseUnlistedTaskBlobRefs; probe k1).
      • Steps: upload a product image (POST /products/images) and create a product with it. Put the image's storage ref on a task, then edit the task's attachments to [].
      • Result:
        • The image's file_metadata row stays active (source = 'product-image', lifecycle_status NULL).
        • The object store never receives a DELETE for its key; it sees only PUT, GET and HEAD.
        • The image URL still answers 200, and the product's image_url is unchanged.
      • Control: a plain owned upload (files/blob-upload → PUT → files/register), listed by a task and then dropped.
        • The release DELETEs its bytes (204) about 2 s after the drop, and its row is reaped.
        • So the release ran in the same window.
    2. Staged bundles can't be taken by another door (files/upload-intents.ts:226; probe k2).
      • Steps: stage a skill_bundle and an automation_bundle through POST /files/upload?purpose=…, then put each storageId on a new task.
      • Result: both are refused with 403 TASK_ATTACHMENT_NOT_OWNED. All staged bytes stay in place.
      • Control: a purpose=file upload is accepted by the same door (200).

    Not driven live: the two video-link lanes

    The cancel/retry/watchdog cleanup and the 7-day unbound GC need an engine-produced transcript row.

    Environment

    Limits

    • The video-link lanes weren't driven live (see above).
    • Only the task door was tried for bundles; the document, mail and REST sync doors share the same proof (ownsUploadedBlob) but weren't called.
    • JSON-level holders beyond listedBlobRefHeld's arms weren't audited.

    Recommendation: #4110 stays closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions