Repository navigation
fix(platform): keep bytes a pending mail or a chat message lists - #4157
Conversation
A queued reply names its attachments by blob ref in its metadata and a chat message names them in its parts, with no file row of their own, so neither blobRefHeld nor the release seam saw them. Deleting or purging the file row a reply attached took the bytes inside the undo window, and the send then could not find them; a chat thread lost the image every later turn replays from the ref. One list of the holders with no file row of their own, listedBlobRefHeld (a task, an outbound mail still queued or failed, a user's chat message, each scoped to the organization), is now asked by blobRefHeld and by the release seam's blob verdict, so the two cannot drift. A sent or delivered mail holds nothing, and a parked chat send is not a holder because it fires through the chat gate, which needs a live file row. No index serves the task or the chat arm, by decision: the measured cost (task 263 ms at 100k tasks, chat 0.5-0.6 s at 400k messages, mail 11 ms through the existing index) is documented at the predicate. Refs #4111
The rejected-upload reclaim refuses a ref whose only holder is a file row while the intent is still open and unstamped, and a consumed intent that nothing holds. Both conditions were pinned only by exact-SQL unit assertions; the real-Postgres lane now drives each one by itself. Refs #4111
The rejected-upload reclaim deleted the caller's intent in its claim and only logged when the store then refused the delete, so the bytes were orphaned with no record left to find them. The claim now tombstones the intent (expires_at_ms = 0): it proves nothing any more, so no bind can take the ref, and it stays the record that the bytes exist. The reclaim drops it once the store confirmed the delete; a failed delete leaves it to the abandoned-upload sweep, which takes it on the org's next mint and retries. Refs #4111
The outbound-mail route proved attachment ownership with the stamping proof on its own connection before the send, so every refusal after it (no connector, no contact address, the API app's reply limits, an unverified author) left the stamp behind. A stamped upload is never reclaimed, so a refused send left bytes nobody could take. The route now asks without a stamp, so a foreign file is still refused first, and the stamping proof runs in the transaction that writes the queued message (email reply, compose, API-channel reply). A refusal now rolls the stamp back with the message, and a reclaim racing the send waits on the intent row as it does for the task door. Refs #4111
The rejected-upload reclaim and the abandoned-upload sweep are race-safe because every door that binds a client-named ref stamps or consumes the intent row in the transaction that writes its holder: the claim waits on that lock and re-reads the row's own columns. The holder subqueries keep the statement's snapshot under READ COMMITTED, so a door that wrote a holder without touching the intent row would race the claim. The unit test's comment said the holders were read under the row's lock; it now says what holds. binding-doors.guard.test.ts enumerates every call of an intent proof on the syntax tree, with the handle it runs on and its kind (in the holder's transaction, an early refusal without a stamp, a bundle lane, a wrapper). A new call fails until it is listed, a stamping proof outside the holder's transaction fails, and the chat door must keep admitting a ref only through a live file row. Refs #4111
checkMessageHeldBlobs holds each email reply's undo window open for ten minutes, so the send jobs those replies scheduled were still waiting when the outbound send lane drained every conversation.send_message job, and its drain timed out (CI, Backend integration 1514/1515 at 37208ff). The lane now deletes its own jobs with its conversations; nothing was left for them to claim. Refs #4111
checkMessageHeldBlobs signed up its own admin and kept it, so later lanes that fan bells out to every owner and admin of the shared organization (an agent's ask escalates to them) also notified and emailed the probe. A lane counting the emails of that window then read one more than it expects (CI at de66a66: the notification email sink read 2 for 1, and the overdue email lane 3 for 2). The lane now removes its admin's membership with the rest of its rows; locally, that user no longer receives any bell in the following lanes. Refs #4111
|
Independent review of PR #4157 at Reviewer: root's separate Correctness and security assessed:
Independently read CI evidence:
Limits/residuals (not blockers):
Recommendation: the reviewed exact head is suitable for the repository's ordinary merge gate after root confirms head identity, latest required-check completion and current-main composition. No additional implementation change is requested by this review. |
|
Post-merge independent review of #4157 at
Runtime (mine; real PG 16.14 with moto S3, at the head):
MEDIUM 1: bytes kept for a mail or chat holder are never reconsidered when that holder ends, so they stay in the store forever.
MEDIUM 2 (privacy/compliance; needs an owner decision): any reader can keep a file's bytes alive past its owner's delete, a document's purge or a retention destruction.
LOW: INFO:
Verified correct:
Routing: this is merged, so both MEDIUMs are follow-up material for the manager. MEDIUM 2 needs root's retention decision. |
Follow-ups from agent #2's independent review of #4109 (record 5966032572), tracked as TALE-492. Every finding was re-checked on
main3a28bff12, after #4115 and #4129, and each one still held.What changed
metadata.attachments, and a chat message names them in its parts. Neither has a file row of its own, so neitherblobRefHeldnor the release seam (knowledge/liveness.ts) saw them.listedBlobRefHeldinfiles/blob-holders.ts. Each arm is scoped to the organization.blobRefHeldand the release seam'sblobLiveboth ask it, so the two can't drift.queuedorfailed(a retry re-sends it), on the email and the API channel alike.userrow with anattachmentpart.app.deferred_sends): it fires through the chat gate, which admits a ref only while its file row lives.upload-intents.test.tsnow says what holds: the intent row serializes the claim, and the holder subqueries keep the statement's snapshot.tests/guards/binding-doors.guard.test.tslists, on the syntax tree, every call of an intent proof (ownsUploadedBlob,firstForeignUpload,consumeUploadIntent,assertOwnedAttachments, the REST ledger's consume). Each entry names the handle the call runs on and its kind: in the holder's transaction, early refusal without a stamp, bundle lane, or wrapper. The guard fails when:claimRejectedUploadnow tombstones the intent (expires_at_ms = 0) instead of deleting it. A tombstoned intent proves nothing, so no bind can take the ref.releaseReclaimedIntent).listedBlobRefHeld; see the table below.stamp: false, so a foreign file is still refused first.conversations/attachment-ownership.ts). A refusal rolls the stamp back, and a reclaim racing the send waits on the intent row, as it does for the task door.Finding → commit → test
blobRefHeld+ release seam)d94f92d60checkMessageHeldBlobs, three checks:deleteFileand a purge each keep the bytes of an email reply, an API reply and a chat message; a sent reply holds nothing (the control). Units:files/blob-holders.test.tscovers both arms and the scope;knowledge/liveness.test.tscovers the release seam caller.a0c6c24a0checkRejectedUploadReclaim: "reject-blob refuses a ref only a file row holds, and a consumed intent nothing holds". A mutant whose claim dropsconsumed_at_ms IS NULLand the holder check flips both halves; output below.c0ba569e1checkRejectedUploadReclaim: "a reclaim whose delete failed leaves the bytes to the abandoned-upload sweep". Units:files/service.reject-blob.test.ts(tombstone kept on a store failure, dropped after success) andfiles/upload-intents.test.ts.e404cc583checkMessageHeldBlobs: "a refused send leaves no stamp, so its upload stays reclaimable". Units:conversations/attachment-ownership.test.ts,send.test.ts(proof on the transaction handle),routes.test.ts(stamp: false), andupload-intents.test.ts(no write without a stamp).f09352af8tests/guards/binding-doors.guard.test.ts. Mutants: droppingstamp: falseat the route fails "stamps or consumes in the holder's transaction"; a newfirstForeignUpload(sql, …)door fails three checks. Output below.d94f92d60Failing before, passing after
Each run used local real PostgreSQL 16.14 + pgvector on a fresh database, and a fresh moto S3 store.
main3a28bff12with only the lane files added: 4 failures, and every other check passes, including #4104's C1–C3 control.The INFO 2 check passes on
main, as expected: it adds coverage and changes no behaviour. The mutant shows that it pins each condition:Head
f09352af8: every holder lane passes. The lanes run werecheckFiles,checkRejectedUploadReclaim,checkMessageHeldBlobs,checkTaskHeldBlobOutlivesFileRow,checkVideoLinkHeldBlobs,checkProductImageReleaseHolders,checkTaskReleaseKeepsLaneRowsandcheckStagedBundlesUnnameable.The mail lanes
checkBlobRefAuthorityandcheckConversationApipass at the head. That includes "outbound mail attaches only the sender's uploads": a foreign file is still refused with 403ATTACHMENT_NOT_OWNEDbefore the contact is looked up.Environmental failures, also present on
mainlocally:pg_searchhere.checkFilesblobGone=false: the moto delete quirk.checkOutboundSendLanechecks: the local job wait. They fail the same way onmain3a28bff12+ lanes.Other local checks:
@tale/sharedresolving to an older checkout through the sharednode_moduleshere (toolCallingApi, fix(platform): enable Sol 6.1 through OpenAI subscriptions #4149). It isn't touched by this change.tscon the changed files and their imports: 0 errors, with@tale/sharedmapped to this tree.INFO 4: measured cost, no index (decision)
These numbers come from synthetic data on PostgreSQL 16: one organization beside ten others, querying a ref nothing holds, which is the worst case.
(org_id, delivery_state, …)64326462on TALE-492 chose correctness without a migration in this PR.listedBlobRefHeld.Docs
No user-visible string changes, so there's nothing to translate.
docs/{en,de,fr}/platform/chat/attachments.mdalready says "A regenerated reply uses the original message's stored attachments". That is now true even after the file is deleted elsewhere.tests/manual/reference/automation.mdnames the new holders and the new lane.Since the first push
37208ff32mergesmainaa2e73974without a force-push.integration-check.tsmerged cleanly: test(platform): keep the RAG sweep's clock off the watchdog lanes #4145'slaneDrivenSchedulesstays, plus this PR's one lane entry.tscreports 0 errors.CI at
37208ff32: Backend integration reported 1514/1515 across 224/224 lanes, and the one failure was caused by this PR.outbound send lane (reply/compose/undo/retry/discard + undo-window job), withdrained=false.checkMessageHeldBlobsholds each email reply's undo window open for ten minutes. The send jobs those replies scheduled were stillcreatedwhen the outbound send lane later drained everyconversation.send_messagejob. The local database showed exactly 3 such jobs after the lane.de66a66b0makes the lane delete its own jobs together with its conversations. Locally:conversation.send_messagejob is left after the lane;checkMessageHeldBlobsfollowed bycheckOutboundSendLane, the drain readsdrained=true. That lane'ssent=falseis the local environment issue: it fails the same way onmainhere.CI at
de66a66b0: Backend integration reported 1513/1515. The outbound send lane now passed, but the notification email sink read 2 emails for 1, and the overdue email lane read 3 for 2.agent_escalationbells in the lanes after it.089fe9426makes the lane remove its admin's membership with the rest of its rows. In a local run of the lanes fromcheckMessageHeldBlobsup to the sink, that user receives no bell, and the lane's own checks still pass.Left open
ON app.messages (org_id) WHERE role = 'user' AND parts @> '[{"type":"attachment"}]', or a GIN index for the task arm.CREATE INDEX CONCURRENTLYisn't available through the migration runner, because each migration runs in one transaction (see 0136's note). Such an index would be a plain build that write-locksapp.messageswhile it runs, so it's a measured follow-up only.deleteFileracing a bind that commits within the same milliseconds still decides on its own snapshot. That is pre-existing for every holder, and the lanes here cover committed holders.Closes #4111