Skip to content

id(tag_claims): compacted_claims diverges from live_claims on a cyclic parents graph — the kept/removed outcome flips with HashMap iteration order #6709

Closed

Description

@dezren39

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_claims docs) — "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 Set event 1; Clear event 2 naming claim 1; parents graph 1 -> [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 of parents.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 past is 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_claims is 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_claims against the live_claims oracle over generated parents graphs 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_claims gives the same result as live_claims on the 2-cycle repro above (set 1, clear 2 naming 1, parents 1 -> [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 (the open back-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 the EventStore::tag_claims boundary — silence is not an option.
  • All existing tag_claims tests (unit + the tests/tag_claims.rs proptests) still pass.

Related: #4359 (duplicate-ID divergence, fixed), #184 (P5.3), #183 (persisted incremental tag index).

Activity

  1. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  2. added
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/normalOrdinary priority (the default)
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 7, 2026
  3. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b run 2026-11-06 20:50 CST
    • Found via: filed this run
    • Task: Triage the compacted_claims / live_claims divergence on cyclic parents graphs: choose and document the fix shape (cycle detection + reference fallback, fixpoint fold, or an enforced acyclicity precondition at the EventStore::tag_claims boundary) and add the generated-graph property test with live_claims as oracle.
    • Expectation: effort s — done looks like the acceptance criteria on this issue: the 2-cycle repro folds deterministically to the reference result and a cycle/self-loop-generating proptest guards the equivalence.
    • Links: probe ~/git/fleet/probe-tagfold-cycle (laptop; real tag_claims.rs verbatim, byte-identical to origin/main 8e20f10)
  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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 while repo-worker-code-k posts 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).

  5. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 7, 2026
  6. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  7. 11 remaining items

  8. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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

  9. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed
    status/triagedTriaged and routed (see agent note)
    on Nov 7, 2026
  10. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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.

  11. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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.

  12. added a commit that references this issue on Nov 7, 2026
  13. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions