Skip to content

fix(platform): keep a product image's bytes while anything holds them - #4115

Merged
yannickmonney merged 1 commit into
mainfrom
fix/product-image-release-blob-held
Oct 3, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/product-image-release-blob-held

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replacing a product's managed image, or deleting the product, deleted the old image's bytes even while a task listed that image as an attachment. The task kept showing the file, and every run start for it then met the store's 404 (#4085's input_missing).

releaseManagedImage decided "may the bytes go?" with its own copy of the holder rule, which knew file rows and a document's current file_ref only. It now asks blobRefHeld, the one predicate #4109 put behind deleteFile, the abandoned-upload sweep and the rejected-upload reclaim. So it also sees tasks (attachments and deliverables) and a document's retained history_files.

Refs #4110. This PR does not close it: the issue's caller sweep (acceptance check 3, below) found more lanes that delete a ref a task or a document can hold.

What changed

  • products/service.ts › releaseManagedImage asks blobRefHeld(tx, organizationId, ref) after it deletes the image's own file row, in the same transaction. This is the same order deleteFile uses: the row goes, and the bytes stay while anything else holds them. Nothing else changed: the "another product still shows it" check, the legal-hold refusal, and the post-commit deleteOrgBlobRefs stay as they were.
  • Both product doors share the release: POST / DELETE /api/app/products/:productId (products/routes.ts:276,289) and REST v1's product update and delete (rest/v1-core.ts:718,733).
  • files/blob-holders.ts docstring now lists the product lane. "ONE predicate for every lane that deletes bytes outside the release seam" now holds for this lane too.
  • No migration, no new error code, no user-visible string, no response change.

Tests

  • New backend:integration lane checkProductImageReleaseHolders (products/image-release.integration.ts). It runs against real Postgres and the object-store pin. Every product write goes through the session doors, as one synthetic admin, and every verdict on the bytes is a HEAD against the store.
    • C (control): an image nothing else holds is reclaimed, row and bytes, on a replace and with its product.
    • H: the issue's reach path. GET files/:fileId hands the uploader the image's storageRef, POST tasks attaches it (200), then the image is replaced. The bytes stay and the task still lists the ref.
    • H2: the same, with DELETE products/:id instead of the replace.
    • Other holders: a task deliverable (outputs), a document's file_ref, a document's history_files and a second file row each keep the bytes through a product delete. The issue had not exercised the history_files arm or a document holder.
  • Unit (products/service.test.ts): the release asks blobRefHeld (a passthrough spy) with the image's ref, and its statement carries the history_files and task arms.

Verification (local)

Real PostgreSQL 16.14 (PGDG bookworm, pgvector 0.8.6, no pg_search) and the CLI's object-store pin, MinIO RELEASE.2025-04-22T22-12-26Z from ghcr.io/tale-project/ops/minio. Each run got a fresh database pair and a fresh MinIO data directory. MinIO's audit webhook logged every S3 call. "main" is 3b23bd2cb plus this PR's two test files only (the lane and its registration).

ITEST_S3_ENDPOINT=… ITEST_LANES=checkProductImageReleaseHolders bun run backend:integration

main + the lane: 17/21, fails

