Skip to content

Aggregate children's embedding content with the database's behaviour registry - #3638

Merged
mstomar125 merged 1 commit into
mainfrom
issue-3627-aggregation-registry
Oct 5, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-3627-aggregation-registry

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #3627

Problem

The text, header and schema behaviours build their embedding content from their children through aggregate_children_content, and each passed it a fresh NodeBehaviorRegistry::new(). That registry holds core's behaviours only. A behaviour another build registers for an extends subtype of a core type (DataExtensions::behavior, through NodeService::new_with_extensions) was in the node service's registry but not in this one. So when a node of that subtype sat under a text, header or schema node, the parent asked core's registry for the child's contribution and got the base type's rule, not the subtype's.

Change

  • NodeAccessor gains behavior_registry(): the behaviour registry the database's node service validates with, extension behaviours included. NodeService returns its own registry.
  • aggregate_children_content resolves each child's contribution through accessor.behavior_registry() and no longer takes a registry argument, so no caller can hand it a different one. The three behaviours call it with the node and accessor they already receive. get_aggregated_content's signature and every caller of it are unchanged: the embedding service and the tests already pass the node service as the accessor.
  • The test doubles that implement NodeAccessor (in behaviors and embedding_service tests) hold core's registry.

With no extension, a database's registry is exactly core's (DataExtensions::none().behavior_registry(); see no_extension_gives_exactly_the_core_registry), so aggregation output is byte-for-byte unchanged.

No extension-API version bump: ADR-082 §8 versions the registration hooks, and the hook's contract already says the subtype's behaviour decides embedding (§2.1). This change makes aggregation honour it. NodeAccessor is not on the versioned surface, and the watched fixture (extensions/fixture_tests.rs) is untouched.

Tests

New, in packages/core/src/behaviors/mod.rs (real SqliteStore + NodeService::new_with_extensions, no model):

  • a_subtype_child_contributes_to_its_parent_as_its_registered_behaviour_says: registers FixtureNoteBehavior for fixture_note extends text through DataExtensions. Its get_parent_contribution labels the content, unlike text's. A text parent aggregates "Plain line\n\nFixture note: Kept aside", and a header parent aggregates "Fixture note: Under a heading".
  • aggregation_with_no_extension_is_unchanged: no extension. A text page with a nested text line, a header, a task, chore extends task and fixture_note extends text (no behaviour of their own) aggregates to "Plain line\n\nNested line\n\n## Section\n\nA note". That expected string was recorded by running the test on the code before this change, where it passed.

Mutation check, each run on its own (both tests per mutation):

Mutation subtype test unchanged test
M1: the code before this change (fresh core registry in each behaviour) FAIL ("Plain line\n\nKept aside") PASS
M2: NodeService::behavior_registry returns a static core-only registry FAIL PASS
M3: HeaderNodeBehavior::get_aggregated_content returns None FAIL (header assertion) PASS
M4: resolve a child by its exact type only (chain[..1]) PASS FAIL (A chore leaks in)
M5: resolve every child with the root's type FAIL FAIL (A task, A chore leak in)

Run (CPU only, each under the machine slot, on this head):

  • cargo nextest run -p nodespace-core --lib --test it filtered to behaviors::, extensions::, test_schema_get_aggregated_content, ai_chat_message_test::, schema_embedding_queue_test::, ai_chat_subtypes_test::, extends_subtype_identity_test::, tool_subtypes_test::: 239 passed.
  • cargo clippy -p nodespace-core -p nodespace-daemon --all-targets -- -D warnings -D clippy::unused-async: clean. This compiles the nlp-gated embedding_service test double; those tests are not run here (no model on the shared machine).
  • cargo fmt --check: clean.
  • bun test scripts/: 1448 pass, 0 fail. bun run scripts/check-pro-boundary.ts: clean.

Documentation

  • ADR-082 §2.1: a subtype's behaviour decides its embedding rules. This implements that for aggregated parents; no new decision.
  • No docs change: architecture/extension-points.md does not describe aggregation.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review Type: Initial Review (medium depth), head ff6b63ae

Requirements Check

  • ✅ get_aggregated_content resolves each child's contribution with the database's registry, extension behaviours included. aggregate_children_content no longer takes a registry. It reads accessor.behavior_registry(), so a caller cannot pass a different registry. Text, header and schema are the only three aggregating behaviours, and all three call the helper directly. NodeService returns &self.behaviors, the registry new_with_extensions builds from DataExtensions. The daemon's embedding wiring (assembly.rs, wire_database_embeddings_bg) uses a clone of that same node service as the accessor, and the clone shares the Arc. Outside #[cfg(test)], the only NodeBehaviorRegistry::new() left is the builder in DataExtensions::behavior_registry.
  • ✅ A core test registers a subtype behaviour through DataExtensions and a text parent aggregates the child the way that behaviour says. a_subtype_child_contributes_to_its_parent_as_its_registered_behaviour_says uses a real SqliteStore and new_with_extensions. It also covers a header parent. The pre-change code fails it (M1 in the mutation table).
  • ✅ With no extension, aggregation output is unchanged. Without an extension, the node service's registry is DataExtensions::none().behavior_registry(), which is exactly NodeBehaviorRegistry::new() with nothing added. no_extension_gives_exactly_the_core_registry already pins that, so the change cannot alter core output. aggregation_with_no_extension_is_unchanged adds a characterization test over text, header, task, chore extends task and an unregistered extends text subtype.

Code Review Findings

