Repository navigation
Description
Overview
SchemaRelationship's name/reverse_name pair is the schema-definition-level naming for both ends of a relationship (e.g. tasks/project, extends/extended_by — see packages/nodespace-types/src/schema.rs). But the relationship edge table (packages/core/src/db/schema.rs) has only a single relationship_type TEXT column — it stores name (the declaring side's label) directly as relationship_type, and reverse_name only inside the row's serialized properties JSON blob (set_schema_declarations, packages/core/src/db/sqlite_store/relationships.rs, serializes the full SchemaRelationship struct into properties). There is no column a query can use to find or filter edges by their reverse label.
This is worse than just "one extra JSON-decode step" for two of NodeSpace's four built-in structural relationships (has_child, member_of, mentions, has_role — packages/core/src/models/schema.rs's BUILTIN_RELATIONSHIP_NAMES): those were never migrated onto the SchemaRelationship naming convention at all. They predate it, are declared as bare reserved strings, and never get a properties blob written with a reverse_name populated — so for a built-in relationship, the reverse name isn't just hard to query, it doesn't exist anywhere as data at all. has_child's reverse direction (child → parent) is reachable today only through hardcoded, relationship-specific Rust methods (NodeService::hierarchy's get_parent/get_children), not through any generic, named, relationship-table-level mechanism.
Ownership principle this issue extends, not introduces: per ../nodespace-docs/decisions/070-schema-relationship-declarations-are-edges.md (ADR-070), relationship data belongs to the relationship table, never to either endpoint's schema — SchemaNode.relationships is a read-time hydration/projection over that table's rows, never storage itself. This issue is squarely a fix to that shared table's column shape (adding reverse_relationship_type alongside relationship_type), consistent with ADR-070's ownership model, not a change to it or a departure from it.
Problem Statement
Anything that wants to do generic, named relationship traversal — not hardcoded per-relationship Rust methods, but "resolve the edge with reverse name X" — has no column to query against. Concretely, this blocks the playbook engine's Play-condition path resolver (graph_resolver.rs) from ever supporting "find my parent via has_child" as a named path segment the way it already supports forward traversal of any SchemaRelationship-declared relationship by name.
Proposed Solution
Add a reverse_relationship_type TEXT column to the relationship table, in packages/core/src/db/schema.rs's SCHEMA_SQL:
Updated by #2688. This issue originally specified a
v006_...migration followingv004_schema_relationship_edges.rs. That ladder no longer exists — #2688 collapsed it into a single current-shape bootstrap, andCLAUDE.mdnow states there is no migration ladder and no schema version. Add the column to the bootstrap DDL and reset the database.
- For
SchemaRelationship-declared edges (tasks/project,extends/extended_by, and any user-declared relationship),set_schema_declarations(and its transactional counterpartset_schema_declarations_in_tx) writesrel.reverse_nameinto this column at the same time it writesrel.nameintorelationship_type— no more relying on apropertiesJSON decode to learn the reverse label. - For the four built-in structural relationships, the reverse names are decided (see the spec-update comment for rationale):
has_child→child_of,member_of→has_member,mentions→mentioned_by,has_role→role_of. Each is wired at the write sites that create those edges:has_child→child_ofis the immediately-needed case (motivated by a Play-condition use case in a separate issue);member_of,mentions,has_roleshould each get a reverse name decided during this issue's implementation, for consistency, even if no consumer needs them immediately. - Per this repo's pre-release policy (see
CLAUDE.md— no backward-compatibility code, no data migrations/backfills), this issue adds the column and populates it going forward from write paths only. It does not backfillreverse_relationship_typefor existing rows from theirpropertiesJSON — NodeSpace has no production data to preserve; reset the database to pick up the new column being populated correctly from write time onward.
Architecture Impact
No existing ADR documents the relationship table's column shape as fixed or asserts properties-JSON-only storage for reverse_name is intentional — this is closing an oversight from when SchemaRelationship's name/reverse_name pair was introduced, not a reversal of a documented decision.
Companion nodespace-docs update required: ../nodespace-docs/components/typed-relationships.md (lines 19-21, its "One stored edge, two readings" section at lines 56-73) currently documents reverseName as real and load-bearing ("makes an edge read naturally from the side that did not declare it") but describes it only as a properties-JSON field, matching today's actual (gap-having) implementation — it never states the reverse name is recoverable only via a JSON decode, not a queryable column, and it says nothing about built-in structural relationships (has_child etc.) having no reverse name as data at all, since that document is scoped to schema-declared relationships. Once this issue lands, that section must be updated to: (1) state reverse_relationship_type is a first-class column, not something requiring a properties decode, and (2) document the decided reverse names for all four built-in structural relationships. ../nodespace-docs/architecture/data-layer.md (lines 14, 38, 65, 79) should also gain the new column in its relationship table description.
Acceptance Criteria
-
relationshiptable gains areverse_relationship_type TEXTcolumn inpackages/core/src/db/schema.rs'sSCHEMA_SQL -
set_schema_declarations/set_schema_declarations_in_txwritereverse_nameinto the new column for everySchemaRelationship-declared edge -
has_childedges are written withreverse_relationship_type = 'child_of'at every site that creates ahas_childedge (confirm all call sites — likelyhierarchy.rs's child-creation/move paths) -
member_of,mentions,has_roleeach get a decided, documented reverse name, written at their respective edge-creation sites - New column is queryable/indexed appropriately for lookup by reverse name (mirror the existing
idx_rel_type/idx_rel_in/idx_rel_outindex pattern if a new index is warranted) - No backfill of existing rows — confirmed via test that a fresh database populates the column correctly from write time, not via any migration-time backfill logic
-
../nodespace-docs/components/typed-relationships.mdand../nodespace-docs/architecture/data-layer.mdupdated per Architecture Impact above - Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Technical Specifications
Reference Files
packages/core/src/db/schema.rs— the single current-shape schema bootstrap; holds therelationshiptable DDL and is where the new column goespackages/core/src/db/sqlite_store/relationships.rs—set_schema_declarations(~line 1547),set_schema_declarations_in_tx(~line 1664) — writerelationship_typefromrel.nametoday; must also write the new column fromrel.reverse_namepackages/nodespace-types/src/schema.rs(~line 238-260) —SchemaRelationship.name/reverse_name— the existing schema-definition-level pair this column now mirrors at the storage levelpackages/core/src/models/schema.rs(~line 56) —BUILTIN_RELATIONSHIP_NAMES— the four structural relationships needing decided reverse namespackages/core/src/services/node_service/hierarchy.rs—get_parent/get_children,create_parent_edge/create_parent_edge_in_tx—has_childedge-creation sites needing the new column populated../nodespace-docs/decisions/070-schema-relationship-declarations-are-edges.md(ADR-070) — the ownership principle (relationshiptable, not either schema, owns relationship data) this issue's fix is consistent with../nodespace-docs/components/typed-relationships.md(lines 19-21, 56-73) — needs updating per Architecture Impact above../nodespace-docs/architecture/data-layer.md(lines 14, 38, 65, 79) — needs updating per Architecture Impact above
Dependencies
None — this can land independently.
Related Issues
- Seed a core Play that completes a parent task when all its children are done #2636 (seed a core Play that completes a parent task when all children are done) — depends on
has_child's reverse name (child_of) existing as real, queryable data before the playbook engine's path resolver can support reverse traversal by name
Non-Goals
- Backfilling
reverse_relationship_typefor existing rows — explicitly out of scope per this repo's no-data-migration policy - Adding reverse-traversal support to
graph_resolver.rs's Play-condition path resolver itself — that consumer-side work belongs to Seed a core Play that completes a parent task when all its children are done #2636, not this issue, which only makes the reverse name exist as queryable data
Activity
malibio commentedon Sep 17, 2026
Baseline before implementation — Frontend: 247 test files passed, 5085 tests passed (117.70s).
Collapse the five-step migration ladder into a single current-shape s…
malibio commentedon Sep 17, 2026
Spec update following #2688
The
v006migration this issue calls for no longer exists as a concept. #2688 collapsed the five-step migration ladder into a single current-shape bootstrap (packages/core/src/db/schema.rs), deletingv001–v005, theuser_versionratchet, and the backup system.CLAUDE.mdnow states explicitly that there is no migration ladder and no schema version.This issue's Technical Specifications cited
v004_schema_relationship_edges.rsas the precedent migration to follow. That file was a data migration — exactly what the no-data-migration policy bans — and following it faithfully here would have meant writing a backfill ofreverse_relationship_typefrom existingpropertiesJSON. That was the trigger for filing #2688.Restated acceptance criteria
The first criterion:
becomes:
The "no backfill of existing rows" criterion stands unchanged and is now structurally enforced — there is no migration mechanism left that could backfill. Reset the database to pick up the new column.
All other criteria are unaffected.
Reverse names for the four built-in structural relationships
The issue leaves
member_of,mentions, andhas_roleto be decided during implementation. Recording the decision here rather than only in a commit, since these become user-visible query keys once #2641 lands and renaming one later is a breaking change to every call site:has_childchild_of(fixed by this issue)member_ofhas_membermentionsmentioned_byhas_rolerole_ofRule:
has_X→X_of, verbs take the passive. This makeshas_child/child_ofandhas_role/role_ofinvert identically.member_of→has_membernecessarily breaks that pattern (it is already named from the member's side);containswas considered and rejected as too easily confused withhas_child, which is the actual containment/outline edge.These are only the built-ins. Schema-declared relationships already carry an author-supplied
SchemaRelationship.reverse_name, which is required rather than derived precisely because naming an inverse is a modeling decision — soset_schema_declarationsjust writes that value into the new column. No derivation, no lookup table for user relationships.Scope note
17 production INSERT sites write
relationship_typetoday (13 hardcode a built-in as a SQL literal, 2 are generic paths takingrel_typeas a parameter, 2 areset_schema_declarations), plus 2 test-fixture sites. The issue's "likelyhierarchy.rs's child-creation/move paths" understates this — the sites are spread acrosssqlite_store/nodes.rs,sqlite_store/relationships.rs, andservices/node_service/hierarchy.rs.