Skip to content

Subtree embedding aggregation must stop at access boundaries; restricted descendants become their own embedding roots #1737

Closed

Description

@malibio

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, and ai-chat are 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 restrictedToMembers on a collection, or adding/removing a member_of edge, 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-phase get_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.md has been updated with the "Aggregation Stops at Access Boundaries" section. Note that its prior reference to aggregate_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-docs changes 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 restrictedToMembers on a collection requeues the affected embedding roots
  • Adding or removing a member_of edge 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 by MAX_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_content currently 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() returning None is 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 origin column 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

Activity

  1. malibio commented on Jul 25, 2026

    @malibio
    CollaboratorAuthor

    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 a member_of edge only if it has no has_child parent. Combined with the embeddable-type list (task, date, person, ai-chat contribute 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

    • Access filtering inside aggregate_children_content. The function does not need an actor threaded through it. Filtering was compensating for a shape that is now unreachable.
    • Re-embedding on access change. This was the subtle half of the original issue — filing a descendant into a restricted collection edits no node, so no content-mutation event fires and the ancestor's vector would silently retain the restricted text. With root-only membership a descendant cannot be independently filed, so the trigger path is unnecessary. Do not implement it.
    • Access-boundary nodes becoming embedding roots. "Embedding root" stays parentless-and-embeddable; it does not also mean access-boundary-and-embeddable.

    Still in scope — assertion, not filtering

    Aggregation should assert the invariant rather than assume it:

    • If the aggregation walk encounters a descendant whose access differs from the aggregating root's, the §2 constraint has been violated. Exclude the descendant from the vector and surface the condition as a defect — do not silently embed across it.
    • This is defense in depth. It is cheap, and it converts a silent semantic leak into a visible bug if the constraint is ever weakened.

    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 the member_of edge 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").

  2. added a commit that references this issue on Aug 1, 2026
    a8d62c6
  3. mstomar125 commented on Aug 1, 2026

    @mstomar125
    Contributor

    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:

    1. Content member_of is root-only (§2) — enforced by assert_root_only_membership, so an embeddable has_child descendant can't carry its own restriction.
    2. The aggregation walk follows has_child only — never member_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, and add_to_collection on a has_child descendant is rejected. No production change was needed — the acceptance criteria that assumed runtime filtering/requeue are moot under the ADR's structural approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions