Skip to content

assert_root_only_membership and its _in_tx twin have silently diverged on the collection-type exemption #2977

Closed

Description

@mstomar125

Problem

No current user-facing or functional impact exists (two independent DB triggers make the divergent branch unreachable today), but it is a real, git-history-confirmed maintenance hazard: the last person to touch this code already believed — incorrectly, per their own commit message — that they'd fixed both twins.

Root cause

assert_root_only_membership (packages/core/src/db/sqlite_store/relationships.rs:478) reads has_parent != 0 && node_type != "person"; assert_root_only_membership_in_tx (line 528) reads has_parent != 0 && node_type != "collection" && node_type != "person" — an extra clause the non-tx sibling lacks. Commit be5a7d270 ("Enforce that a collection is always a root") deliberately removed the collection exemption from the non-tx function, with a commit message stating explicitly "the collection exemption in both root-only membership guards is gone" — but the diff never touched the _in_tx twin, which still has it. Two DB triggers (collection_is_root_edge, collection_is_root_type) currently make has_parent structurally always 0 for a collection, so the divergence is inert today — but it's a proven authoring hazard, not a hypothetical one.

Suggested fix

Remove the leftover node_type != "collection" clause from assert_root_only_membership_in_tx to match the non-tx twin, and add a shared macro/helper so this pair (and other _in_tx twins in this codebase) can't silently diverge again.


Found via the 2026-09-25 full-repo code sweep (finding #31 of 84 in CODE_SWEEP_FINDINGS_2026-09-25.md). Severity: medium. Category: duplicate.

Activity

  1. self-assigned this
    on Sep 25, 2026
  2. added
    sweepFound via the 2026-09-25 full-repo code sweep
    on Sep 25, 2026
  3. removed their assignment
    on Sep 25, 2026
  4. malibio commented on Sep 26, 2026

    @malibio
    Collaborator

    Frontend: 277 files / 5392 tests passed

  5. self-assigned this
    on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

foundationsweepFound via the 2026-09-25 full-repo code sweep

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions