Repository navigation
fix(platform): release orphaned mail bytes and guard the stamp clear - #3739
Merged
Merged
Conversation
The nightly stamp pass's second walk handed every stamped ref no emailed attachment backs to `releaseCorpusRefs`, which has no blob stage. A ref nothing references at all (an attachment deleted while its best-effort blob delete failed, a release job out of retries) lost its corpus row and kept its bytes, and once that row was gone nothing enumerated the ref again, since the blob walk lists corpus refs only. The walk now gets its own `releaseUnbacked`, wired to `releaseRefs`: corpus rows, bytes, and the trashed file row that only remembers them. The first walk keeps its corpus-only release. The kept set, and so the clear, is unchanged: corpus-live implies blob-live. The clear decided on app rows and wrote to the corpus, a database of its own, so a ref that turned back into an attachment in between (its document trashed or deleted, the file unfiled, a trashed file row restored) lost a correct stamp until the next night. The clear now returns the rows it hit, reads their backing again through the same statement, and gives every live attachment the first walk's stamp back; those no longer count as cleared. The stats keep each walk apart (`stampsScanned`, `unbackedReleased`, `unbackedFailures`): the attachments line no longer mixes in the second walk's releases, and the stale-stamps line reports what the second walk cleared, released and failed, naming the causes it actually has. The reconcile test that passed on the pre-#3668 code is replaced by ones that fail there and on main: the second walk's wired release deletes a dead ref's bytes and reaps its trashed file row, hands a kept ref back whole, and logs its failures. The emailed-attachments lane proves the bytes and the re-stamp on real Postgres.
This was referenced Sep 28, 2026
yannickmonney
added a commit
that referenced
this pull request
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #3668. The nightly mail-stamp pass now releases unbacked corpus rows through
releaseRefs, so orphaned bytes and trashed unbound file metadata are cleaned up too. Its first attachment walk retains corpus-only release, preserving bytes still referenced by a file. The logs and statistics distinguish the two walks.The clear pass rechecks app backing after clearing an obsolete conversation stamp. Clear and restamp commit in one corpus transaction: an attachment observed by the recheck keeps its mail scope, and another indexer cannot observe an intermediate NULL stamp. A newly dead/spam attachment is also restamped before its corpus release, which runs after the transaction commits. A failed release keeps the row isolated and is retried by the next pass.
Independent review reproduced why both guards matter: the original branch left a dead attachment NULL-stamped and the real content-hash indexer copied its private filename into an ordinary document's chunks. Restoring the stamp without a transaction still leaked that context to a concurrent indexer. The final regression runs that indexer during the clear, injects a corpus-release failure, and verifies the retained stamp, successful next-pass cleanup and preserved file bytes.
Validation:
No schema change. The existing shared release ordering still permits orphaned bytes if blob deletion fails after corpus deletion; this change logs such failures and does not add a bucket-wide sweep. Embedding responses and the release failure are local test fixtures; database, concurrent indexing and object storage are real. The app and corpus remain independent databases: an app binding or holding-document change that commits after the backing recheck is not fenced by this transaction, and may require the later indexing/reconciliation pass to repair its stamp. Closing every such transition requires a shared writer protocol or persistent donor provenance beyond this correction. Whole-repository CI must pass on the final pushed head before merge.