Skip to content

Exclude and re-root a descendant whose access differs from its embedding root's #2895

Closed

Description

@malibio

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_of is 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

  1. 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_of edge, or sits under a restricted collection the root does not.
  2. 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.
  3. Re-root. Treat the excluded descendant as its own embedding root:
    • NodeService::get_embedding_root_id and the spawned-task walk in queue_root_for_embedding_async stop at it;
    • it gets its own vector if its type is embeddable;
    • refresh_for_rootness does not delete its embedding while the access difference holds.
  4. 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-bearing member_of edges "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_rootness does 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-bearing member_of edge). 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_adr059 still passes (the construction invariant is unchanged).
  • Companion nodespace-docs edits land: ADR-059 §6 reconciled with §2/§7, and the tree-root-only statements in data-layer.md and 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. Calls behavior.get_aggregated_content(node, accessor).
  • Tree walk behaviors: packages/core/src/behaviors/mod.rs, TextNodeBehavior / HeaderNodeBehavior get_aggregated_content. Walks children through NodeAccessor, 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_id and queue_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: restrictedToMembers on collections; the effective-access walk described in ADR-059 §6 (member_of / has_child ancestry).

Implementation Notes

  • Do not run bare cargo test -p nodespace-core; use bun 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

Activity

  1. malibio commented on Sep 23, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 262 files / 5264 tests passed

  2. self-assigned this
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions