Repository navigation
Description
Overview
When a node leaves a tree, nothing re-queues the tree it left. The old root's embedding keeps the departed subtree's text until someone next edits that tree. Leaving includes:
- outdenting to root;
- moving under a parent in another tree;
- deleting its
has_childedge.
Joining a tree works: the tree gained is re-queued.
Problem Statement
The embedding queue follows has_child. Every path that changes a node's parent calls refresh_for_rootness(node_id, is_root). That function fixes the moved node's title and its own embedding, then calls queue_root_for_embedding(node_id). That resolves the node's new embedding root. The old root, whose aggregate just lost the node's subtree, is never queued.
Deleting a node does not have this problem. delete_node resolves the embedding root before the delete and queues it afterwards.
Two consequences:
- Stale search. The old root still ranks for text it no longer contains, until an unrelated edit to that tree re-queues it.
- Access leak through a legitimate flow. A user outdents a line so it becomes its own root. They then file it into a restricted collection, which is allowed because it is now a root. The old open root's vector still carries the line's text, so semantic search surfaces its meaning to readers outside the collection. This is the leak ADR-059 §7 exists to prevent, and it happens with no invariant bypassed.
member_of plays no part in the fix. Embeddings follow has_child only. The trigger is the node's position in the tree, not its classification.
Proposed Solution
In each path that removes or replaces a node's has_child parent, resolve the node's embedding root before the edge changes (NodeService::get_embedding_root_id). After the change, queue that old root when it differs from the new one. This is the same capture-before, queue-after pattern delete_node already uses.
Paths to cover:
NodeService::move_nodeandmove_node_unchecked(packages/core/src/services/node_service/hierarchy.rs), for outdent-to-root and reparent across trees.- The
has_childrelationship-delete paths inpackages/core/src/services/node_service/relationship.rs, the ones that callrefresh_for_rootness(target_id, true)/refresh_for_rootness_in_tx(.., true). move_children_to_parentand any otherrefresh_for_rootnesscall site that detaches a node. Audit every call site; each one that can change the parent must queue the old root.
A move within the same tree resolves the old and new roots to the same id, so no extra queue is written.
Acceptance Criteria
- Outdenting a node to root re-queues its former tree root. A test asserts the old root's embedding is marked stale, or gets a stale marker.
- Moving a node under a parent in a different tree re-queues both the old and the new root.
- Deleting a node's
has_childedge through the relationship API re-queues the former tree root. - A move within one tree queues that tree once, and nothing else.
- The outdent-then-file case is covered: after outdenting and filing a line into a restricted collection, the former root is queued. Its rebuilt aggregate excludes the line.
- Each new test is mutation-checked: removing the old-root queue makes it fail.
- Code passes
bun run quality:fix - Tests pass (
bun run test:all)
Technical Specifications
Reference Files
- Rootness refresh:
packages/core/src/services/node_service/crud.rs,refresh_for_rootness/refresh_for_rootness_in_tx - Move paths:
packages/core/src/services/node_service/hierarchy.rs,move_node,move_node_unchecked - Relationship delete:
packages/core/src/services/node_service/relationship.rs, thehas_childdetach call sites - Pattern to copy:
packages/core/src/services/node_service/crud.rs,delete_node(theroot_id_for_embeddingcapture and queue) - Embedding root:
packages/core/src/services/node_service/embedding.rs,get_embedding_root_id,queue_root_for_embedding
Implementation Notes
- Queueing is
#[cfg(feature = "nlp")]on the service paths. The stale-marker assertions need the store-level marker (has_embeddings/ stale state), not a running NLP engine. - The
_in_txrelationship path writes no embedding state inside the transaction (seerefresh_for_rootness_in_tx). Queue the old root after commit, as the non-tx path does, rather than inside the transaction. - Do not run bare
cargo test -p nodespace-core; usebun run rust:test:lib/bun run rust:test:core.
Estimate: small, about half a day. It touches roughly 3–4 call sites, applies one existing pattern, and adds one test module.
Related Issues
- Exclude and re-root a descendant whose access differs from its embedding root's #2895 (embedding roots and access boundaries;
get_embedding_root_idnow resolves re-rooted descendants) - Subtree embedding aggregation must stop at access boundaries; restricted descendants become their own embedding roots #1737 (superseded by ADR-059; it rejected re-embedding on
member_ofchanges, which this issue does not reopen)
Activity
malibio commentedon Sep 25, 2026
Frontend baseline: 262 files / 5269 tests passed