From 2ca29f0b01b862004dedd1c957860d22549a0174 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 22:58:44 +0000 Subject: [PATCH] id-sync(B02): bounded revocation sweeps stop at the interval's end apply_revocation swept previously accepted records using only effective_from, so a bounded suspension learned late quarantined or flagged records admitted at or after its exclusive effective_until. The sweep now leaves those records alone, matching RevocationRecord::covers. The reference model in the B02 test follows the same boundary, and a regression admits records before, inside, at and after the interval before applying the suspension. Refs #11955 Co-Authored-By: Claude Opus 5.5 --- .../federation/slices/b02_key_revocation.rs | 7 ++ .../id/crates/id-sync/tests/federation_b02.rs | 66 +++++++++++++++++-- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/pkgs/id/crates/id-sync/src/federation/slices/b02_key_revocation.rs b/pkgs/id/crates/id-sync/src/federation/slices/b02_key_revocation.rs index ba346a786e..a1db377eaf 100644 --- a/pkgs/id/crates/id-sync/src/federation/slices/b02_key_revocation.rs +++ b/pkgs/id/crates/id-sync/src/federation/slices/b02_key_revocation.rs @@ -506,6 +506,7 @@ impl RevocationRegistry { } let recorded_at = record.recorded_at; let from = record.effective_from; + let until = record.effective_until; let subject = record.subject.clone(); self.revocations.push(record); let mut affected = Vec::new(); @@ -513,6 +514,12 @@ impl RevocationRegistry { if !subject_matches(&subject, &rec.key, &rec.peer_id) { continue; } + // A bounded interval ends at its exclusive `until`: a record + // admitted then or later was admitted after the revocation + // stopped applying, so the sweep leaves it alone. + if until.is_some_and(|until| rec.admitted_at >= until) { + continue; + } let escalate = matches!(rec.status, RecordStatus::Flagged { .. }) && rec.admitted_at >= from; if !matches!(rec.status, RecordStatus::Accepted) && !escalate { diff --git a/pkgs/id/crates/id-sync/tests/federation_b02.rs b/pkgs/id/crates/id-sync/tests/federation_b02.rs index 47f2206a6b..fe08550a4e 100644 --- a/pkgs/id/crates/id-sync/tests/federation_b02.rs +++ b/pkgs/id/crates/id-sync/tests/federation_b02.rs @@ -91,9 +91,10 @@ fn ref_peer_tag(peer: &str) -> String { } impl RefModel { - fn sweep(&mut self, tag: &str, by_key: bool, from: u64) { + fn sweep(&mut self, tag: &str, by_key: bool, from: u64, until: Option) { for (ktag, ptag, admitted_at, verdict) in self.records.values_mut() { - let hit = if by_key { ktag == tag } else { ptag == tag }; + let after_end = until.is_some_and(|u| *admitted_at >= u); + let hit = !after_end && if by_key { ktag == tag } else { ptag == tag }; let escalate = *verdict == RefVerdict::FlaggedIndeterminate && *admitted_at >= from; if hit && (*verdict == RefVerdict::AcceptedValid || escalate) { *verdict = if *admitted_at >= from { @@ -111,7 +112,7 @@ impl RefModel { .entry(tag.clone()) .or_default() .push((from, until)); - self.sweep(&tag, true, from); + self.sweep(&tag, true, from, until); } fn revoke_peer(&mut self, peer: &str, from: u64, until: Option) { @@ -120,7 +121,7 @@ impl RefModel { .entry(tag.clone()) .or_default() .push((from, until)); - self.sweep(&tag, false, from); + self.sweep(&tag, false, from, until); } fn blocked( @@ -682,6 +683,63 @@ fn bounded_interval_blocks_only_inside_and_quarantine_is_sticky() { )); } +#[test] +fn late_bounded_revocation_sweeps_only_records_admitted_inside_it() { + let (_ska, key_a) = keypair([3u8; 32]); + let mut reg = RevocationRegistry::new(); + admit(&mut reg, "before", key_a, "peer-1", 100, None); + admit(&mut reg, "inside", key_a, "peer-1", 250, None); + admit(&mut reg, "at-end", key_a, "peer-1", 300, None); + admit(&mut reg, "after", key_a, "peer-1", 400, None); + + // The suspension is learned only after every admission. + let affected = reg + .apply_revocation(RevocationRecord { + record_id: "late-suspension".to_string(), + subject: RevocationSubject::Key(key_a), + effective_from: 200, + effective_until: Some(300), + reason: RevocationReason::AdministrativeDisable, + recorded_at: 500, + }) + .expect("bounded revocation must apply"); + assert_eq!(affected, vec!["before".to_string(), "inside".to_string()]); + assert!(matches!( + status_of(®, "before"), + RecordStatus::Flagged { .. } + )); + assert!(matches!( + status_of(®, "inside"), + RecordStatus::Quarantined { .. } + )); + assert_eq!(status_of(®, "at-end"), RecordStatus::Accepted); + assert_eq!(status_of(®, "after"), RecordStatus::Accepted); + + // A later unbounded revocation still reaches the post-interval + // records, and the earlier quarantine stays. + reg.apply_revocation(RevocationRecord { + record_id: "compromise".to_string(), + subject: RevocationSubject::Key(key_a), + effective_from: 350, + effective_until: None, + reason: RevocationReason::KeyCompromise, + recorded_at: 600, + }) + .expect("unbounded revocation must apply"); + assert!(matches!( + status_of(®, "inside"), + RecordStatus::Quarantined { .. } + )); + assert!(matches!( + status_of(®, "at-end"), + RecordStatus::Flagged { .. } + )); + assert!(matches!( + status_of(®, "after"), + RecordStatus::Quarantined { .. } + )); +} + #[test] fn malformed_revocation_and_admission_inputs_are_rejected() { let (_ska, key_a) = keypair([3u8; 32]);