Skip to content

Register subtype behaviours from build_shared_services in every database - #3625

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3414-typed-subtypes
Oct 5, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3414-typed-subtypes

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Part of #3414 (the "Typed subtypes and edge fields" section, ADR-082 §2.1 and §5). This is the second of three PRs. It is stacked on #3624: the base is issue-3414-supported-extension-ids, so the diff shows only this PR's commit. Retarget it to main once #3624 lands.

What changes

DaemonExtensions::behavior(b) adds the Rust NodeBehavior of an extends subtype of a core type.

  • Per-database registration. Every database the daemon opens registers b in its own NodeBehaviorRegistry, alongside core's, so the daemon validates the subtype on every write through its node API.
  • Composition. This uses the registry's existing rules. validate_node runs the chain base first, so a subtype refuses more and never less. resolve takes the nearest behaviour for embedding, markdown and content rules.

Core (nodespace_core::extensions):

  • DataExtensions: none(), behavior(b), behavior_registry() and check().
  • NodeService::new_with_extensions(store, &data). NodeService::new is that call with DataExtensions::none().
  • DataExtensionsError is #[non_exhaustive].

Rejected at startup (build_shared_services runs DaemonExtensions::check, which runs DataExtensions::check before anything is built):

  • a behaviour for a core type;

  • a second behaviour for one type;

  • a type that is not a schema id create_schema can store.

    The last rule exists because create_schema derives the id from the name as lowercase with _, so a behaviour keyed team-space would never match a node.

Daemon: build_database_services builds each database's node service with shared.extensions.data().

A behaviour no longer makes its type known to the create path. ensure_known_node_type accepted any type with a behaviour.

  • Until now that set was exactly the core types; the registry test holds it to CoreNodeType::ALL.
  • With extension behaviours, a subtype would be accepted before its schema existed. The node would then be stored outside its base: not a collection, and missing from collection queries.
  • It now accepts a core type or a type with a schema. With no extension this is the same set, so behaviour is unchanged.

With DaemonExtensions::none() and NodeService::new, the registry is NodeBehaviorRegistry::new() exactly, as before. build_unrouted_services keeps NodeService::new: it never serves a database.

