Repository navigation
fix(platform): keep a product image's bytes while anything holds them - #4115
Conversation
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.
03078ad to
ac6eb14
Compare
|
Independent review of PR #4115 at
The change.
Local evidence. Lanes
The caller inventory (#4110 acceptance check 3) sits in the PR body. I spot-checked the staged-bundle claim:
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
Verdict: accepted for #4110's product lane. |
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).releaseManagedImagedecided "may the bytes go?" with its own copy of the holder rule, which knew file rows and a document's currentfile_refonly. It now asksblobRefHeld, the one predicate #4109 put behinddeleteFile, the abandoned-upload sweep and the rejected-upload reclaim. So it also sees tasks (attachments and deliverables) and a document's retainedhistory_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›releaseManagedImageasksblobRefHeld(tx, organizationId, ref)after it deletes the image's own file row, in the same transaction. This is the same orderdeleteFileuses: 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-commitdeleteOrgBlobRefsstay as they were.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.tsdocstring now lists the product lane. "ONE predicate for every lane that deletes bytes outside the release seam" now holds for this lane too.Tests
backend:integrationlanecheckProductImageReleaseHolders(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.GET files/:fileIdhands the uploader the image'sstorageRef,POST tasksattaches it (200), then the image is replaced. The bytes stay and the task still lists the ref.DELETE products/:idinstead of the replace.outputs), a document'sfile_ref, a document'shistory_filesand a second file row each keep the bytes through a product delete. The issue had not exercised thehistory_filesarm or a document holder.products/service.test.ts): the release asksblobRefHeld(a passthrough spy) with the image's ref, and its statement carries thehistory_filesand 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-26Zfromghcr.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" is3b23bd2cbplus this PR's two test files only (the lane and its registration).main+ the lane: 17/21, failsThis head (
03078ad12;ac6eb1465amends only the commit message, same tree): 20/21, passesIn 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
DeleteObjectcalls per probe key, before the lane's cleanup:mainoutputs, product deletedfile_ref, product deletedhistory_files, product deletedOther 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.tsand the integration-scope guard: 12 files, 217 tests, all passing.oxlint --type-awareandoxfmt --checkon the changed files: clean.tscover the changed files,products/routes.ts,rest/v1-core.tsandintegration-check.ts: clean.knip: clean.Neighbour blob lanes (
checkFiles,checkDocuments,checkBlobRefAuthority,checkAbandonedUploadReclaim,checkTaskHeldBlobOutlivesFileRow,checkRejectedUploadReclaim,checkProductImageReleaseHolders,checkDocumentWriteGuards): the head passes 78/80 andmain+ 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
deleteOrgBlobRefscaller, webdav's localdeleteOrgBlobRef, and every other direct byte delete outsidefiles/service.tsand the release seam, at3b23bd2cb. 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.products/routes.ts:276,289,rest/v1-core.ts:718,733(product image release)blobRefHeld(this PR)files/service.tsdeleteFile,claimRejectedUpload, upload-intent sweepblobRefHeld(#4109)tts/service.ts:458,568,973,1014,1054video_links/service.ts:306,339,394,core/video_links/ingest_video_link.ts:286products/images.ts:152,connectors/blob-sink.ts:58,files/routes.ts:157,rest/v1-conversations.ts:372documents/project-text.ts:282,webdav/handlers.ts:1271blobRefHeldfirst)documents/replacement.ts:996erasure/service.ts:946,1099organizations/teardown.ts:131,object_storage/service.ts:477/501/506, store probes, the agent image tool's transit blobvideo_links/service.ts:238cleanupCancelledVideoLink(cancel, retry, watchdog)job.storage_ref, returned to the paster asstorageId, and the ref of their own file rowvideo_links/service.ts:603unbound-job GC (7 days)skills/upload.ts:102,automations/upload.ts:144(staged bundle cleanup)files/upload?purpose=…ownsUploadedBlob's intent arm ignores purpose and only stampsbound_at_ms, so a task can hold the zip and the later consume still succeedsThe 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.