From a5375daaee72bc143299d13a9b1d4e5233993a7c Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 12:05:17 -0600 Subject: [PATCH 1/2] fix(id): ignore supersedes edges from superseded attestations in compose_view (#4003) --- pkgs/id/src/boards.rs | 126 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 9 deletions(-) diff --git a/pkgs/id/src/boards.rs b/pkgs/id/src/boards.rs index 58c909fbe6..67e4fee860 100644 --- a/pkgs/id/src/boards.rs +++ b/pkgs/id/src/boards.rs @@ -1216,17 +1216,43 @@ impl BoardGraph { // Current moderator frontier: a role attestation that another // attestation supersedes is history, not authority. Following // the signed supersedes links (never arrival order) keeps this - // identical on every peer holding the same set. - let mut attestation_superseded: BTreeSet = BTreeSet::new(); - for signed in self.objects.values() { - if let BoardObject::RoleAttestation(value) = &signed.object { - if &value.board == board { - if let Some(previous) = &value.supersedes { - attestation_superseded.insert(previous.clone()); - } + // identical on every peer holding the same set. An attestation + // that is itself superseded — by an active generic supersede + // above, or by an active attestation's supersedes edge — has no + // effect, so its own supersedes edge does not apply either + // (#4003): superseding a revocation reinstates the grant it + // revoked. Like the generic frontier, this resolves to a fixed + // point over the active attestations. + let attestation_edges: Vec<(ArtifactHash, Option)> = self + .objects + .iter() + .filter_map(|(hash, signed)| match &signed.object { + BoardObject::RoleAttestation(value) if &value.board == board => { + Some((hash.clone(), value.supersedes.clone())) } + _ => None, + }) + .collect(); + let mut active_attestations: BTreeSet = attestation_edges + .iter() + .map(|(hash, _)| hash.clone()) + .filter(|hash| !superseded.contains(hash)) + .collect(); + let attestation_superseded: BTreeSet = loop { + let named: BTreeSet = attestation_edges + .iter() + .filter(|(hash, _)| active_attestations.contains(hash)) + .filter_map(|(_, previous)| previous.clone()) + .collect(); + let next: BTreeSet = active_attestations + .difference(&named) + .cloned() + .collect(); + if next == active_attestations { + break named; } - } + active_attestations = next; + }; let current_moderators: BTreeSet = self .objects .iter() @@ -2421,6 +2447,88 @@ mod tests { assert_eq!(view.moderation_log.len(), 1); } + #[test] + fn superseded_revocation_no_longer_revokes() { + // #4003: a revocation attestation that is itself superseded has + // no effect, so the grant it revoked is authority again. + let owner = key(41); + let moderator = key(42); + let author = key(43); + let other = key(44); + let moderator_key = hex_encode(&moderator.verifying_key().to_bytes()); + let mut graph = BoardGraph::default(); + let root_hash = graph.insert(board(&owner)).unwrap(); + let thread_hash = graph.insert(thread(&owner, root_hash.clone(), "General")).unwrap(); + let post_hash = graph + .insert(post(&author, root_hash.clone(), thread_hash, "hello")) + .unwrap(); + let attestation = |seq: u64, member: String, granted: bool, supersedes: Option| { + SignedBoardObject::sign( + &owner, + seq, + "", + BoardObject::RoleAttestation(RoleAttestation { + board: root_hash.clone(), + member, + role: BoardRole::Moderator, + granted, + supersedes, + }), + ) + .unwrap() + }; + let grant_hash = graph + .insert(attestation(2, moderator_key.clone(), true, None)) + .unwrap(); + graph + .insert(moderation( + &moderator, + 1, + root_hash.clone(), + post_hash.clone(), + ModerationActionKind::Hide, + Some("spam"), + )) + .unwrap(); + let view = graph.compose_view(&root_hash, &ViewLayers::default()).unwrap(); + assert_eq!(view.hidden.len(), 1); + + // Revoke: the moderator's Hide stops applying. + let revocation_hash = graph + .insert(attestation(3, moderator_key.clone(), false, Some(grant_hash.clone()))) + .unwrap(); + let view = graph.compose_view(&root_hash, &ViewLayers::default()).unwrap(); + assert!(view.objects.contains(&post_hash)); + assert!(view.hidden.is_empty()); + + // Nullify the revocation with a generic Supersede whose + // replacement is an unrelated attestation: the original grant + // is the current frontier again and the Hide applies once more. + let other_grant_hash = graph + .insert(attestation( + 4, + hex_encode(&other.verifying_key().to_bytes()), + true, + None, + )) + .unwrap(); + let supersede = SignedBoardObject::sign( + &owner, + 5, + "", + BoardObject::Supersede(Supersede { + board: root_hash.clone(), + previous: revocation_hash, + replacement: other_grant_hash, + }), + ) + .unwrap(); + graph.insert(supersede).unwrap(); + let view = graph.compose_view(&root_hash, &ViewLayers::default()).unwrap(); + assert_eq!(view.hidden.len(), 1); + assert!(!view.objects.contains(&post_hash)); + } + #[test] fn superseded_supersede_record_has_no_effect() { let owner = key(39); From f78d780023525a14cbe99be81dd35f6228d0caf1 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 12:11:44 -0600 Subject: [PATCH 2/2] fix(id): recompute attestation frontier from eligible set so chains reactivate (#4003) --- pkgs/id/src/boards.rs | 112 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 14 deletions(-) diff --git a/pkgs/id/src/boards.rs b/pkgs/id/src/boards.rs index 67e4fee860..6dc374157d 100644 --- a/pkgs/id/src/boards.rs +++ b/pkgs/id/src/boards.rs @@ -1233,25 +1233,39 @@ impl BoardGraph { _ => None, }) .collect(); - let mut active_attestations: BTreeSet = attestation_edges + let eligible_attestations: BTreeSet = attestation_edges .iter() .map(|(hash, _)| hash.clone()) .filter(|hash| !superseded.contains(hash)) .collect(); - let attestation_superseded: BTreeSet = loop { - let named: BTreeSet = attestation_edges - .iter() - .filter(|(hash, _)| active_attestations.contains(hash)) - .filter_map(|(_, previous)| previous.clone()) - .collect(); - let next: BTreeSet = active_attestations - .difference(&named) - .cloned() - .collect(); - if next == active_attestations { - break named; + // Recompute the active set from the eligible set on every pass, + // never by only shrinking the previous pass: in a chain + // grant -> revocation -> grant -> revocation, the middle + // revocation must reactivate once the grant superseding it is + // itself superseded, and a shrinking-only loop can never bring + // it back (Codex P1 on PR #4512). Supersedes edges always name + // an already-inserted record, so the graph is acyclic and this + // settles within one pass per chain link; the pass cap only + // bounds a graph that somehow broke that rule. + let mut active_attestations: BTreeSet = eligible_attestations.clone(); + let attestation_superseded: BTreeSet = { + let mut named: BTreeSet = BTreeSet::new(); + for _ in 0..=attestation_edges.len() { + named = attestation_edges + .iter() + .filter(|(hash, _)| active_attestations.contains(hash)) + .filter_map(|(_, previous)| previous.clone()) + .collect(); + let next: BTreeSet = eligible_attestations + .difference(&named) + .cloned() + .collect(); + if next == active_attestations { + break; + } + active_attestations = next; } - active_attestations = next; + named }; let current_moderators: BTreeSet = self .objects @@ -2529,6 +2543,76 @@ mod tests { assert!(!view.objects.contains(&post_hash)); } + #[test] + fn attestation_chain_frontier_reinstates_and_re_revokes() { + // Chain grant -> revocation -> grant -> revocation, each + // attestation superseding its predecessor: only the last + // revocation is the frontier, the first revocation reactivates + // once the second grant falls, and the first grant stays + // revoked (Codex P1 on PR #4512). + let owner = key(45); + let moderator = key(46); + let author = key(47); + let moderator_key = hex_encode(&moderator.verifying_key().to_bytes()); + let mut graph = BoardGraph::default(); + let root_hash = graph.insert(board(&owner)).unwrap(); + let thread_hash = graph.insert(thread(&owner, root_hash.clone(), "General")).unwrap(); + let post_hash = graph + .insert(post(&author, root_hash.clone(), thread_hash, "hello")) + .unwrap(); + let attestation = |seq: u64, granted: bool, supersedes: Option| { + SignedBoardObject::sign( + &owner, + seq, + "", + BoardObject::RoleAttestation(RoleAttestation { + board: root_hash.clone(), + member: moderator_key.clone(), + role: BoardRole::Moderator, + granted, + supersedes, + }), + ) + .unwrap() + }; + let first_grant = graph.insert(attestation(2, true, None)).unwrap(); + graph + .insert(moderation( + &moderator, + 1, + root_hash.clone(), + post_hash.clone(), + ModerationActionKind::Hide, + Some("spam"), + )) + .unwrap(); + let hidden = |graph: &BoardGraph| { + graph + .compose_view(&root_hash, &ViewLayers::default()) + .unwrap() + .hidden + .len() + }; + assert_eq!(hidden(&graph), 1); + + let first_revocation = graph + .insert(attestation(3, false, Some(first_grant))) + .unwrap(); + assert_eq!(hidden(&graph), 0); + + let second_grant = graph + .insert(attestation(4, true, Some(first_revocation))) + .unwrap(); + assert_eq!(hidden(&graph), 1); + + graph + .insert(attestation(5, false, Some(second_grant))) + .unwrap(); + assert_eq!(hidden(&graph), 0); + let view = graph.compose_view(&root_hash, &ViewLayers::default()).unwrap(); + assert!(view.objects.contains(&post_hash)); + } + #[test] fn superseded_supersede_record_has_no_effect() { let owner = key(39);