Acceptance mapping (#3414, typed subtypes and edge fields)

  • build_shared_services takes additional NodeBehaviors for extends subtypes of core types. They are registered in each database's NodeBehaviorRegistry, and a behaviour for a type core already defines is rejected at startup.
  • Core fixture: a subtype of collection with its own behaviour, covering:
    • validation;
    • bucketed fields;
    • subtype-aware queries returning it for collection;
    • retype through rebucket_and_validate.

Tests

packages/core/src/extensions/fixture_tests.rs is new and added to WATCHED_PATHS. It defines fixture_collection extends collection, whose behaviour refuses a max_members below 1 in its own bucket, a rule the number type alone admits.

  • a_subtype_node_is_validated_by_its_behaviour_and_its_base: the subtype's rule applies, and so does collection's no-: rule.
  • the_subtypes_fields_are_stored_in_its_own_bucket: max_members goes to fixture_collection and description to collection.
  • queries_for_collection_return_the_subtype: both query_nodes_by_type("collection") and CollectionService::get_all_collections_with_counts return it.
  • a_collection_retyped_to_the_subtype_is_rebucketed_and_validated: a retype to max_members: 0 is refused and the node keeps its type. A valid retype moves the new field to the subtype's bucket and keeps description in collection's.
  • a_subtype_without_its_schema_is_an_unknown_type.
  • the_node_service_registers_the_added_behaviours.
  • a_node_service_with_a_behaviour_for_a_core_type_is_refused: refused before anything is written, so no core schemas are seeded.

Unit tests:

  • extensions::tests::no_extension_gives_exactly_the_core_registry;
  • …a_behaviour_for_a_core_type_or_a_second_one_for_a_type_is_rejected;
  • …a_behaviour_whose_type_is_not_a_schema_id_is_rejected;
  • services::extensions::tests::check_rejects_a_refused_behaviour.

Daemon fixture (extension_points_fixture.rs, through build_shared_services with the isolated home and no model):

  • a_subtype_behaviour_is_enforced_in_every_database: two databases, and each refuses max_members: 0.
  • a_behaviour_for_a_core_type_stops_startup.

Mutation check. 11 mutants, all killed. Every new test is killed by at least one:

Mutant Killed by
B1: node service ignores the added behaviours a_subtype_node_is_validated…, …retyped…, the_node_service_registers…
B2: refused extensions fall back to core's registry a_node_service_with_a_behaviour_for_a_core_type_is_refused
B3: behavior_registry registers nothing 4 fixture tests and a_behaviour_for_a_core_type_or_a_second…
B4: no schema-id check a_behaviour_whose_type_is_not_a_schema_id_is_rejected
B5: a behaviour makes its type known again a_subtype_without_its_schema_is_an_unknown_type
B6: fields not re-bucketed by owner (existing code) the_subtypes_fields_are_stored_in_its_own_bucket
B7: a query matches its type exactly (existing code) queries_for_collection_return_the_subtype, …retyped…
B8: daemon builds node services with NodeService::new a_subtype_behaviour_is_enforced_in_every_database
B9: DaemonExtensions::behavior drops it the daemon fixture tests, check_rejects_a_refused_behaviour
B10: DaemonExtensions::check skips the data check a_behaviour_for_a_core_type_stops_startup, check_rejects_a_refused_behaviour
B11: behavior_registry adds a stray behaviour no_extension_gives_exactly_the_core_registry

Local runs (crate-scoped, under the machine slot):

  • cargo clippy -p nodespace-core -p nodespace-daemon --all-targets -- -D warnings -D clippy::unused-async: clean.
  • Core --lib extensions:: unknown_node_type behaviors::tests: 142/142.
  • Daemon extension_points_fixture required_extensions services::extensions per_db: 24/24.
  • bun test scripts/: 1441/1441.
  • The full frontend suite: 5875/5875.
  • cargo fmt --check, Pro boundary, node-type literals and the extension-API version check: all pass.

Extension API

2.4 → 2.5 (minor). This adds a daemon hook: DaemonExtensions::behavior, and the data hook DataExtensions / NodeService::new_with_extensions.

  • The bump touches the Rust constant and its pin, the TypeScript constant, and the re-recorded surface snapshot (only version).
  • The core fixture is added to WATCHED_PATHS, and the script's test expects it.

Documentation

NodeSpaceAI/nodespace-docs#109 (branch issue-3414-typed-subtypes) gains a "Subtype behaviours" section, two failure-isolation rows, the core fixture in the watched files and the version.

Note for the follow-up builds

ADR-082 §2.1 and ADR-083 name the subtypes pro-collection and pro-database-settings. create_schema stores those names as pro_collection and pro_database_settings, and a behaviour keyed with a - is now refused at startup with that explanation.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review: PR #3625 (Register subtype behaviours from build_shared_services in every database)

Review Type: Initial Review, medium depth. Stacked on #3624, so this covers only this PR's diff (74f6ac42). Read-only: nothing was built or run.

Code Review Summary

This is a clean, well-scoped implementation of ADR-082 §2.1 / §5 behaviour registration, and it improves the codebase. Things I verified:

  • No change with no extension. DataExtensions::none().behavior_registry() is NodeBehaviorRegistry::new() with no registrations.
  • ensure_known_node_type keeps the same set for core. CoreNodeType::from_id matches exactly CoreNodeType::ALL, and register_core debug-asserts that every built-in behaviour is a core type. With no extension, the set is identical.
  • Refusal comes before any write. new_with_extensions builds the registry before the event channels and before any seeding.
  • Every routed database gets the behaviours. In the daemon, build_database_services is the only non-test place that builds a NodeService for a real database. Every other NodeService::new call in packages/daemon/src is inside a #[cfg(test)] module. The exception is build_unrouted_services, whose store is a private in-memory database.
  • The startup check is complete. It runs before anything is built.
  • The version bump is right. 2.4 → 2.5 is minor, which §8 requires for a new optional hook. The constants, the pin, the snapshot, WATCHED_PATHS and the script test all move together.
  • Project rules hold. No Pro wording or issue numbers in the code, and no literal node_type comparisons in production code.

I found no critical issues. Two items are Important. One is a guard that covers only one of the write paths, while the hook's doc comment claims more than that. The other is an ADR naming conflict that affects a cross-repo contract.

Requirements Check (#3414: typed subtypes, behaviour half)

  • ✅ build_shared_services takes extra NodeBehaviors, through DaemonExtensions::behavior. They are registered in each database's own NodeBehaviorRegistry by build_database_services.
  • ✅ A behaviour for a core type is rejected at startup: DaemonExtensions::check → DataExtensions::check, run before anything is built. The fixture a_behaviour_for_a_core_type_stops_startup goes through build_shared_services.
  • ✅ Core fixture fixture_collection extends collection covers:
    • validation by the subtype's behaviour and by collection's;
    • bucketed fields;
    • query_nodes_by_type("collection") and CollectionService returning the subtype;
    • a retype through rebucket_and_validate, both refused and accepted.
  • ✅ The daemon fixture uses an isolated home with no model and two databases, and each one enforces the behaviour.
  • ✅ ADR-082 §8: the minor bump, and the new fixture added to WATCHED_PATHS.
  • ⚠️ "A subtype without its schema is refused as an unknown type" holds only on create_node_with_parent (see finding 1).
  • ➖ Edge fields come in a later PR, so they are not counted here.

Findings

Critical Issues

None.

Suggested Improvements

1. 🟡 Important: the schema-first guard covers one create path, and the hook's doc comment says it covers all of them

📁 packages/core/src/services/node_service/crud.rs:2539, plus :253 (ensure_instantiable) and :83 (ensure_retype_allowed)
📁 packages/core/src/extensions.rs:76-78 ("without it a node of the type is refused as an unknown type")

ensure_known_node_type has one caller, prepare_create_node_with_parent. These paths never reach it:

  • create_node(Node);
  • bulk and hierarchy import;
  • the retype in update_node.

Here is what happens on those paths when a type has an extension behaviour but no schema:

  • type_chain falls back to [subtype] (type_ancestry.rs:29, chain_or_unextended).
  • resolve_field_owners skips the missing schema.
  • Only the subtype's own behaviour runs, and the write succeeds.

The node is then stored outside its base:

  • collection's : rule is skipped;
  • collection-name collision marking is skipped;
  • the singleton short-circuit in create_node is skipped (type_is_a(DatabaseSettings) is false);
  • the node is missing from query_nodes_by_type("collection") until the schema is created.

That is exactly the hazard the PR description gives as the reason for this change. Two more points:

  • The ADR's own flow is a retype. ADR-082 §2.1 and ADR-083 name retype as the Pro flow (settings singleton → subtype, collection → subtype), and §7 defers "seeding on database open". So a misordering on the other build's side would land on an unguarded path.
  • The daemon fixture uses an unguarded path. It creates its nodes with create_node.

Suggested fix (small): move the rule into ensure_instantiable. Its doc comment says ensure_creatable_in_batch, which calls it, runs on every create path, and ensure_retype_allowed calls it on retype. The rule: when a type has a registered behaviour, is not a core type and has no schema, return UnknownNodeType. This is already cached per distinct type in a batch. Plain invented types keep their current behaviour on those paths, and no compatibility concern arises.

Add a fixture test for a retype into the subtype before its schema exists. If you would rather not widen the guard, narrow the wording to the create-with-parent path in two places: DataExtensions::behavior's doc, and in docs PR #109 the "The schema comes first" bullet and the failure-isolation row ("Refused as an unknown type; nothing is written").

Principle: fail fast at the single choke point every write passes through, and make the documented contract of a versioned hook match its behaviour.

2. 🟡 Important: subtype ids now conflict with the names ADR-082 and ADR-083 give

📁 packages/core/src/extensions.rs:98 (NotASchemaId)

The rule itself is right and is needed:

  • ADR-078 says node types and schema ids share one normalized snake_case space.
  • ADR-082 §2.1 says the subtype's schema is created with create_schema, which normalizes the name.
  • Without the rule, a behaviour keyed with a - would never match a node, and nothing would report it.

The conflict:

  • The ADRs use dashes. ADR-082 §2.1 and ADR-083 use pro-collection, pro-database-settings and pro-person.
  • ADR-083 fixes a bucket key for nodespace-cloud. It specifies properties->'pro-collection'->>'restrictedToMembers' for the cloud tenant schema.
  • Only the PR body says otherwise. The "Note for the follow-up builds" is the one place that records the decision, and it will not be read once the PR is merged.

Under the rule to follow accepted ADRs literally, please record pro_collection / pro_database_settings / pro_person (and the matching bucket keys) as an amendment to ADR-082/083. It can go in docs PR #109, which today changes only architecture/extension-points.md. Otherwise the cloud work will target a bucket that never exists.

Principle: keep a single source of truth for a contract shared across repos.

3. 🟢 Suggestion: check for a core type before checking the schema-id form; also reject ""

📁 packages/core/src/extensions.rs:94-101

The schema-id check runs before register. A behaviour for a core type whose id contains - is therefore reported as NotASchemaId, for example CodeBlockNodeBehavior → code-block. Its message, "create_schema stores a schema under its lowercase name…", sends the author the wrong way: the real problem is that the type is a core type.

Check CoreNodeType::from_id / AlreadyRegistered first, so the core-type rule always reports as CoreType.

Separately, normalize_schema_id("") == "", so an empty type_name() passes check() but can never match a schema. Reject it explicitly.

4. 🟢 Suggestion: embedding aggregation ignores extension behaviours (follow-up)

📁 packages/core/src/behaviors/mod.rs:503 (text), :554 (header), :1528 (schema)

Each of these get_aggregated_content implementations builds a fresh NodeBehaviorRegistry::new() and passes it to aggregate_children_content. A descendant whose type is an extension subtype therefore contributes to its root's embedding through its base's behaviour, not its own. That contradicts the new docs ("the nearest behaviour in the chain decides embedding…").

Collection subtypes don't hit this today, because collections are roots. The hook is general, though: a later subtype of text or task would. Thread the service's registry through NodeAccessor, or document the limit, and track it as a follow-up.

5. 🟢 Suggestion: watched fixtures should pin every item of the new hook (ADR-082 §8)

📁 packages/core/src/extensions/fixture_tests.rs, packages/daemon/tests/it/extension_points_fixture.rs

These items are part of the versioned hook, but no file in WATCHED_PATHS uses them:

Item Where it is used today
DataExtensions::check unit tests and a doctest in extensions.rs
DataExtensions::behavior_registry unit tests and a doctest in extensions.rs
DaemonExtensions::data assembly.rs

None of those files is watched, so renaming or retyping one of these items would not trip the version gate. One call each in the two fixtures closes the gap.

6. 🟢 Suggestion: make BehaviorRegistrationError #[non_exhaustive]

📁 packages/core/src/behaviors/mod.rs:2731

It is now part of the extension API through DataExtensionsError::Behavior, but it is still an exhaustive enum. Adding a registration rule later would then be a major change. DataExtensionsError and DaemonExtensionsError are already non_exhaustive for exactly this reason.

Nitpicks

  • Nit: build_unrouted_services (packages/daemon/src/services/assembly.rs:619) keeps NodeService::new. That is correct, since it never serves a database. Using new_with_extensions(…, shared.extensions.data()) anyway would cost nothing and keep "every node service the daemon builds has the same registry" true without an exception to remember.

  • Nit: the two fixture behaviours differ slightly:

    • the core one refuses a non-numeric max_members, while the daemon one admits it;
    • for supports_markdown, the core one delegates to collection, while the daemon one returns false.

    This is harmless, but sharing one definition, or aligning the two, would keep them from drifting.

Recommendation

APPROVE (with recommendations). There are no blockers, and the change improves the codebase. I'd address finding 1 before merge, either by widening the guard to ensure_instantiable or by narrowing the documented claim, because it is small and the hook's contract states it. Finding 2 should land in docs PR #109 (or an ADR amendment) before the Pro build relies on these names. Findings 3–6 can be done in this PR or tracked as follow-ups.

@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)

I addressed the APPROVE review's findings in 06e90a0a.

✅ Addressed

  • 🟡 1. The schema-first guard covered one path only. The rule now lives in ensure_instantiable, through a new ensure_extension_type_has_schema. Every create path (single, with a parent, bulk, hierarchy import, invariant action) and every retype run ensure_instantiable. A type that has an extension behaviour but no schema in this database is refused as UnknownNodeType.
    • It reads the schema only for such a type. Core types and schema-defined types are not read, so core's behaviour is unchanged.
    • The earlier ensure_known_node_type change stays. It refuses on the create-with-parent path before a date container can be auto-created.
    • a_subtype_without_its_schema_is_an_unknown_type now covers create_node_with_parent, create_node(Node) and the retype in update_node, and checks that the node keeps its type.
  • 🟡 2. Subtype names vs ADR-082/083. The docs PR NodeSpaceAI/nodespace-docs#109 now carries a dated amendment to ADR-082 §2.1. Node types and schema ids share ADR-078's snake_case space, so the subtypes are stored as pro_database_settings and pro_collection, buckets included. The guide states the same. I did not edit ADR-083: its cloud paths (properties->'pro-collection') are for that ADR's owners and the cloud work in the later rebuild, so I'm flagging them here rather than changing them.
  • 🟢 3. Check order and the empty name. behavior_registry now reports a core type as CoreType before the schema-id rule (code-block is covered by a test), and it refuses "".
  • 🟢 5. Untested public surface. The watched daemon fixture now calls DataExtensions::check, DataExtensions::behavior_registry and DaemonExtensions::data.
  • 🟢 6. BehaviorRegistrationError is now #[non_exhaustive]. I checked first: Create the record on an add that names another skill's subject, and the type on a bare 'start tracking' (closes #3533) #3604's hunks in behaviors/mod.rs are at lines 1127, 1247, 4224 and 4463, and this attribute sits at 2731.

⏭️ Deferred

  • 🟢 4. The text, header and schema behaviours aggregate children's embedding content with a fresh core-only registry (behaviors/mod.rs). Making that use the node service's registry touches a file Create the record on an add that names another skill's subject, and the type on a bare 'start tracking' (closes #3533) #3604 has open, and it changes embedding, which is outside this hook. It's worth a follow-up issue. Today a subtype's embedding rule applies to its own node, not to a parent's aggregation of it.
  • Nit: build_unrouted_services keeps NodeService::new, because its in-memory store never serves a database.
  • Nit: the two fixture behaviours differ slightly. Each file stands alone, so they stay as they are.

Mutation check of the fixes. All 3 mutants are killed:

  • skipping the guard is caught by a_subtype_without_its_schema_is_an_unknown_type;
  • letting an empty name pass is caught by a_behaviour_whose_type_is_not_a_schema_id_is_rejected;
  • putting the schema-id check before the core-type check is caught by the same test.

Local runs:

  • clippy (core and daemon, --all-targets, -D warnings): clean.
  • Core extensions:: abstract unknown retype instantiable behaviors::tests create_node: 180/180.
  • Daemon extension_points_fixture required_extensions services::extensions: 15/15.
  • bun test scripts/: 1441/1441.
  • fmt and the version check: pass.

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: Finding 1 is fixed with new logic in the core create and retype path (ensure_instantiable). That is worth a second look, even though core types never reach the new read.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review (Re-Review): PR #3625

Review Type: Re-Review, medium depth. It covers only commit 06e90a0a, plus the last commit of docs PR NodeSpaceAI/nodespace-docs#109 (86dcb88b). Read-only: nothing was built or run.

Previous Review Summary

Count Items
Previous recommendations 8 6 numbered findings and 2 nits
Addressed 5 1 (guard on every path), 2 (ADR-082 amendment), 3 (check order and empty name), 5 (watched surface), 6 (non_exhaustive)
Deferred, with reasons 3 4 (embedding aggregation) and both nits
New issues 0 blocking 2 minor (🟢)

Verification of the fix for finding 1

The guard is in ensure_extension_type_has_schema, called first in ensure_instantiable.

It runs on every create and retype path. I traced every caller on origin/issue-3414-typed-subtypes:

  • Single create. create_node → create_node_in_tx → insert_node_in_tx_no_invariant_dispatch → ensure_creatable.
  • Create with a parent and with relationships. create_node_with_parent and create_node_with_relationships (through create_node_with_parent_in_tx) reach the same insert.
  • Invariant action. playbook/actions.rs:2363 calls the insert directly.
  • Bulk create. bulk_create, bulk_create_hierarchy and bulk_create_hierarchy_trusted call ensure_creatable_in_batch (bulk.rs:154, :596, :730).
  • Retype. Every site that changes node_type is followed by ensure_retype_allowed, which calls ensure_instantiable:
    • crud.rs:1250 → :1291
    • crud.rs:1389 → :1419
    • crud.rs:1522 → :1557
    • crud.rs:1805 → :1844
    • bulk.rs:894 → :943

The only other inserts are store.create_node calls inside sqlite_store tests.

Core types and schema-defined types are not read.

  • NodeBehaviorRegistry::get is an exact map lookup with no fallback, so it returns None for any type without its own behaviour.
  • register_core registers only CoreNodeType ids, and CoreNodeType::from_id returns early for those.
  • NodeBehaviorRegistry::new() is the only registry any NodeService gets unless new_with_extensions is used. No core test or production path registers a non-core behaviour on a service, except the two fixtures.

So with no extension, ensure_extension_type_has_schema returns Ok before any I/O, and core behaviour is unchanged.

Order against the other checks is fine.

  • Bulk. In bulk_create, assert_may_be_root runs before the guard for a new type. It is a read and passes for a type with no schema, so the error is still UnknownNodeType.
  • Retype. ensure_retype_allowed returns early when the type is unchanged. Only the target type is checked, so a retype out of a subtype to collection never reads.
  • update_node. The _seed flag stamp is written only after a successful update, so a refused retype writes nothing. That matches the docs row "nothing is written".

The batch cache is still correct.

  • instantiable_types records only types that passed, and the guard is a read of schema presence that nothing in a create batch can undo.
  • A batch that carries the subtype's schema and nodes of it together is refused, because the pre-validation loop runs before any insert. That fails closed. It is also the right result: before this commit those nodes would have been validated with the chain [subtype] and skipped the base's rules.

The tests cover the paths claimed.

  • a_subtype_without_its_schema_is_an_unknown_type (fixture_tests.rs:262) asserts UnknownNodeType on create_node_with_parent, create_node(Node) and the update_node retype, and checks that the node keeps collection.
  • The create_node_with_parent assertion is caught by ensure_known_node_type first. The create_node and retype assertions are the ones that kill the "drop the guard" mutant, which matches the mutation note in the round-1 reply.
  • The daemon fixture creates the schema before writing, so it does not depend on the old unguarded path.

Verification of the other addressed items

  • 3 (extensions.rs:100-104). register runs first, so code-block reports CoreType, and "" is refused as NotASchemaId. A duplicate is still AlreadyRegistered. The partly built registry is dropped on Err. ✅
  • 5. DataExtensions::check, behavior_registry and DaemonExtensions::data are now called from extension_points_fixture.rs, which is in WATCHED_PATHS (scripts/check-extension-api-version.ts:65). These changes fall under this PR's 2.4 → 2.5 bump. ✅
  • 6. #[non_exhaustive] is on BehaviorRegistrationError. ✅
  • 2 (docs 86dcb88b). Accurate. ✅
    • normalize_schema_id lowercases the name, maps space and - to _, and collapses repeated _, which matches "lowercase, with words joined by _".
    • The ADR-082 §2.1 amendment is dated and names pro_database_settings / pro_collection and the properties["pro_collection"] bucket.
    • The guide's "The schema comes first" bullet and its failure-isolation row now say "any create path, or retyping", which matches the code.

Findings

1. 🟢 Suggestion: ADR-083 still states the hyphenated cloud path, with no pointer to the amendment

📁 nodespace-docs decisions/083-pro-owned-state-leaves-the-core-data-model.md:105 (and :70 for pro-person)

The ADR-082 amendment does say that "the hyphenated spellings … in ADR-083 name the same types". The trouble is that ADR-083:105 is the line the nodespace-cloud work will copy from: properties->'pro-collection'->>'restrictedToMembers'. Someone reading only ADR-083 gets the wrong bucket key.

Leaving ADR-083's wording to its owners is reasonable. Two small additions would remove the trap:

  • a one-line "see the ADR-082 §2.1 amendment (2026-10-05)" note next to ADR-083:70 and :105;
  • a tracked follow-up for the cloud tenant-schema paths.

The amendment could also name pro_person (from ADR-083:70) next to the other two rather than leaving it to "and so on".

Principle: a cross-repo contract should be correct at the place implementers read it.

2. 🟢 Nit: the guard checks that the schema exists, not that it places the type under a base, and it repeats ensure_known_node_type's read

📁 packages/core/src/services/node_service/crud.rs:277-297, :2570-2585

Existence is not placement. get_schema is get_node(id) (SELECT * plus deserialising), so it confirms only that a node with that id exists. The rationale in the doc comment is that the schema "places the type under the core type it extends". A schema with that id but no extends would pass, and the node's chain would still be [subtype].

The behaviour API declares no base, so core cannot check the right base. Two cheap options would match the stated rationale more closely:

  • core_type_of(node_type).is_some(), which reads type_ancestry;
  • the is_abstract_type-style SELECT 1 … AND node_type = schema.

The logic is duplicated. The existence-to-UnknownNodeType code now appears twice (ensure_known_node_type and ensure_extension_type_has_schema). One small helper would keep the two from drifting.

Neither point affects core types, since neither code path reads for them, and the cost per extension-type create is negligible. Optional.

Note, no action needed: the guard reads on the pool, not on the update's tx. That is the same as is_abstract_type next to it. If the Pro build ever creates a subtype's schema and retypes into it inside one NodeService transaction, the retype will be refused (fail-closed). Calling create_schema and then the retype as separate writes, as ADR-082 §2.1 describes, is unaffected.

Deferred items

Recommendation

APPROVE. Finding 1 from the first review is now fixed at the right choke point. The fix:

  • is on every create and retype path;
  • does not read for core or schema-defined types;
  • keeps the batch cache correct;
  • has tests that kill the relevant mutants.

The docs amendment is accurate. Two optional items remain: the ADR-083 pointer and filing the follow-up for finding 4. Neither blocks merge.

🤖 Generated with Claude Code

@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 (re-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 2: re-review, APPROVE)

✅ Addressed

  • The re-review asked for a follow-up issue on deferred finding 4 before merge. It is filed as Aggregate children's embedding content with the database's behaviour registry #3627: aggregate children's embedding content with the database's behaviour registry instead of a fresh core-only one. It lists the three sites and the acceptance criteria, and is unassigned.
  • 🟢 1, partly. The ADR-082 §2.1 amendment in NodeSpaceAI/nodespace-docs#109 (1a85a66) now names pro_person alongside pro_database_settings and pro_collection. It also states that a path written with the hyphenated spelling, such as ADR-083's tenant-schema paths, means the snake_case bucket.

⏭️ Deferred

  • 🟢 1, the rest: a pointer line inside ADR-083 itself. That ADR is owned by the cloud/sync decision makers, and ADR-082's amendment already names ADR-083 explicitly. I'd leave the edit to its owners when the tenant-schema work starts.

  • 🟢 2: requiring the schema to extend a core type, and sharing one helper with ensure_known_node_type.

    • The guard's job is to stop a node of a type that has no definition in this database. Whether the extension's schema uses extends is the extension's own contract (ADR-082 §2.1: "The other build ensures its schemas exist").
    • Checking the chain would add a chain resolution to every create of such a type for a case the build controls.
    • The duplicated read happens only for extension types, at most twice per create on the create-with-parent path. A shared helper would save one line.

    I'd revisit both if an extension ever registers a behaviour for a non-subtype.

  • Noted, no change: a schema created and retyped into inside one transaction is refused, because the check reads outside the transaction, like the abstract-type check beside it. The documented flow creates the schema at bind or join, before any retype.

No code changed this round.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: This round changes only the docs amendment and files a follow-up issue. The re-review approved the code as it stands at 06e90a0a.

🤖 Generated with Claude Code

@mstomar125
mstomar125 force-pushed the issue-3414-supported-extension-ids branch from 657470c to f265d30 Compare October 5, 2026 14:52
Base automatically changed from issue-3414-supported-extension-ids to main October 5, 2026 14:52
@mstomar125
mstomar125 force-pushed the issue-3414-typed-subtypes branch from 06e90a0 to 28c798b Compare October 5, 2026 14:53
@mstomar125

Copy link
Copy Markdown
Contributor Author

Rebased onto main after #3624 merged: git rebase --onto origin/main 657470c0, which drops #3624's pre-squash commits. The new head is 28c798b7, now based on main. The rebase had no conflicts and only this PR's two commits are replayed. check-extension-api-version passes (2.4 → 2.5), and the push check passed.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits October 5, 2026 17:05
DaemonExtensions::behavior(b) adds the behaviour of an `extends` subtype of
a core type (ADR-082 §2.1). Each database the daemon opens registers it in
its own NodeBehaviorRegistry, so the daemon validates the subtype on every
write through its node API, base behaviours first.

- nodespace_core::extensions::DataExtensions carries the behaviours;
  NodeService::new_with_extensions builds a node service with them, and
  NodeService::new is that with none. build_database_services passes the
  daemon's.
- Rejected at startup (DataExtensions::check, run by
  build_shared_services): a behaviour for a core type, a second behaviour
  for one type, and a type that is not a schema id create_schema can store.
- A behaviour no longer makes its type known to the create path: a type is
  known when it is a core type or has a schema, so a subtype is refused
  until its schema, which places it under its base, exists in the
  database. With no extension this is the same set as before.
- Fixtures: a `fixture_collection extends collection` with its own
  behaviour in core (validation by it and its base, bucketed fields,
  queries and the collection listing returning it, retype through
  rebucket_and_validate) and in the daemon (enforced in every database;
  a behaviour for a core type stops startup). The core fixture is added to
  WATCHED_PATHS.
- EXTENSION_API_VERSION 2.5: a new daemon hook (minor).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e and retype

- ensure_instantiable, which every create path (single, with a parent,
  bulk, hierarchy import, invariant action) and every retype run, refuses a
  type another build registered a behaviour for while the database has no
  schema for it. The check reads the schema only for such a type; core
  types and schema-defined types are not read.
- DataExtensions::behavior_registry reports a core type as one before the
  schema-id rule (a core id such as code-block is not a schema id
  create_schema produces), and refuses an empty type name.
- BehaviorRegistrationError is non_exhaustive: it is part of the extension
  API now.
- The fixtures cover create_node and the retype for a schema-less subtype,
  and the daemon fixture uses DataExtensions::check, behavior_registry and
  DaemonExtensions::data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3414-typed-subtypes branch from 5a3cc88 to 31ec8f2 Compare October 5, 2026 15:05
@mstomar125
mstomar125 merged commit 253b621 into main Oct 5, 2026
@mstomar125
mstomar125 deleted the issue-3414-typed-subtypes branch October 5, 2026 15:05
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.

1 participant