Repository navigation
Description
Overview
ADR-059 §7 and data-layer.md say embedding aggregation asserts rather than filters. A descendant whose access differs from the aggregating root's means the root-only membership invariant has been violated. That descendant is excluded from the root's vector, the violation is surfaced, and the descendant becomes its own embedding root so authorized readers can still find it by meaning. None of this is implemented. Aggregation walks has_child with no access check, and get_embedding_root_id always resolves to the tree root. Implement the defect handling as documented.
Problem Statement
The boundary is currently prevented by construction only:
member_ofis root-only (SqliteStore::assert_may_gain_parent).- Independently restricted interior types (
task,project,date,person,ai-chat) contribute nothing to a parent's vector.
embedding_aggregation_never_spans_an_access_boundary_adr059 (packages/core/src/services/node_service/mod.rs) pins both. If either invariant is broken, whether by a future write path, sync, a bulk import or a type becoming embeddable, nothing notices. Restricted text would enter an open root's vector and leak its meaning through semantic search. Nothing detects this or reports it, and the restricted content is never re-rooted so authorized readers can find it.
Proposed Solution
- Detect. During root-aggregate content extraction, check each descendant that would contribute to the vector: does its effective access differ from the aggregating root's? For example, it carries its own restriction-bearing
member_ofedge, or sits under a restricted collection the root does not. - Exclude and surface. Leave that descendant, and its subtree, out of the root's aggregated content. Log it as a defect (
tracing::error!naming both node ids) instead of embedding across the boundary. - Re-root. Treat the excluded descendant as its own embedding root:
NodeService::get_embedding_root_idand the spawned-task walk inqueue_root_for_embedding_asyncstop at it;- it gets its own vector if its type is embeddable;
refresh_for_rootnessdoes not delete its embedding while the access difference holds.
- Scope the "only a tree root is an embedding root" rule (from the title-only search change) to "except a re-rooted access-boundary descendant", in both code comments and docs.
Architecture Impact
nodespace-docs/decisions/059-access-classification-not-outline-position.md(§6 table row "Embedding root", §7): this issue implements the documented defect handling. The ADR contradicts itself: §6 says restriction-bearingmember_ofedges "are not constrained to parentless nodes … at any outline depth", while §7 relies on §2's root-only membership constraint, which the code enforces. Companion docs edit required: reconcile §6 with §2/§7 as implemented.nodespace-docs/architecture/data-layer.md(§ Aggregation Never Spans an Access Boundary, and "Only root nodes … get embedded"; "Not embeddable: … child nodes"): state the re-rooted descendant as the one exception to tree-root-only embedding.nodespace-docs/decisions/029-behavior-owned-embedding.md(revision note: "only a tree root is ever an embedding root"): add the same exception.
Acceptance Criteria
- A descendant whose access differs from its aggregating root's contributes nothing to that root's embedding, and neither does its subtree.
- That condition is surfaced as a defect (an error-level log naming both node ids), not silently handled.
-
get_embedding_root_id(and the spawned-task walk) resolves a node inside or at such a descendant to the descendant, not the tree root. The descendant is embedded if its type is embeddable. -
refresh_for_rootnessdoes not delete the re-rooted descendant's embedding. - A test builds the violating shape by writing the edge directly, bypassing
assert_may_gain_parent(a descendant with a restriction-bearingmember_ofedge). It asserts: the root's aggregate excludes the descendant's text; the descendant is its own embedding root; the defect is surfaced. Mutation-check it: the test fails with the exclusion removed. -
embedding_aggregation_never_spans_an_access_boundary_adr059still passes (the construction invariant is unchanged). - Companion
nodespace-docsedits land: ADR-059 §6 reconciled with §2/§7, and the tree-root-only statements indata-layer.mdand ADR-029 carry the exception. - Code passes
bun run quality:fix - Tests pass (
bun run test:all)
Technical Specifications
Reference Files
- Aggregation:
packages/core/src/services/embedding_service.rs,extract_content_for_embedding. Callsbehavior.get_aggregated_content(node, accessor). - Tree walk behaviors:
packages/core/src/behaviors/mod.rs,TextNodeBehavior/HeaderNodeBehaviorget_aggregated_content. Walks children throughNodeAccessor, which has no access information today. - Accessor:
packages/core/src/services/mod.rs,NodeAccessor(get_node,get_children,get_nodes). The access check needs either a new accessor method or a pre-computed exclusion set passed into aggregation. - Embedding root:
packages/core/src/services/node_service/embedding.rs:get_embedding_root_idandqueue_root_for_embedding_async. - Rootness refresh:
packages/core/src/services/node_service/crud.rs,refresh_for_rootness/try_refresh_for_rootness. - Root-only membership:
packages/core/src/db/sqlite_store/,assert_may_gain_parent. - Existing invariant test:
packages/core/src/services/node_service/mod.rs,embedding_aggregation_never_spans_an_access_boundary_adr059. - Access model:
restrictedToMemberson collections; the effective-access walk described in ADR-059 §6 (member_of/has_childancestry).
Implementation Notes
- Do not run bare
cargo test -p nodespace-core; usebun run rust:test:lib/bun run rust:test:core. - Keep the construction invariant (root-only
member_of) as the primary guarantee; this issue adds the defect-path handling, not a replacement.
Related Issues
- Search's keyword half should match root titles, not node content at every depth #2867 (only tree roots are embedding roots; title-only keyword search)
- Decide whether date and schema nodes get titles, and unify the title rule across write paths #2858 (one title rule)
Activity
malibio commentedon Sep 23, 2026
Frontend baseline: 262 files / 5264 tests passed
Exclude and re-root a descendant whose access differs from its embedd…