Blob GC reference integrity: the fixes for the 2026-08-30 mail-body loss.
blob-gc is the only component that deletes blobs, and blobs are content-addressed
and shared, so one missed reference loses that content for every holder with no
undo. On 2026-08-30 a sweep deleted 17 blobs, two of which were still referenced.
An audit found eight gaps. This release fixes all of them.
blob_gc must stay "dryrun" until the candidate lists produced by this build have
been reviewed on real data. This release makes that review possible; it does not
authorise re-enabling deletion.
fix(agent): re-validate blob GC candidates immediately before deleting
The minAge grace assumed a blob's mtime tracks its most recent write, but
BlobStore.Put early-returns without touching the file when the hash already
exists. A deduplicated write therefore keeps the ORIGINAL mtime, so a blob that
becomes referenced again during the reference scan is simultaneously absent from
the snapshot, older than the cutoff, and a two-pass candidate. Both existing
guards miss it, and the stamped-message redelivery path makes it deterministic.
Candidates are now re-checked against a fresh reference set immediately before
deletion, inside deleteSweptBlobs so nothing can reach a delete without it.
fix(agent): count queued outbound attachments as referenced blobs
Attachment-dedup splits an outbound message into a skeleton plus separate
attachment blobs, which the queue worker reassembles before relaying. Only the
skeleton was referenced, so the GC reclaimed the attachments and the message
relayed with them missing. The queue entry stayed healthy throughout, so this
damaged outbound mail without leaving any evidence.
fix(agent): parse mail keys structurally, then fail loudly on bad records
The mail scan matched a "/mail/" substring, which a user could trip by creating
an IMAP mailbox named "mail". proto.Unmarshal failures were then silently
skipped, dropping references. Fixed in that order deliberately: making unmarshal
fatal first would have let any user disable the GC node-wide.
fix(agent): do not carry blob GC candidates across a failed pass
Both error paths returned the previous candidate set, so it survived an
arbitrary run of failed passes and "two consecutive passes" stopped meaning two
consecutive good ones.
fix(agent): scan the spool twice so a released message keeps its body
An admin releasing a message from quarantine moves it backward through the
directory order the scan reads, so a release landing mid-scan appeared in no
listing at all and its body looked unreferenced.
feat(agent): log every blob a sweep reclaims, with size and mtime
The incident left "candidates:17 deleted:17" and nothing else, so the hashes
were unrecoverable and attribution meant decoding spool envelopes by hand. Both
modes now log per-blob detail at Info: a deleting pass is the one whose record
cannot be reconstructed afterwards.
test(agent): fail when a blob-bearing proto field escapes the reference set
Twice a field that pins a blob was missing from the scan. A descriptor walk now
requires every blob-bearing proto field to be explicitly classified, so a third
recurrence fails the build instead of production.