PASS  a product image nothing else holds is reclaimed on a replace and with its product — replace=200 old bytes gone=true row gone=true new kept=true (want 200/true/true/true); delete=200 bytes gone=true row gone=true (want 200/true/true)
FAIL  replacing a product image keeps the bytes a task lists (#4110) — files door=200/same ref=true (want 200/true), attach=200 (want 200), replace=200 (want 200), kept=false listed=true (want true/true), image row gone=true
FAIL  deleting a product keeps the image bytes a task lists (#4110) — files door=200 (want 200), attach=200 (want 200), delete=200 (want 200), kept=false listed=true (want true/true), image row gone=true
FAIL  deleting a product keeps the image bytes a task deliverable, a document or another file row holds — task outputs: delete=200/kept=false, document file_ref: delete=200/kept=true, document history_files: delete=200/kept=false, another file row: delete=200/kept=true (want 200/true each)

This head (03078ad12; ac6eb1465 amends only the commit message, same tree): 20/21, passes

PASS  a product image nothing else holds is reclaimed on a replace and with its product — replace=200 old bytes gone=true row gone=true new kept=true (want 200/true/true/true); delete=200 bytes gone=true row gone=true (want 200/true/true)
PASS  replacing a product image keeps the bytes a task lists (#4110) — files door=200/same ref=true (want 200/true), attach=200 (want 200), replace=200 (want 200), kept=true listed=true (want true/true), image row gone=true
PASS  deleting a product keeps the image bytes a task lists (#4110) — files door=200 (want 200), attach=200 (want 200), delete=200 (want 200), kept=true listed=true (want true/true), image row gone=true
PASS  deleting a product keeps the image bytes a task deliverable, a document or another file row holds — task outputs: delete=200/kept=true, document file_ref: delete=200/kept=true, document history_files: delete=200/kept=true, another file row: delete=200/kept=true (want 200/true each)

In both runs, the one other failure is "knowledge BM25 indexes verified at boot". It fails locally only because pg_search is absent.

The store's own record (MinIO audit), backend DeleteObject calls per probe key, before the lane's cleanup:

Probe main head
C: old image, replaced 1 (HEAD 404) 1 (HEAD 404)
C: image, product deleted 1 (HEAD 404) 1 (HEAD 404)
H: task attachment, replaced 1 (HEAD 404) 0 (HEAD 200)
H2: task attachment, product deleted 1 (HEAD 404) 0 (HEAD 200)
task outputs, product deleted 1 (HEAD 404) 0 (HEAD 200)
document file_ref, product deleted 0 (HEAD 200) 0 (HEAD 200)
document history_files, product deleted 1 (HEAD 404) 0 (HEAD 200)
second file row, product deleted 0 (HEAD 200) 0 (HEAD 200)

Other local gates:

  • vitest: backend/domains/products/, rest/v1-core.test.ts, rest/v1-core.crm.test.ts, rest/product-images.test.ts, files/service.product-images.test.ts, files/blob-holders.test.ts, tasks/blob-holders.test.ts, integration-lane-helpers.test.ts and the integration-scope guard: 12 files, 217 tests, all passing.

  • oxlint --type-aware and oxfmt --check on the changed files: clean.

  • tsc over the changed files, products/routes.ts, rest/v1-core.ts and integration-check.ts: clean.

  • knip: clean.

  • Neighbour blob lanes (checkFiles, checkDocuments, checkBlobRefAuthority, checkAbandonedUploadReclaim, checkTaskHeldBlobOutlivesFileRow, checkRejectedUploadReclaim, checkProductImageReleaseHolders, checkDocumentWriteGuards): the head passes 78/80 and main + the lane passes 75/80. Both share the same 2 environment failures: BM25 without pg_search, and "agent upsert … foreign project", which needs another org's project and fails in any fresh filtered run. main's 3 other failures are this lane's.

Not exercised: a task attach racing the release. Both doors run in transactSerializable, so the release (it reads tasks, then deletes the image's row) and the attach (it reads the row, then inserts the task) are a write skew that SSI aborts and retries. The retry either sees the task or refuses the attach. No UI path reaches H or H2 (#4110: API only).

Caller inventory (#4110 acceptance check 3)

This was a read-only sweep of every deleteOrgBlobRefs caller, webdav's local deleteOrgBlobRef, and every other direct byte delete outside files/service.ts and the release seam, at 3b23bd2cb. Each lane below either deletes a ref nothing else can name, or now asks the shared rule. The exception is the open rows, which were found from source and not exercised.

Lane Ref it deletes Protection Verdict
products/routes.ts:276,289, rest/v1-core.ts:718,733 (product image release) the released image's ref blobRefHeld (this PR) fixed here
files/service.ts deleteFile, claimRejectedUpload, upload-intent sweep stored ref blobRefHeld (#4109) safe
tts/service.ts:458,568,973,1014,1054 TTS chunk ref: no file row, no intent, never sent to a client single holder, row and bytes go together safe
video_links/service.ts:306,339,394, core/video_links/ingest_video_link.ts:286 fresh transcript, nothing committed names it fresh ref safe
products/images.ts:152, connectors/blob-sink.ts:58, files/routes.ts:157, rest/v1-conversations.ts:372 bytes written in the same call, whose row or intent write failed; never returned fresh ref safe
documents/project-text.ts:282, webdav/handlers.ts:1271 fresh bytes after a failed bind or ingest fresh ref; the only residual is a COMMIT the server applied while the client saw an error safe (hardening: ask blobRefHeld first)
documents/replacement.ts:996 server-minted staging and final refs its own file-row-only check; no other door can name these refs today safe (a second copy of the rule)
erasure/service.ts:946,1099 the subject's uploads and video-link refs none, on purpose by design (product decision)
organizations/teardown.ts:131, object_storage/service.ts:477/501/506, store probes, the agent image tool's transit blob whole-org teardown; verified move; probe and transit keys n/a safe
video_links/service.ts:238 cleanupCancelledVideoLink (cancel, retry, watchdog) job.storage_ref, returned to the paster as storageId, and the ref of their own file row none. The task door's file-row arm admits the ref, and so do three document doors open
video_links/service.ts:603 unbound-job GC (7 days) same ref; it then also deletes the file row, even one a document is bound to none open
skills/upload.ts:102, automations/upload.ts:144 (staged bundle cleanup) the staged zip's intent ref, returned by files/upload?purpose=… none. ownsUploadedBlob's intent arm ignores purpose and only stamps bound_at_ms, so a task can hold the zip and the later consume still succeeds open (#4104 class)

The open lanes need their own decisions: whether a cancelled or expired video link may keep bytes that a task or document holds, and whether a staged bundle a task attached is refused or kept. Each also needs its own lane, so they are left out of this PR. The full inventory, with reach sequences, is attached to the tracking task.

Replacing a product's managed image, or deleting the product, released
the old image with its own copy of the holder rule: file rows and a
document's current file. A task that listed the image as an attachment
(the task door accepts a ref whose file row names the caller as its
uploader, and the image's row does), a task deliverable or a document's
retained version lost the bytes, and every run start of such a task
then met the store's 404.

releaseManagedImage now asks blobRefHeld, the one predicate the files
lanes already share: the image's row goes, and its bytes stay while a
file row, a document (current or retained version) or a task still
holds them. The session and REST v1 product doors share the release.

The new checkProductImageReleaseHolders lane proves it against real
Postgres and the object-store pin. On main, the replace and the delete
remove bytes a task attachment, a task deliverable and a document's
retained version hold; with the fix they stay, and an image nothing
holds is still reclaimed on a replace and with its product.

Refs #4110. Its caller sweep (acceptance check 3) found more lanes that
delete a ref a task or a document can hold: the video-link cancel
cleanup and unbound GC, and the staged skill and automation bundle
cleanup. This change does not close the issue.
@yannickmonney
yannickmonney force-pushed the fix/product-image-release-blob-held branch from 03078ad to ac6eb14 Compare October 3, 2026 07:49
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4115 at ac6eb1465171d4b462ca34a79b3534279dea92d5: accepted. The head has the same tree as 03078ad12. The PR refs #4110 rather than closing it, so the three open deletion lanes in its inventory stay with the issue.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run 6b60fb49-b479-4eeb-850a-951812ec31f3.
  • Implementation: agent optimize rag action #4 5f5307c9, TALE-491 run 721b0164 (handoff 585a2581, request a6a56d07). This run is distinct.
  • Method: I read the diff and ran the checks myself, against real PostgreSQL 16 with moto S3. A fresh database and store were used for each run.

The change. releaseManagedImage (products/service.ts) now asks blobRefHeld(tx, organizationId, ref) instead of keeping its own copy, which knew only file rows and a document's file_ref.

  • The order is the same as deleteFile's: the image's own file row goes first, in the same transaction, and only then is the shared rule asked. Asking it before the delete would let the row hold its own bytes forever, and the control below would catch that.
  • Both product doors (session and REST v1) return through that release, so both are covered.
  • The blob-holders.ts docstring now names the product lane.

Local evidence. Lanes checkFiles,checkProductImageReleaseHolders:

Tree Result
main 3b23bd2cb, with only the lane files added 23/28. C (control) passes. H (replace) and H2 (product delete) fail with kept=false listed=true. The other-holders check fails for task outputs and history_files and passes for a document file_ref and another file row, the two holders the old copy did know.
head ac6eb1465 26/28. Every product-image check passes. The 2 failures are environmental: BM25 needs pg_search, and moto has a known checkFiles delete quirk.
  • Unit tests: products/ and files/blob-holders.test.ts pass, 5 files and 59 tests.
  • CI at the exact head: 50 success, 11 skipped by design (candidate gates, fork-PR jobs, untouched containers) and Trivy neutral.
  • Composition with current main d5453d02f:
    • git merge-tree is clean.
    • The only shared file is integration-check.ts, where main added drive-window checks inside an existing lane and this PR adds one lane registration.
    • Locally, the composed tree runs the lane at 26/28, with every product-image check passing (the same two environmental failures).
    • The lockfile is unchanged since 3b23bd2cb.

The caller inventory (#4110 acceptance check 3) sits in the PR body. I spot-checked the staged-bundle claim:

  • skills/upload.ts consumes the skill_bundle intent, then deletes the staged key whatever happens.
  • ownsUploadedBlob's intent arm stamps without checking the purpose, so a task can hold that zip first.
  • The PR marks this lane open, and the inventory is right to.

The other two open lanes, the cancelled video-link cleanup and the 7-day unbound-job GC, are left to #4110 with their own decisions.

INFO

  • The handoff names a possible related bug, unverified: tasks/retire.ts trashes a retired task's own unbound file rows (:189-192), which could include a product image's row if a task's ref is retired. That belongs with bug(platform): replacing or deleting a product's image deletes bytes a task lists #4110's remaining lanes.
  • documents/replacement.ts:996 keeps a second, file-row-only copy of the rule. The inventory finds its refs server-minted and unreachable by another door today, and I agree. The module's "ONE predicate" wording therefore still has that exception, plus the three open lanes.
  • No new UI string and no response change, so there was no browser pass.

Verdict: accepted for #4110's product lane.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant