Skip to content

Reject reparenting a collection member into an interior position (ADR-059 §2) - #1772

Merged
mstomar125 merged 1 commit into
mainfrom
issue-1765-reparent-membership-guard
Jul 28, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-1765-reparent-membership-guard

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

What

Adds the reparent side of the root-only content-membership rule (ADR-059 §2). #1742 enforces it at member_of write time; this closes the reverse transition — a node that already holds a member_of edge (a root member) being moved into an interior position, which would make it a forbidden interior member with no member_of write for the forward guard to catch.

How

The guard is enforced at the store's two has_child attach sites, symmetric with how #1742 enforced the forward direction at the store's member_of INSERT sites. Adversarial review confirmed these are the only two store paths that attach an existing node to a parent (the rest create fresh nodes or move already-interior ones), so gating both covers every reparent path by construction:

  • SqliteStore::move_node — the service NodeService::move_node (outline drag/indent) and NodeService::upsert_node_with_parent (the gRPC upsert / save_node_with_parent Tauri command; a distinct reparent path the first review caught bypassing a service-only guard).
  • SqliteStore::bulk_create_has_child — the sync-apply cold sweep (apply_cold_rel_sweep_batched), mirroring Enforce root-only content membership for member_of edges as a store-aware relationship validation #1742's guard on its sibling bulk_add_to_collections.

When a node's type is neither collection nor person and it holds one or more member_of edges, a move that would give it a has_child parent is rejected with an error naming the collections (a single chunked query on the bulk path).

  • Reject, not drop — a node can hold several member_of grants, each an independent access path; silently dropping them on an indent would revoke access with no record (Michael's decision on the issue's criterion 8).
  • Move to root stays allowed (new_parent = None) — the guard only fires when the node would gain a parent.
  • collection (nesting) and person (grantee, ADR-037 §4) exempt — matching the forward guard.

Adversarial review of the first (service-level) attempt found that upsert_node_with_parent bypassed a service-only guard; moving the check to the store chokepoint closes that and any future reparent surface.

Tests

  • Store test_reparent_guard_rejects_moving_a_member_under_a_parent: store.move_node rejects reparenting a member; non-member moves freely; move-to-root allowed; person exemption; and bulk_create_has_child rejects a member in a batch (cold-sweep parity).
  • Service test_reparenting_a_collection_member_is_rejected: rejection via both move_node and upsert_node_with_parent, proof the membership is not dropped (second attempt still rejects), move-to-root still allowed.

All core test targets green — 980 lib + integration + doctests, 0 failed. Reviewed adversarially three times: the passes caught the upsert_node_with_parent bypass and the bulk_create_has_child cold-sweep gap in turn, both now closed and tested. The sync side of the cold-sweep rejection (permanent-vs-transient classification, so a bad incoming edge can't wedge the cursor) is tracked in nodespace-sync#378.

Closes #1765

…-059 §2)

The store guard from #1742 enforces root-only content membership at member_of
write time; this adds the reparent side at the store's two has_child attach
sites, symmetric with the forward guard: SqliteStore::move_node (the service
move_node and upsert_node_with_parent reparent paths) and bulk_create_has_child
(the sync-apply cold sweep, mirroring bulk_add_to_collections). A node that holds
a member_of edge cannot gain a has_child parent — that would make it a forbidden
interior member with no member_of write to catch it. The move is rejected rather
than silently dropping the membership (a node can hold several member_of grants,
each an independent access path), with an error naming the collections. The bulk
check is one chunked query. Collection and person nodes are exempt; moving a
member to root stays allowed.

Closes #1765

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Store-level reparent guard verified through three independent adversarial reviews, each of which caught a real completeness gap and drove the enforcement to the correct layer:

  1. First attempt guarded the service move_node only → review found upsert_node_with_parent (gRPC / save_node_with_parent) reparents via store.move_node directly, bypassing it.
  2. Moved to the store SqliteStore::move_node chokepoint → review found bulk_create_has_child (the sync reconnect cold sweep) attaches existing roots without going through move_node, asymmetric with Enforce root-only content membership for member_of edges as a store-aware relationship validation #1742's guard on its sibling bulk_add_to_collections.
  3. Gated BOTH store attach sites via a batched assert_may_gain_parent. The third review's exhaustive enumeration confirms these are the ONLY two store paths that attach an existing node (the rest create fresh nodes or move already-interior ones), so coverage is complete.

980 lib + all integration + doctest targets green; clippy clean; pre-push gate (test:all + daemon build + e2e) green. Cold-sweep permanent-vs-transient handling tracked in nodespace-sync#378. Author=reviewer=mstomar125 self-approval per merge policy.

@mstomar125
mstomar125 merged commit fd5b417 into main Jul 28, 2026
2 checks passed
@mstomar125
mstomar125 deleted the issue-1765-reparent-membership-guard branch July 28, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject reparenting a node that holds a member_of edge into a non-root position (ADR-059 §2 criterion 8)

1 participant