Repository navigation
Register subtype behaviours from build_shared_services in every database - #3625
Conversation
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 ( Code Review SummaryThis is a clean, well-scoped implementation of ADR-082 §2.1 / §5 behaviour registration, and it improves the codebase. Things I verified:
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)
FindingsCritical IssuesNone. Suggested Improvements1. 🟡 Important: the schema-first guard covers one create path, and the hook's doc comment says it covers all of them 📁
Here is what happens on those paths when a type has an extension behaviour but no schema:
The node is then stored outside its base:
That is exactly the hazard the PR description gives as the reason for this change. Two more points:
Suggested fix (small): move the rule into 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: 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 📁 The rule itself is right and is needed:
The conflict:
Under the rule to follow accepted ADRs literally, please record 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 📁 The schema-id check runs before Check Separately, 4. 🟢 Suggestion: embedding aggregation ignores extension behaviours (follow-up) 📁 Each of these Collection subtypes don't hit this today, because collections are roots. The hook is general, though: a later subtype of 5. 🟢 Suggestion: watched fixtures should pin every item of the new hook (ADR-082 §8) 📁 These items are part of the versioned hook, but no file in
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 📁 It is now part of the extension API through Nitpicks
RecommendationAPPROVE (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 |
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Address review (round 1)I addressed the APPROVE review's findings in ✅ Addressed
⏭️ Deferred
Mutation check of the fixes. All 3 mutants are killed:
Local runs:
Re-Review DecisionDecision: RE-REVIEW NEEDED Rationale: Finding 1 is fixed with new logic in the core create and retype path ( 🤖 Generated with Claude Code |
Pragmatic Code Review (Re-Review): PR #3625Review Type: Re-Review, medium depth. It covers only commit Previous Review Summary
Verification of the fix for finding 1The guard is in It runs on every create and retype path. I traced every caller on
The only other inserts are Core types and schema-defined types are not read.
So with no extension, Order against the other checks is fine.
The batch cache is still correct.
The tests cover the paths claimed.
Verification of the other addressed items
Findings1. 🟢 Suggestion: ADR-083 still states the hyphenated cloud path, with no pointer to the amendment 📁 nodespace-docs 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: Leaving ADR-083's wording to its owners is reasonable. Two small additions would remove the trap:
The amendment could also name 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 📁 Existence is not placement. The behaviour API declares no base, so core cannot check the right base. Two cheap options would match the stated rationale more closely:
The logic is duplicated. The existence-to- 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 Deferred items
RecommendationAPPROVE. Finding 1 from the first review is now fixed at the right choke point. The fix:
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
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Address review (round 2: re-review, APPROVE)✅ Addressed
⏭️ Deferred
No code changed this round. Re-Review DecisionDecision: 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 🤖 Generated with Claude Code |
657470c to
f265d30
Compare
06e90a0 to
28c798b
Compare
|
Rebased onto main after #3624 merged: 🤖 Generated with Claude Code |
28c798b to
5a3cc88
Compare
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]>
5a3cc88 to
31ec8f2
Compare
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 tomainonce #3624 lands.What changes
DaemonExtensions::behavior(b)adds the RustNodeBehaviorof anextendssubtype of a core type.bin its ownNodeBehaviorRegistry, alongside core's, so the daemon validates the subtype on every write through its node API.validate_noderuns the chain base first, so a subtype refuses more and never less.resolvetakes the nearest behaviour for embedding, markdown and content rules.Core (
nodespace_core::extensions):DataExtensions:none(),behavior(b),behavior_registry()andcheck().NodeService::new_with_extensions(store, &data).NodeService::newis that call withDataExtensions::none().DataExtensionsErroris#[non_exhaustive].Rejected at startup (
build_shared_servicesrunsDaemonExtensions::check, which runsDataExtensions::checkbefore anything is built):a behaviour for a core type;
a second behaviour for one type;
a type that is not a schema id
create_schemacan store.The last rule exists because
create_schemaderives the id from the name as lowercase with_, so a behaviour keyedteam-spacewould never match a node.Daemon:
build_database_servicesbuilds each database's node service withshared.extensions.data().A behaviour no longer makes its type known to the create path.
ensure_known_node_typeaccepted any type with a behaviour.CoreNodeType::ALL.With
DaemonExtensions::none()andNodeService::new, the registry isNodeBehaviorRegistry::new()exactly, as before.build_unrouted_serviceskeepsNodeService::new: it never serves a database.Acceptance mapping (#3414, typed subtypes and edge fields)
build_shared_servicestakes additionalNodeBehaviors forextendssubtypes of core types. They are registered in each database'sNodeBehaviorRegistry, and a behaviour for a type core already defines is rejected at startup.collectionwith its own behaviour, covering:collection;rebucket_and_validate.Tests
packages/core/src/extensions/fixture_tests.rsis new and added toWATCHED_PATHS. It definesfixture_collection extends collection, whose behaviour refuses amax_membersbelow 1 in its own bucket, a rule thenumbertype 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_membersgoes tofixture_collectionanddescriptiontocollection.queries_for_collection_return_the_subtype: bothquery_nodes_by_type("collection")andCollectionService::get_all_collections_with_countsreturn it.a_collection_retyped_to_the_subtype_is_rebucketed_and_validated: a retype tomax_members: 0is refused and the node keeps its type. A valid retype moves the new field to the subtype's bucket and keepsdescriptionin 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, throughbuild_shared_serviceswith the isolated home and no model):a_subtype_behaviour_is_enforced_in_every_database: two databases, and each refusesmax_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:
a_subtype_node_is_validated…,…retyped…,the_node_service_registers…a_node_service_with_a_behaviour_for_a_core_type_is_refusedbehavior_registryregisters nothinga_behaviour_for_a_core_type_or_a_second…a_behaviour_whose_type_is_not_a_schema_id_is_rejecteda_subtype_without_its_schema_is_an_unknown_typethe_subtypes_fields_are_stored_in_its_own_bucketqueries_for_collection_return_the_subtype,…retyped…NodeService::newa_subtype_behaviour_is_enforced_in_every_databaseDaemonExtensions::behaviordrops itcheck_rejects_a_refused_behaviourDaemonExtensions::checkskips the data checka_behaviour_for_a_core_type_stops_startup,check_rejects_a_refused_behaviourbehavior_registryadds a stray behaviourno_extension_gives_exactly_the_core_registryLocal runs (crate-scoped, under the machine slot):
cargo clippy -p nodespace-core -p nodespace-daemon --all-targets -- -D warnings -D clippy::unused-async: clean.--lib extensions:: unknown_node_type behaviors::tests: 142/142.extension_points_fixture required_extensions services::extensions per_db: 24/24.bun test scripts/: 1441/1441.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 hookDataExtensions/NodeService::new_with_extensions.version).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-collectionandpro-database-settings.create_schemastores those names aspro_collectionandpro_database_settings, and a behaviour keyed with a-is now refused at startup with that explanation.🤖 Generated with Claude Code