Repository navigation
Exclude and re-root a descendant whose access differs from its embedding root's (#2895) - #2903
Conversation
…ing root's (closes #2895) ADR-059 §7's defect path. Root-only membership keeps access boundaries out of embedding aggregates by construction; when that is bypassed, aggregation now leaves the boundary descendant and its subtree out of the root's vector, logs the violation at error level naming both ids, and the descendant becomes its own embedding root. - SqliteStore::access_boundary / access_boundaries_under / embedding_root_id (new embedding_roots module): the nearest restricted collections reached from a node's own classification, compared against its embedding root's - NodeAccessor::access_boundaries_under drives the exclusion in the shared aggregation walk - get_embedding_root_id, the spawned-task walk, NodeEmbeddingService queueing, bulk create and delete all resolve through embedding_root_id - refresh_for_rootness keeps a re-rooted descendant's embedding - embed_root_node queues boundary descendants that have no embedding yet Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CbMVLf7z8mBEgn2xPsNLcB
Pragmatic Code Review: PR #2903Review Type: Initial Review (the PR has no earlier reviews or comments) SummaryThis PR adds the ADR-059 §7 defect path. It is a clear improvement. The access check lives in one place, the new I checked the boundary logic hardest, since this is an access-leak defense:
No blockers. There is one important gap in how quickly the defect path takes effect, plus some test-coverage gaps. Requirements Check (issue #2895)
Standards: no backward-compatibility code. Code Review Findings1. 🟡 Important: a root vector already leaking stays leaked until something re-embeds the root📁 The exclusion only takes effect when the root is next re-embedded. The bypassing
The docs say root-only membership is what makes an access-change trigger unnecessary. On the defect path that constraint has, by definition, been bypassed. Timeliness is outside the ACs, so this is not a blocker. The data-layer.md section still suggests the handling happens immediately, which overstates it. Recommendation: add one sentence to data-layer.md's defect-path section: the exclusion applies at the root's next re-embed, and the write that creates the boundary does not trigger one. Also file a follow-up. The most likely bypass paths (sync apply, bulk import) could queue Principle: defense in depth, and docs that match behavior. A defense that runs only on an unrelated later event should say so. 2. 🟡 Important: the boundary logic is tested through one shape only📁 The one integration test covers an open root with a restricted descendant and a descendant filed into an open collection. The rest of the comparison logic in
These are exactly the branches a later refactor of the set-equality or seed-depth rules would silently break. For example, changing Recommendation: add a small table-driven store-level test in Principle: test coverage should match how critical the code is. This is security logic with several branches. 3. 🟢 Suggestion: the subtree CTE runs twice on every embed📁
Recommendation: leave it for now. If embed latency on large trees ever matters, compute the set once in Principle: DRY, and avoiding repeated I/O. 4. 🟢 Suggestion: bulk create assumes every node shares one embedding root📁 The comment says all nodes in a bulk import share one root, so only Recommendation: reword the comment to "share the same tree; the embedding root of the first parent is assumed to cover the batch", or collect distinct embedding roots per parent (cheap, since parents are few). Principle: comments should state an assumption accurately when the change affects it. 5. 🟢 Nit: the new doc paragraph is attached to the constant, not the function📁 The doc block above 6. 🟢 Nit: inconsistent chunking of IN-lists📁
7. 🟢 Nit: this defect's log carries no error field📁
Security notes (verified, no action)
Recommendation: APPROVEThe change meets every acceptance criterion, is architecturally cohesive and fails safe. Findings 1 (document the "next re-embed" timing, and file a follow-up) and 2 (table-driven boundary-shape tests) are strongly recommended. Neither blocks the merge. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
- Add access_boundary_shapes_agree_across_exclusion_and_rerooting_adr059: nested boundaries, restricted root with same/different collection, the ties rule, a restricted collection in the subtree, the person exemption, an open collection nested in a restricted one, and a same-access candidate with a boundary below it. Each shape asserts both access_boundaries_under and embedding_root_id. Mutation-checked (subset-for-equality, person exemption, restricted-collection self-check). - Move MAX_AGGREGATION_DEPTH above aggregate_children_content's doc block so rustdoc attaches it to the function. - Structured tracing fields in queue_access_boundaries. - Bulk-create comment states why one embedding root covers the whole import. - Exclusion timing documented in nodespace-docs data-layer.md (8b353d4). Skipped: computing the boundary CTE once per embed (the walk fetching its own boundaries keeps the exclusion unbypassable; cost is small next to embedding generation), and chunking embedding_root_id's IN-list (the chain is capped at 1000, far below SQLite's 32766 variables). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CbMVLf7z8mBEgn2xPsNLcB
…from member_of only Collections nest through member_of, never has_child. A collection may have has_child children but never a parent, and a node with a parent cannot become a collection (ADR-059 §2). - Schema triggers collection_is_root_edge / collection_is_root_type refuse a has_child edge onto a collection and a type switch to collection on a child. has_child is written from about a dozen places, so the DDL is the one enforcement point that covers all of them, including sync and raw writes. - Readable collection_not_root errors on the create, reparent (assert_may_gain_parent) and create_relationship paths. - The collection exemption in both root-only membership guards is gone: collections never have parents, so it guarded nothing. - Access boundaries: a collection is never a boundary or an embedding root. Candidates are member_of holders only, and the access walk follows member_of through collection nesting, without the restricted-collection self-check or the has_child step out of a collection. - Tests: collection_is_always_a_root_adr059 covers create, move, relationship create, a raw edge insert and a type switch (mutation-checked: each trigger and each Rust check fails the test when removed). The boundary-shapes test drops its nested-collection shape, and the root-only membership store test now files a root collection and refuses an interior one. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CbMVLf7z8mBEgn2xPsNLcB
Address-review summaryAddressed (
Skipped:
Folded in after discussion (
The pre-push gate passed, including e2e. Re-Review DecisionRE-REVIEW NEEDED. |
Pragmatic Code Review: PR #2903 (Re-Review)Review Type: Re-Review. Covers Previous Review Summary: 7 recommendations. 5 addressed, 2 skipped with sound reasons, 0 open. The new work raises 1 minor issue (🟡) plus a few 🟢 notes.
Requirements Check (issue #2895)All criteria are still met.
The docs match the code. Review of the new invariant (
|
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
- assert_may_gain_parent finds collections and member_of holders in its existing chunked query, instead of a separate full-row fetch; the doc comment's single-round-trip claim holds again. - access_boundary documents that a node never counts itself. - collection_not_root takes an optional id, so a create without one reads "a new collection cannot have a parent" rather than "collection 'new'". Skipped: a readable check in create_relationship_in_tx (the trigger's collection_not_root message already names the rule), and relabelling the boundary-shapes test (the shape (c) comment points to its replacement test). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CbMVLf7z8mBEgn2xPsNLcB
Address-review summary (re-review)Addressed (
Skipped:
The pre-push gate passed. Re-Review DecisionNO RE-REVIEW NEEDED. The changes are a query consolidation covered by the invariant test, a doc comment, and error wording. |
Closes #2895
Summary
Implements ADR-059 §7's defect path. Root-only membership still keeps access boundaries out of embedding aggregates by construction. When that is bypassed, three things happen:
tracing::error!naming the root and the descendant.How "access differs" is decided locally
SqliteStore::access_boundary(node)is the set of nearest restricted collections reached from the node's own classification. The walk starts at the node itself if it is a restricted collection, otherwise at itsmember_ofedges, and then follows ADR-059 §1/§3. A descendant is a boundary when its set is non-empty and differs from its embedding root's. Candidates are found with one cheap subtree query:member_ofholders (excludingperson, whose edges are RBAC grants) and restricted collections. When the invariant holds there are none, and no walk runs.Changes
db/sqlite_store/embedding_roots.rs:access_boundary,access_boundaries_under,embedding_root_id.NodeAccessor::access_boundaries_underdrives the exclusion inaggregate_children_content. If the boundaries can't be read, it aggregates nothing rather than risk a leak.get_embedding_root_id, the spawned-task walk,NodeEmbeddingService::find_embedding_root_id(replacesfind_root_id), and the bulk-create and delete queueing all resolve throughembedding_root_id.refresh_for_rootnesskeeps a re-rooted descendant's embedding.embed_root_nodequeues any boundary descendant that has no embedding yet. The edge that created the boundary edited no content, so nothing else would queue it.Tests
access_boundary_descendant_is_excluded_and_rerooted_adr059writes themember_ofedge directly, bypassingassert_may_gain_parent. It asserts:embedding_aggregation_never_spans_an_access_boundary_adr059still passes.Docs
Companion edits are in nodespace-docs
f3c13e3: ADR-059 §6 is reconciled with §2/§7, and the tree-root-only statements indata-layer.mdand ADR-029 now carry the exception.data-layer.mdalso documents the local access comparison.🤖 Generated with Claude Code
https://claude.ai/code/session_01CbMVLf7z8mBEgn2xPsNLcB