Repository navigation
Description
Problem
compacted_claims (the production fold behind the default tag view) does not always agree with the reference fold live_claims — on a cyclic parents graph it keeps a claim the reference removes, and which answer it gives flips with HashMap iteration order, so the same input yields different live-claim sets in different processes.
The module documents the equivalence as unconditional:
pkgs/id/src/tag_claims.rs:19-24— "Two folds give the live claims. [live_claims] walks the causal past of each clear. It is the reference. [compacted_claims] makes one pass over the parent links … Both give the same result (P5.3, Phase 5: compaction for tag clears #184)."pkgs/id/src/tag_claims.rs:243-247(compacted_claimsdocs) — "The result is the same as [live_claims] …"
No acyclicity precondition is stated or checked anywhere.
Verified reproduction (this run, origin/main 8e20f10f93; tag_claims.rs sha256 a1590882…)
Probe on the laptop at ~/git/fleet/probe-tagfold-cycle — the real tag_claims.rs copied verbatim (byte-identical sha256 to origin/main), plus a minimal p2panda_core::Hash shim covering only the API the file uses:
- Input: claim
Setevent 1;Clearevent 2 naming claim 1; parents graph1 -> [2],2 -> [1](a 2-cycle). live_claims(the reference): the clear's causal past is the transitive closure (causal_past,tag_claims.rs:169-181), which contains claim 1 through the cycle → the claim is removed. Result: 0 claims, every run.compacted_claims: acyclic control (2 -> [1],1 -> []) agrees (0 claims). On the 2-cycle, across 12 fresh processes it kept the claim in 5 processes (64/64 calls each) and removed it in 7 — the outcome is decided by the iteration order ofparents.keys().
Mechanism
compacted_claims folds depth-first from each root in parents.keys() order (tag_claims.rs:255). The open set (tag_claims.rs:266-269) silently drops a back-edge into an ancestor that is still being folded. Whichever of the set/clear pair folds second decides the result:
- Clear folds first: its
pastis built only from already-folded parents (tag_claims.rs:281-285), the set is not in any folded parent's set yet, so the clear removes nothing (tag_claims.rs:287-289); the set then inserts itself (tag_claims.rs:290-292) and survives. - Set folds first: the clear sees it and removes it.
live_claims has no such order dependence because it computes each clear's past as a full transitive closure.
Reachability, stated honestly
From today's store this input does not arise: an event's ID is Hash::digest of its whole signed bytes (pkgs/id/src/chain.rs:423), and its parents are named inside those bytes, so a parents cycle would require a BLAKE3 hash cycle. The production caller is EventStore::tag_claims → compacted_claims (pkgs/id/src/event_store/claims.rs:87), fed by stored events and fork proof headers.
That makes this a contract/robustness defect, not a live exploit: the two folds are public pure functions whose documented equivalence is false as stated, the production fold's answer on out-of-contract input is nondeterministic (process-to-process), and nothing detects the out-of-contract input. #4359 already hardened these exact folds against adversarial duplicate-ID inputs for the same reason — the folds are expected to be robust on adversarial applied/parents values, not only on honest-store ones. The existing equivalence proptest (pkgs/id/tests/tag_claims.rs:484-518, test_the_compacted_fold_agrees_with_the_causal_walk) cannot find this: its generator builds histories from real signed events, whose parents graphs are DAGs by construction.
Why it matters
- The default tag view (
tag_claims()/tag_index()) is only as trustworthy as the fold-equivalence contract; a silent, nondeterministic divergence class undermines the P5.3 design claim the rest of Phase 5 builds on (e.g. the persisted incremental index, Phase 5: persisted incremental tag index #183, will bake in whichever answer the fold gives). - Per the repo's testing doctrine,
live_claimsis a ready-made oracle: the invariant "both folds agree" should be property-tested over generated graphs — including cycles, self-loops, and duplicate IDs — not only over well-formed causal histories.
Acceptance criteria
- A property test compares
compacted_claimsagainst thelive_claimsoracle over generatedparentsgraphs that include cycles and self-loops (plus the duplicate-ID shapes from id(tag_claims): compacted_claims returns a claim twice when the applied list repeats an ID — the production fold diverges from live_claims on duplicate input #4359), and either passes or is the failing test this fix closes. -
compacted_claimsgives the same result aslive_claimson the 2-cycle repro above (set 1, clear 2 naming 1, parents1 -> [2],2 -> [1]→ claim removed), deterministically across repeated runs/processes. - The fix shape is chosen explicitly and documented in
tag_claims.rs: e.g. detect a cycle during the walk (theopenback-edge case) and fall back to the reference computation for the affected component, fold to a fixpoint, or refuse/document the precondition and enforce it at theEventStore::tag_claimsboundary — silence is not an option. - All existing
tag_claimstests (unit + thetests/tag_claims.rsproptests) still pass.
Related: #4359 (duplicate-ID divergence, fixed), #184 (P5.3), #183 (persisted incremental tag index).
Activity
developing-today commentedon Nov 7, 2026
CODE-2077
dezren39 commentedon Nov 7, 2026
🤖 Agent note · filed
~/git/fleet/probe-tagfold-cycle(laptop; real tag_claims.rs verbatim, byte-identical to origin/main 8e20f10)dezren39 commentedon Nov 7, 2026
Picked up by
repo-worker-code-k— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-kposts progress markers; after 30 minutes of silence any other worker may pick this up.)Lane K triage: verifying the compacted_claims vs live_claims cyclic-parents divergence against current main (tag_claims.rs docs, fold mechanism, proptest generator shape).
dezren39 commentedon Nov 7, 2026
🤖 Agent note · picked up
repo-worker-code-k(issue id(tag_claims): compacted_claims diverges from live_claims on a cyclic parents graph — the kept/removed outcome flips with HashMap iteration order #6709 is the task in fallback mode)compacted_claimsdiverges fromlive_claimson a cyclicparentsgraph (order-dependent kept/removed outcome) inpkgs/id/src/tag_claims.rs, against current main: the unconditional-equivalence docs, the DFS/open-set mechanism, the reference fold's transitive closure, and the equivalence proptest's generator shape.task/small-fix+queue/queued), or an already-fixed verdict with evidence.11 remaining items
dezren39 commentedon Nov 7, 2026
Picked up by repo-worker-code-t (Lane T, fallback mode — queue backend down, fleet queue health 503 PostgREST PGRST002). Small-fix for #6709: making compacted_claims agree deterministically with the live_claims oracle on cyclic parents graphs, with property coverage for cycles/self-loops.
🤖 Agent note · picked up
dezren39 commentedon Nov 7, 2026
Heartbeat: implementation in progress on laptop worktree ~/git/fleet/fb-6709-tagfold (branch fallback/6709-tagfold-cycle) — fix shape chosen and documented in tag_claims.rs: parents_have_cycle (iterative three-color DFS) detects a cycle up front and compacted_claims falls back to the live_claims reference for the whole input (equivalence by construction, deterministic; cycles cannot arise from the store, so the fast path is unchanged for honest inputs). Tests added: the 2-cycle repro, self-loops, and a 2000-case generated-graph property test with live_claims as oracle. Next: run the tag_claims suites.
dezren39 commentedon Nov 7, 2026
Heartbeat: targeted_tests_passed on laptop worktree ~/git/fleet/fb-6709-tagfold (branch fallback/6709-tagfold-cycle) — cargo test --lib tag_claims: 13 passed (incl. the 2-cycle repro, self-loops, and the 2000-case generated-graph property test); cargo test --test tag_claims: 12 passed (existing signed-history proptests green); cargo fmt --check clean. Next: push + PR.
Merge pull request #6736 from developing-today/fallback/6709-tagfold-…
dezren39 commentedon Nov 7, 2026
Released by repo-worker-code-t (Lane T, fallback mode) — DONE. Fix landed and merged: PR #6736 (#6736); this issue auto-closed via
Fixes #6709. Verification on the laptop worktree: cargo test --lib tag_claims 13 passed (2-cycle repro, self-loops, 2000-case generated-graph property test with live_claims as oracle), cargo test --test tag_claims 12 passed, cargo fmt --check clean. Codex review on PR #6736 completed with no findings. Outcome: fixed_merged; ci: PR checks queued at merge (standing merge authority — CI runs on main), Codex clean.