Repository navigation
Description
Overview
The root-aggregate embedding model folds a root node's whole has_child subtree into one vector. The aggregation walk applies no access filtering — it is a pure graph traversal with no actor identity threaded through it at all. Where a descendant sits behind an access boundary the root does not cross, that descendant's text enters the root's vector, and semantic search returns a relevance signal plus a pointer to content the searcher may not read.
Problem Statement
aggregate_children_content in packages/core/src/behaviors/mod.rs walks descendants depth-first via accessor.get_children(), collects each child's get_parent_contribution(), and recurses wherever can_have_children() is true. It is bounded only by MAX_AGGREGATION_DEPTH. No access check exists, and the function signature carries no actor to check against.
The exposure is not verbatim text — it is meaning plus a pointer. A search for "contractor rate renegotiation" ranks an open project root highly because a restricted descendant's text is in its vector, and the result links to a node the searcher can open. That is enough to confirm the restricted content exists and roughly what it says.
Two things narrow but do not close this:
- Type luck.
task,date,person, andai-chatare not embeddable and do not contribute to a parent, so the common "open project with a restricted task" shape happens to be safe. An embeddable child (text,header,code-block) under an open embeddable root is not, and nothing prevents that shape. - Embeddings are local-only. Vectors are never synced and each device regenerates from synced content, which bounds the blast radius. It does not remove the requirement: a device regenerates from the content it holds, and a device whose user was granted a restricted descendant holds that descendant — so the vector it builds must still respect the boundary if that vector is ever used to answer a query on behalf of a different identity, and the "locally it is all yours" assumption is false the moment a device holds content restricted from its own user.
Proposed Solution
- Aggregation stops descending at any descendant whose access differs from the aggregating root's. The excluded descendant contributes nothing to the root's vector.
- An excluded descendant becomes its own embedding root, so its content stays searchable to those who may read it. Excluding content from an ancestor's vector must never make it unsearchable for authorized readers — that would trade a leak for silent data loss from search.
- The embedding queue must therefore enqueue an access-boundary node as a root in its own right, not only parentless nodes of embeddable types. This is a change to what "embedding root" means: parentless-and-embeddable, plus access-boundary-and-embeddable.
- Re-embedding must be triggered when access changes, not only when content changes. Flipping
restrictedToMemberson a collection, or adding/removing amember_ofedge, changes which subtree a vector may cover — so the affected roots need requeuing even though no node content was edited.
Content hashing is the existing change-detection mechanism; because the assembled content changes when a descendant is excluded, the hash changes too, so re-embedding on access change composes with what is already there.
Architecture Impact
- ADR-059 (
../nodespace-docs/decisions/059-access-classification-not-outline-position.md) §6 is the governing decision, and §5 is the conceptual basis: the embedding boundary, the access boundary, and the atomicity/OCC boundary are three independent partitions of the graph that do not coincide. This issue implements §6. - ADR-029 (
../nodespace-docs/decisions/029-behavior-owned-embedding.md) owns the behavior-driven extraction this modifies. The two-phaseget_embeddable_content()/get_aggregated_content()split is unchanged; the descendant walk inside phase 2 gains the boundary check. - ADR-045 (
../nodespace-docs/decisions/045-do-not-sync-embeddings-regenerate-locally.md) is why the blast radius is bounded but the requirement stands — regeneration is per-device from synced content. architecture/data-layer.mdhas been updated with the "Aggregation Stops at Access Boundaries" section. Note that its prior reference toaggregate_subtree_content()was stale — that function no longer exists, having been replaced by behavior-driven extraction — and the doc has been corrected.- The companion
nodespace-docschanges are already committed; no further docs work is required.
Acceptance Criteria
- Aggregation does not descend past a descendant whose access differs from the aggregating root's
- An excluded descendant of an embeddable type is enqueued and embedded as its own root
- An excluded descendant remains findable by semantic search for an identity that may read it
- The aggregating root's vector contains no text from the excluded descendant (asserted on assembled content, not only on search results)
- Flipping
restrictedToMemberson a collection requeues the affected embedding roots - Adding or removing a
member_ofedge requeues the affected embedding roots - Non-embeddable descendant types behave as before (no regression in the existing type table)
- Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Technical Specifications
Reference Files
- Aggregation walk:
packages/core/src/behaviors/mod.rs—aggregate_children_content(node, accessor, registry), bounded byMAX_AGGREGATION_DEPTH - Content assembly:
packages/core/src/services/embedding_service.rs—extract_content_for_embedding(node)(two-phase, per ADR-029),embed_root_node(root_id),compute_content_hash - Behavior trait:
NodeBehavior::get_embeddable_content,get_parent_contribution,get_aggregated_content,can_have_children - Queue trigger:
packages/core/src/services/node_service/embedding.rs—queue_root_for_embedding
Implementation Details
aggregate_children_contentcurrently takes(node, accessor, registry)and has no notion of an actor or an access domain. Deciding how the boundary is expressed is the main design choice in this issue: the walk needs to compare each descendant's access domain against the root's. Prefer resolving the boundary from the graph (does this descendant have a restricted ancestor the root does not?) over threading a user identity through the embedding pipeline — embedding is a background process with no request identity, and giving it one would be a larger change with its own risks.get_parent_contribution()returningNoneis the existing mechanism by which a child declines to contribute. The boundary check is different: it must also stop the recursion into that child's own subtree, not just skip its contribution.- The existing
origincolumn on the embedding table distinguishes'local'from'remote'; under ADR-045 every embedding is'local', so this issue does not interact with it. - Requeuing on access change needs a domain-event hook for relationship and property changes on collections, which is a different trigger path from the node-content mutations that drive queueing today.
Related Issues
- Harden the RLS access walk: assert member_of classification, minimum-depth tie resolution, and cycle bound as tested invariants #1735 (the access predicate the boundary check reasons about)
Activity
malibio commentedon Jul 25, 2026
Scope narrowed: root-only membership removes the boundary-crossing shape
ADR-059 §2 (commit
07b4ab1) now constrains content membership to root nodes only — a content node may hold amember_ofedge only if it has nohas_childparent. Combined with the embeddable-type list (task,date,person,ai-chatcontribute nothing to a parent's vector), an access boundary cannot appear inside an embeddable root's aggregate.That changes what this issue is asking for.
No longer in scope
aggregate_children_content. The function does not need an actor threaded through it. Filtering was compensating for a shape that is now unreachable.Still in scope — assertion, not filtering
Aggregation should assert the invariant rather than assume it:
Why the assertion is worth keeping
The invariant is a conjunction of two otherwise-unrelated facts: root-only membership (ADR-059 §2) and the embeddable-type list (
data-layer.md). Either changing breaks it — making a currently non-embeddable type embeddable, or admitting non-root membership, silently reintroduces the leak. The assertion is what makes that failure loud.Dependency
Enforcement of root-only membership needs the store-aware validation phase described in ADR-059 §2 — per-node
validate()cannot express it, since it must consult the store for the target's parent edges. That is the same seam #1734 opens for store-aware uniqueness rules. The constraint should be enforced on themember_ofedge write and on the sync-apply path, not only in the UI.Docs: ADR-059 §2 and §7,
architecture/data-layer.md("Aggregation Never Spans an Access Boundary").Pin ADR-059 embedding-access-boundary invariant with a regression test (
mstomar125 commentedon Aug 1, 2026
Resolved in #1891 (merged).
This issue's premise was superseded by ADR-059 (the governing decision). The issue proposed runtime access-filtering in the aggregation walk + an access-change requeue trigger. ADR-059 §2/§6/§7 instead makes the boundary unreachable by construction: "aggregation needs no access filtering and re-embedding needs no access-change trigger" (§7). The two load-bearing invariants:
member_ofis root-only (§2) — enforced byassert_root_only_membership, so an embeddablehas_childdescendant can't carry its own restriction.has_childonly — nevermember_of— so content filed into a restricted collection is never pulled into an unrelated open root's vector; collections/non-embeddable types contribute nothing.Both were already in place; I verified them empirically and added the missing regression test (
embedding_aggregation_never_spans_an_access_boundary_adr059): an open root's aggregate excludes a restricted-collection member's content, andadd_to_collectionon ahas_childdescendant is rejected. No production change was needed — the acceptance criteria that assumed runtime filtering/requeue are moot under the ADR's structural approach.