Skip to content

fix(platform): release orphaned mail bytes and guard the stamp clear - #3739

Merged
yannickmonney merged 3 commits into
mainfrom
fix/mail-stamp-pass-orphans-race-logs
Sep 28, 2026
Merged

yannickmonney merged 3 commits into
mainfrom
fix/mail-stamp-pass-orphans-race-logs

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • 360 area tests across 30 files; 32 focused stamp/reconciliation tests; full platform typecheck and scoped type-aware lint.
  • Real PostgreSQL with pg_search and a fresh working MinIO: the initial branch passed all 47 checks across files, provider credentials, corpus purge and emailed attachments. The corrected mail/files run passes 35/35, including the new concurrent clone and failed-release retry proof. Both the original defect and a deliberately non-atomic correction fail that regression (34/35).
  • Manual automation register, formatting and diff checks passed; scoped SAST ran 162 rules with no findings.

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.

yannickmonney and others added 3 commits September 28, 2026 18:16
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.
@yannickmonney
yannickmonney merged commit d15477b into main Sep 28, 2026
57 of 58 checks passed
@yannickmonney
yannickmonney deleted the fix/mail-stamp-pass-orphans-race-logs branch September 28, 2026 20:42
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