From d80da2fde27cdbd88edfc29f5c3e1bba5920fe85 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Fri, 20 Nov 2026 13:15:26 -0700 Subject: [PATCH] Spam samples: ending a hold early removes the sample too (UD-14a) Since #500, a spam-training sample's hold on a message's blob ends with the account's own copy: release() clears the sample's temporary link. The blob purge is what removes a SpamTrainingSample, and it finds one only through that link's value once the link expires. With the link cleared early, nothing found the sample again, so its registry item and account index stayed behind for good, past the account's deletion. release() now reads the sample's id from the link before clearing it, and removes the registry item and its index in the same write. The system suite's account purge test caught it ("Store is not empty": a leftover SpamTrainingSample). --- crates/features/src/undelete/samples.rs | 47 +++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/crates/features/src/undelete/samples.rs b/crates/features/src/undelete/samples.rs index 307fd8cd..69fa8243 100644 --- a/crates/features/src/undelete/samples.rs +++ b/crates/features/src/undelete/samples.rs @@ -23,10 +23,18 @@ //! Each hold is noted as `s` + account + blob hash + until (empty value), so //! it can be found from the message, with the link it set under that //! account. +//! +//! Ending a hold early also removes its `SpamTrainingSample`. The blob purge +//! is what normally removes one: it finds the sample's id in the expired +//! link. Once the link is cleared here, nothing would find it again. +use registry::{ + schema::prelude::{ObjectType, Property}, + types::{EnumImpl, id::ObjectId}, +}; use store::{ - IterateParams, SUBSPACE_UNDELETE, Store, ValueKey, - write::{AnyClass, BatchBuilder, BlobLink, BlobOp, ValueClass, now}, + IterateParams, SUBSPACE_UNDELETE, SerializeInfallible, Store, ValueKey, + write::{AnyClass, BatchBuilder, BlobLink, BlobOp, RegistryClass, ValueClass, now}, }; use trc::AddContext; use types::blob_hash::{BLOB_HASH_LEN, BlobHash}; @@ -82,11 +90,38 @@ pub async fn release(data: &Store, account_id: u32, hash: &BlobHash) -> trc::Res let mut batch = BatchBuilder::new(); batch.with_account_id(account_id); for until in untils { - batch - .clear(BlobOp::Link { - hash: hash.clone(), - to: BlobLink::Temporary { until }, + let link = BlobOp::Link { + hash: hash.clone(), + to: BlobLink::Temporary { until }, + }; + // The link's value is the sample's id: its registry entry goes too + let sample = data + .get_value::(ValueKey { + account_id, + collection: 0, + document_id: 0, + class: ValueClass::Blob(link.clone()), }) + .await + .caused_by(trc::location!())? + .filter(|id| id.object() == ObjectType::SpamTrainingSample); + if let Some(sample) = sample { + let object_id = ObjectType::SpamTrainingSample.to_id(); + let item_id = sample.id().id(); + batch + .clear(ValueClass::Registry(RegistryClass::Index { + index_id: Property::AccountId.to_id(), + object_id, + item_id, + key: (account_id as u64).serialize(), + })) + .clear(ValueClass::Registry(RegistryClass::Item { + object_id, + item_id, + })); + } + batch + .clear(link) .clear(class(account_id, hash.as_slice(), until)); } data.write(batch.build_all()) -- 2.54.0