No 🔴 Critical or 🟡 Important findings.

What I checked and found sound:

  • Seam choice. Passing the registry as a parameter of get_aggregated_content would change the NodeBehavior trait, which is the type the behaviour-registration hook takes (ADR-082 §8, versioned). It would break every extension behaviour. A getter on NodeAccessor changes nothing an extension implements. The only implementor in production is NodeService; the others are test doubles. nodespace-sync has no impl NodeAccessor outside its read-only reference copy. Removing the helper's registry parameter also means a later edit cannot bring back a fresh core registry without changing the function's signature. That makes this regression structurally hard to reintroduce. Good design.
  • No EXTENSION_API_VERSION bump: agreed. None of scripts/check-extension-api-version.ts's WATCHED_PATHS is touched. The behaviour hook's documented contract (DataExtensions::behavior: "the nearest behaviour in the chain also decides embedding…"; ADR-082 §2.1) already promised this. The change is a conformance fix, not a contract change. NodeAccessor is ordinary core library API, which §5 and §8 leave unversioned.
  • Send/lifetimes. The boxed future now holds &NodeBehaviorRegistry borrowed from accessor, where it used to own a registry. It lives for the same 'a, and the registry is Sync. Dropping the async move { … } wrapper for Box::pin(aggregate_children_content(node, accessor)) is a clean simplification. As a side effect, each aggregation no longer allocates a fresh registry.
  • Tests. Both new tests go through the real path (NodeService as the accessor, the same call the embedding service makes), need no model, and run in the default test tier. The mutation table is convincing: M1/M2/M3 cover the registry and header paths, and M4/M5 cover chain resolution.
  • CLAUDE.md rules. No literal node_type comparisons outside tests. No issue numbers in comments. No lint suppressions. Neutral "another build" wording that passes the Pro boundary check. The doc comments on NodeAccessor::behavior_registry and the helper are accurate.

🟢 Suggestion: one source of truth for the embedding service's registry (follow-up, non-blocking)
📁 packages/core/src/services/embedding_service.rs:107,120-134,176-183
NodeEmbeddingService now uses two handles for the same registry. It resolves the root's behaviour through its own behaviors: Arc<NodeBehaviorRegistry> field (behavior_for). Aggregation, through self.node_accessor, resolves every child through node_accessor.behavior_registry(). All 15 NodeEmbeddingService::new/with_config call sites pass node_service.behaviors().clone() together with that same node service as the accessor, so the two agree today. Nothing enforces it, though: a future caller that pairs a core-only registry with an extended accessor (or the reverse) would resolve a subtype root one way and its subtype children another. In a follow-up, consider dropping the behaviors constructor parameter and resolving the root through self.node_accessor.behavior_registry(). That gives the embedding service a single registry source (DRY). The constructor is public and has many call sites, so it belongs in its own change, not this PR.

Recommendation: APPROVE. The change is small and correctly scoped. It makes subtype behaviours decide their contribution to an aggregating parent, as ADR-082 §2.1 already promised. The output without an extension is unchanged by construction, and the test is mutation-checked. The one suggestion is an optional follow-up.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review (round 1)

Review: APPROVE, with no Critical or Important findings. One 🟢 suggestion.

  • ✅ Addressed: 0
  • ⏭️ Skipped: 1
  • 📝 Commits: 0 (head unchanged at ff6b63ae)

⏭️ Skipped: give NodeEmbeddingService a single registry source (embedding_service.rs:107,120-134,176-183)

The finding is accurate. The service resolves the root's behaviour through its own behaviors field and the children's through node_accessor.behavior_registry(). Every caller passes node_service.behaviors().clone() together with that same node service as the accessor, so the two always agree today.

I left it out of this PR for three reasons:

  • Scope. The fix removes a parameter from the public NodeEmbeddingService::new / with_config. That touches 14 files across core, daemon, cli and agent. Six of them are in packages/agent, which is outside this change's lane.
  • Risk. It changes nothing in the outcome today, since the two handles are the same Arc on every production path. It is a hardening against a future mispairing.
  • No behaviour change from this PR depends on it.

Worth doing as its own follow-up: resolve the root through node_accessor.behavior_registry() and drop the behaviors constructor parameter.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: No code changed after the review. The only finding was an optional, out-of-scope suggestion, documented above as skipped.

@mstomar125
mstomar125 force-pushed the issue-3627-aggregation-registry branch from ff6b63a to 53a3ac9 Compare October 5, 2026 16:05
…registry (closes #3627)

The text, header and schema behaviours aggregated their children through
a fresh NodeBehaviorRegistry::new(), which holds core's behaviours only,
so a behaviour another build registered for an extends subtype of a core
type was ignored when a node of that subtype sat under one of them.

NodeAccessor gains behavior_registry(): the registry the database's node
service validates with. NodeService returns its own. The aggregation
helper resolves each child's contribution through it and no longer takes
a registry argument. get_aggregated_content and its callers are
unchanged. With no extension the registry is core's, so the output is
the same.

Tests: a text and a header parent aggregate a child of a subtype whose
registered behaviour contributes differently from text's; with no
extension, a mixed tree aggregates to the output the previous code gave.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3627-aggregation-registry branch from 53a3ac9 to 0cfa42b Compare October 5, 2026 16:11
@mstomar125
mstomar125 merged commit 49e1832 into main Oct 5, 2026
@mstomar125
mstomar125 deleted the issue-3627-aggregation-registry branch October 5, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aggregate children's embedding content with the database's behaviour registry

1 participant