Repository navigation
fix(platform): reclaim a rejected upload only when nothing holds it - #4109
Conversation
A real-Postgres lane, checkRejectedUploadReclaim, drives POST /api/app/files/reject-blob through the session doors against the object-store pin and judges the bytes by HEAD: the caller's unbound upload goes; a foreign or registered one stays (the controls); and an upload a task lists (#4104's P2), one a document or a task holds without a stamp, one a non-consuming bind vouched for, a reclaimed ref attached afterwards and a bind racing the reclaim must all keep their bytes. On main the last five fail: the reclaim deletes the bytes, and a reclaimed ref can still be attached to a task.
POST /api/app/files/reject-blob proved "never bound" by consuming the caller's open upload intent and asked about file rows alone. The task door, the document multi-bind and the outbound-mail door bind without consuming (they stamp bound_at_ms), so an upload attached to a task and then rejected lost its bytes while the card kept listing it (#4104). One holder rule now answers "may these bytes go?" for every lane that deletes bytes outside the release seam: blobRefHeld (files/blob-holders.ts) holds a ref named by a file row, a document's current file or retained version, or a task. deleteFile and the abandoned-upload sweep ask it in place of their own copies. The reclaim claims the caller's intent in one statement on its row (claimRejectedUpload): unconsumed, inside its TTL, not vouched for and not held, or nothing goes. A bind still committing holds the row's lock, so the claim waits and re-reads the stamp; the claim deletes the intent rather than consuming it, so a reclaimed ref is no longer the caller's to attach. consumeUploadIntent's any-purpose form lost its last caller and now requires a purpose. Closes #4104
Backend integration run 37097165795 failed one of 1487 checks: checkRagWatchdogBatch's "a row lock held past the settle lock timeout defers that row alone" read locked=failed because a second, concurrent rag reconcile tick (two "failed 2" lines at 04:42:26.281 and .286) failed the row the moment the test released its lock. The lane runs before this change's lane, imports none of the changed modules, passed on main's CI run 37085344227 and passes locally on this head. The token cannot rerun a job, hence this empty commit.
|
Independent review of PR #4109 at
Local runtime evidence. Lanes
Verified correct, from source (the review agent, cross-checked):
MEDIUM (pre-existing on
LOW and INFO, all pre-existing unless noted:
Verdict: accepted. #4104's acceptance checks 1 and 2 are met and pinned. Check 3, the optional consume at the task bind, was rightly not taken. The product-image MEDIUM goes to the manager as a follow-up. |
Summary
POST /api/app/files/reject-blobdeleted the bytes of an upload that a task already listed as an attachment. The reclaim decided "never bound" by consuming the caller's open upload intent, and it checked file rows only. But the task door, the document multi-bind and the outbound-mail door bind without consuming: they stampbound_at_msinstead (#3191). The reclaim also never asked #4085'staskHoldsBlobRef.Now one holder rule decides "may these bytes go?" for every lane that deletes bytes outside the release seam. The reclaim claims the caller's intent in a single statement on its row, and only when nothing holds the blob.
Closes #4104
What changed
One holder rule:
blobRefHeld(newbackend/domains/files/blob-holders.ts). A ref is held when any of these names it:file_refor a retainedhistory_filesversion;taskHoldsBlobRef).deleteFileand both abandoned-upload sweep statements now ask this rule instead of carrying their own copies. As a result,deleteFilenow also keeps retained-version bytes, and the sweep now also keeps a ref a document holds. Both changes keep bytes; neither deletes anything new. The knowledge release seam (assessRefLiveness) keeps its own statement: it judges in the middle of a purge (live rows only, minus the row being purged), and the new module says so.The reclaim claims atomically:
claimRejectedUpload(upload-intents.ts). It is oneDELETE … RETURNINGon the caller's intent row. It succeeds only if the intent is the caller's, unconsumed, inside its TTL, not vouched for (bound_at_ms IS NULL) and not held (blobRefHeld).deleteRejectedUploadBlobasks nothing else, then deletes the key.reject-blob, or the task door mid-transaction) holds the row's lock. The claim waits, then re-reads the stamp.ownsUploadedBlobstill accepts a consumed intent for the rest of its TTL, so onmaina reclaimed ref can still be attached to a task. Deleting the row means it can't.consumeUploadIntent's any-purpose form lost its only caller (the reclaim), sopurposeis now required.Response unchanged: still
{deleted: boolean}. No migration, no new error code, no user-visible string.Not chosen: consuming the intent at the task bind (acceptance check 3).
ownsUploadedBlobdeliberately doesn't consume: one upload can become one document per team, or a task plus a document, or a mail attachment. Consuming at one door would break those multi-binds. The claim-side rule covers every non-consuming lane (tasks, document multi-bind, outbound mail) at once.Finding → commit → test
files/upload→ task attach → reject deleted the bytes719ee861a(fix)checkRejectedUploadReclaim: "keeps the bytes of an upload a task lists";upload-intents.test.ts›claimRejectedUploadtaskHoldsBlobRef,documents.file_ref)719ee861afile_ref,history_files, taskoutputs);blob-holders.test.ts719ee861afirstForeignUpload, the mail door's proof)719ee861apg_stat_activity719ee861ad96d728bc(lane)719ee861aservice.reject-blob.test.tsdeleteFileand the sweep719ee861aupload-intents.test.ts(sweep statements);checkFiles,checkTaskHeldBlobOutlivesFileRow,checkAbandonedUploadReclaim(real Postgres)Test plan
These ran locally against real PostgreSQL 16.14 (pgvector 0.8.6, no pg_search) and the CLI's object-store pin: MinIO
RELEASE.2025-04-22T22-12-26Z, pulled fromghcr.io/tale-project/ops/minio, binary sha25653e2a2cb…bb817cmatching the image's ownminio.sha256sum. Each run got a fresh database pair and a fresh MinIO data directory. MinIO's audit webhook recorded every S3 call.cd services/platform DATABASE_URL=… KNOWLEDGE_DATABASE_URL=… TALE_CONFIG_DIR=… TALE_CONFIG_BUILTIN_DIR=… \ ITEST_S3_ENDPOINT=http://127.0.0.1:59487 ITEST_S3_ACCESS_KEY=… ITEST_S3_SECRET_KEY=… \ ITEST_LANES=checkRejectedUploadReclaim bun run backend:integrationFails on
main+ the lane (8b916c0b9+d96d728bc): 17/23Passes on the head (
719ee861a): 22/23DeleteObjectcalls onmainand 13 on the head. The lane's own cleanup accounts for 11 in each run. So the backend's reclaim deleted 8 objects onmain(C1 and the seven held or raced refs) and 2 on the head (C1 and the reclaimed-then-attached ref).checkFiles,checkDocuments(which includes the existing "reject-blob reclaim (orphan deletes, bound refuses)" check),checkBlobRefAuthority,checkAbandonedUploadReclaim,checkTaskHeldBlobOutlivesFileRow,checkRejectedUploadReclaimandcheckDocumentWriteGuardsran on fresh databases:main+ lane: 69/76, the 5 lane failures above plus the same two the head has.bunx vitest runover the 40 test files of the files domain and of every test that imports the changed modules: 535/535.oxfmt --checkandoxlint --type-awareon the changed files: clean;tsc --noEmitover the changed files withintegration-check.ts: clean;tests/guards/integration-scopeandintegration-skipsguards: pass;bun run lint:manual,bun run knip:check: pass;tools/opengrep/run.sh) on the changed sources: 0 findings.CI at the exact head
f36e3adcb11b7cc44bce595a6df570ec21cc0e34: 50 pass, 12 skipped, 0 fail.checkRejectedUploadReclaimchecks.f36e3adcbis an emptychore:commit. The first run at719ee861a(run 37097165795) failed 1 of 1487 checks, an unrelated timing flake:checkRagWatchdogBatch's "a row lock held past the settle lock timeout defers that row alone" readlocked=failed.rag reconciletick (twofailed 2lines, 5 ms apart) failed the row as soon as the test released its lock.main's CI run 37085344227, locally on this head, and in the rerun.Checklist
bun run check: not run whole. The sandbox has a 4 GiB limit, so I ran the targeted gates above and leave the full set to CI.bun run lint:sast: Opengrep on the changed sources, 0 findings.reference/automation.mdrow for task-held blobs now names the reclaim, its tests and its lane.Out of scope
deleteOrgObjectalso clears the deployment default; this behaviour predates the change and is left unchanged here.