Repository navigation
Add the core node type registry, shared envelope, closed schemas and extends-aware rules - #3462
Conversation
Pragmatic Code Review — PR #3462Review Type: Initial Review SummaryThe foundation is sound and a clear net improvement: one registry, one envelope, an ancestry table kept by triggers inside the writing statement, composed behaviours, closed core buckets, a closed field-type enum and the UUID id rule. The trigger algebra is correct for a single-parent tree (I replayed add, remove, re-target, mid-chain delete with cascade, and an One finding blocks: closing the How I verified: read every production file in the diff; ran the lint ( Requirements Check (issue #3439)
Code Review Findings🔴 Critical1. PTY session capture is rejected by the closed
2.
🟡 Important3. The
4. A core schema can gain
5. Two rules still compare exactly, through a constant the lint cannot see
6.
7. Legacy camelCase spellings are still read, and can no longer be stored
8. Re-targeting a type under a root-only base does not check existing nodes
🟢 Suggestions9. The task/project expression indexes now index every row — 📁 10. Two chain resolvers, and 11. Exact comparisons to revisit when the ai-chat and tool subtypes land — 12. Test gaps — no service-level test that re-targets or deletes a schema through Nits
What is solid
RecommendationREQUEST CHANGES. Finding 1 is a functional regression and must be fixed before merge. Finding 2 needs an explicit decision. Findings 3 to 7 are small, local and best folded into this PR; 8 can move to the structural-rules issue if it is named there. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). One blocking finding: the closed ai-chat bucket rejects the four undeclared capture keys that PTY launch and session capture still write. One checklist finding needs a decision (skill.node_types declared as a list of schema ids). Full findings in the review comment above: #3462 (comment)
Review addressed (through
|
| # | Finding | What changed |
|---|---|---|
| 1 🔴 | PTY capture refused by the closed ai-chat bucket |
capture:agent_type and capture:exit_code are declared on ai-chat. capture:started_at / capture:ended_at are no longer written (duplicates of created_at / last_active, as ADR-088 says). New tests: every key build_capture_properties writes is declared by the schema, and finalize_capture backfills a real node through NodeService. |
| 2 🔴 | skill.node_types, tool.source, tool.handler declared against the sheets |
Kept as interim declarations (the alternative is deleting data existing code reads, or doing #3418 / #3450 here). The PR description now lists them, names the issue that removes each, and no longer says nothing departs from the sheets. This one is Michael's call; flagged to him. |
| 3 🟡 | schema ancestry row deletable through the schema API |
create_schema refuses a name that normalizes to a core type id. The delete and retype-out triggers skip core ids. Trigger test and service test added. |
| 4 🟡 | Core schema could gain extends / abstract |
update_schema refuses both on a core schema. is_abstract_type answers from the registry for a core type. Test added. |
| 5 🟡 | Two rules compared exactly through a constant | bulk_create_mentions resolves chat endpoints with is_a_sql; the relationship-target check uses type_is_a. The three wire-shape checks use is_exactly. The lint has a constantComparison pattern with tests. Test: a subtype of ai-chat is refused as a relationship target and dropped by the bulk mention path. |
| 6 🟡 | One read per created node | Covered by #4 for core types; ensure_creatable_in_batch caches the instantiable check and the chain per distinct type in the three bulk loops. |
| 7 🟡 | Legacy camelCase reads | Removed from task_node_to_value and without_promoted, and from the frontend mirror in node-normalize.ts; tests updated. |
| 8 🟡 | Re-target under a root-only base | update_schema refuses it while any node of the type (or a subtype) has a has_child parent. Test added. |
| 9 🟢 | Indexes hold a NULL per node | Now partial on the value being present. The existing planner test (schema_test.rs) still passes under libsql. |
| 10 🟢 | Two chain resolvers | resolve_type_chain and the batch resolver read the ancestry table. |
| 12 🟢 | Test gaps | Service-level re-target and schema-delete test reading type_chain; lint tests for constant comparisons. |
| Nits | validate_task_node and its test deleted; the re-key no longer falls back to a shared namespace (a non-UUID preferred id fails the step); the three search-and-replace doc comments fixed; PR description corrected on what the registry records. |
Not changed
- No compilation errors or warnings #10, in-transaction reads.
ensure_creatableandvalidate_behaviorsstill read through the pooled reader inside a transaction. That matchesresolve_field_ownerson the same paths; switching one of them would make the two disagree about what a transaction sees. Worth doing for both together. - Set up Tauri + Svelte project structure #11,
Priority::applies_to. Still exact. The query service's sort reads each row's own bucket, so ranking a subtype's inheritedpriorityneeds that sort made chain-aware first. Listed in the PR description under "Left exact on purpose", with the agent loop's ai-chat watcher. - Nit,
isA(nodeType, base: string). Left asstring: a user-defined type id is a legitimate base. - Nit,
EdgeField.type. Left open. The schema-management doc gives edge fields a separate, narrower set, and nothing validates their scalar types today.
Re-Review Decision
Decision: RE-REVIEW NEEDED
Rationale: A critical fix, new guards in the schema API and DDL triggers, a changed index definition and a changed chain resolver.
Pragmatic Code Review — PR #3462Review Type: Re-Review Previous Review Summary
How I verified: read every hunk of Status of previous findings
The merge of New findings🟡 ImportantN1. The new refusals in
Nits
RecommendationAPPROVE. The blocking regression is fixed and tested on the real path, the SQL and Rust views of a core type can no longer be made to disagree through the schema API, and the remaining exact comparisons are documented with reasons. Fold N1 into this PR if it is a quick move; it does not need another review round. Finding 2 stays open for Michael's decision on the interim declarations. |
malibio
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.
Re-review addressed (
|
|
Merge queue: #3462 was taken out of the queue — it conflicts with main in: packages/core/src/db/sqlite_store/search.rs. Rebase onto origin/main, push, and re-run |
ddbc670 to
d76e4cf
Compare
|
Branch rewritten as one commit on current |
|
Merge queue: #3462 was taken out of the queue — the merge gate failed on it, rebased onto main. Reproduce with |
d76e4cf to
76f175a
Compare
…extends-aware rules (closes #3439) Lays the foundation of ADR-086: - CoreNodeType registry in nodespace-types: one variant per core type with its parent, abstract flag, category, content role, structural and participation rules, titling and wire shape. Seeded schemas, behaviours, the wire conversion and the frontend plugin list are tested against it. - NodeEnvelope: the generic Node is the envelope and every typed wire struct embeds it. lifecycleStatus is always serialized. - type_ancestry table kept by triggers inside the schema write, so SQL can apply a base type's rule to its subtypes. Root-only triggers and the mention filter resolve through it; task/project indexes cover subtypes. - Behaviours compose through the extends chain; validation, embedding, titling and the collection, person, ai-chat and play rules follow it. - Abstract schemas: create and retype into one are refused on every path. - Closed core schemas: an undeclared key in a core bucket is rejected; fields and itemFields are validated recursively. - Typed clients: the generic update refuses a core field that has a typed update when the request is flagged typed_client. - SchemaField.type and itemType are a closed enum; string is not a type. - Every create path refuses a non-UUID id outside the three named forms; seeded plays and views have fixed literal UUIDs. - scripts/check-node-type-literals.ts fails the push check on a literal node_type comparison in Rust, SQL or TypeScript outside tests. The on-disk shape changes: reset the database. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
76f175a to
36da2c3
Compare
Closes #3439.
Lays the foundation of ADR-086: one registry of core types, one envelope on every wire shape, a type-ancestry table so SQL can apply a base type's rule to its subtypes, abstract types, closed core schemas, a closed field-type vocabulary, and the UUID id rule. The sibling ADR-086 issues build on this.
Kind and category
No new node type. This changes how every core type is registered and validated. The registry (
CoreNodeType,packages/nodespace-types/src/core_type.rs) records for each of the 21 core types that exist today: parent, abstract flag, category, content role, structural rules, participation rules, titling, and wire shape.ai-chatandtoolare registered as they are stored today (concrete, andai-chatstructured because ofmessages[]). #3446, #3448 and #3450 make them abstract bases, add their subtypes andai-chat-message, and move them to their final categories; the registry tests fail until each layer follows.What changed
Registry and envelope (
nodespace-types)CoreNodeTypewithfrom_id,nearest(chain),is_a,is_exactly, and the per-type record.NodeEnvelope: the genericNodeis the envelope, andTaskNode,PersonNode,ProjectNode,QueryNode,AiChatNodeandSchemaNodeembed it.lifecycleStatusis always serialized.node_to_typed_value, the promoted-field lists andtyped_update_fieldsmatch onCoreNodeTypewith no catch-all for core types.SchemaFieldTypeis a closed enum (text,number,boolean,date,datetime,enum,array,object) forSchemaField.typeanditemType.stringis refused with a message namingtext. Edge-field types are unchanged.SchemaNodecarriesabstractandextends.Type-ancestry table (
core/src/db/schema.rs)type_ancestry(node_type, ancestor, depth), one row per (type, ancestor) pair including the type itself.extends-edge writes, so it is updated inside the transaction that writes the schema, on every write path. Core types' rows are seeded from the registry.MustBeRoottypes and resolve through the table, so a subtype ofcollectionis root-only.node_type, so they cover subtypes and stay sparse.resolve_type_chainreads the table, so there is one chain resolver.Chain-aware rules
@picker's exclusions, collection lookups and membership, the person membership exemption, ai-chat reference and retype guards, the settings singleton, play validation and play events all resolve through the chain.scripts/check-node-type-literals.tsfails the push check andtest:scriptson a literalnode_typecomparison in Rust, SQL or TypeScript outside tests.Abstract types
abstracton a schema (create and update). Create and retype into an abstract type are refused in the service on every create path; a query for one returns its subtypes. A type with nodes of its own cannot become abstract.The registry is the authority for core types
extendsandabstractcannot be changed through the schema API, so the ancestry table and the registry cannot disagree.Closed core schemas
custom:/org:/plugin:, or start with_. Subtype buckets and user-defined types stay open.fieldsanditemFieldsare validated recursively.collection.descriptionand atoolschema are declared;playandcheckboxhave behaviours.node-types.mddescribes a different final shape, because the issue that owns the final shape also owns the writer:skill.node_types(a list of schema ids). Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418 replaces it with theapplies_torelationship.tool.handlerandtool.sourceon the basetooltype. Make tool an abstract base with a tool-native subtype and drop source #3450 moveshandlertotool-nativeand removessource.ai-chatcapture:agent_typeandcapture:exit_code. Split ai-chat into an abstract base with ai-chat-native and ai-chat-pty subtypes #3446 renames the capture fields and moves them toai-chat-pty.capture:started_atandcapture:ended_atare no longer written (they duplicatedcreated_atandlast_active).Typed clients
UpdateNodeRequest.typed_client. The Tauriupdate_nodecommand and the dev-proxy set it; the daemon then refuses a generic patch naming a field of a core type that has a typed update (task, person, project, query). The CLI and agent leave it unset and are validated by the same pipeline.Ids
database-settings-singleton.Frontend
NodeEnvelopeis the base interface with a requiredlifecycleStatus; every typed node interface extends it.core-node-types.tsmirrors the registry and is pinned to the Rust source by a test.isAresolves user subtypes through the loaded schemas'extends.useranddocumentplugin definitions are removed.Left exact on purpose
is_exactly/isExactlyremain where a subtype must not match, or where resolving the chain was out of reach:schemameta-type everywhere (nothing can extend it);dateandschema;Priority::applies_to, which rankspriorityonly for a query targeting exactlytaskorproject. A query over a subtype sortspriorityas text; the query service's sort reads each row's own bucket, so ranking a subtype needs that sort made chain-aware first;local_agent_service.rs), which reacts to exactlyai-chatuntil Split ai-chat into an abstract base with ai-chat-native and ai-chat-pty subtypes #3446 adds the subtypes;taskrenders with the generic component.Not in this PR
components/node-types.mddescribes the decided design and this PR moves the code toward it. The interim declarations listed above are the places where the code is not yet at that design.MustBeRootforcollectionandschema(what is enforced today),mentionableandembedded. The other structural rules of ADR-089 (dateas a root, thechildren: nonetypes) and the default-query exclusion are declared and enforced by Declare and enforce children and parent rules per node type #3447 and Make one governance check decide whether an archived node participates anywhere #3443.Database
The on-disk shape changes (new table, new triggers, changed indexes,
textinstead ofstringin stored schemas, UUID ids for seeded plays). Reset the database.Testing
bun run test:changed(all tiers; this diff touches the gate).core_type_registry_test.rs, a daemon RPC test for the typed-client flag, the lint's own tests, and the frontend registry and plugin tests.🤖 Generated with Claude Code