Skip to content

feat: Implement namespaced properties for type-safe node type changes (Issue #794) - #799

Merged
malibio merged 3 commits into
mainfrom
feature/issue-794-namespaced-properties
Jan 7, 2026
Merged

malibio merged 3 commits into
mainfrom
feature/issue-794-namespaced-properties

Conversation

@malibio

@malibio malibio commented Jan 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Implement namespaced properties where each type's properties live under their own namespace
  • When a node's type changes (e.g., task → text), old type's properties remain dormant under their namespace
  • Properties are now stored as properties[node_type][field_name] instead of flat properties[field_name]

Changes

Core Storage Changes

  • Update apply_schema_defaults_with_fields() to write defaults under type namespace
  • Update validate_node_with_fields() to read from type namespace (removed flat fallback)
  • Update property merge in update_node() to deep-merge within type namespaces
  • Update backfill_schema_version() to only add version for types with schema fields
  • Update create_node() to store _schema_version in type namespace

Query Service Changes

  • Update property filters to use namespaced paths (properties.task.status)
  • Update in-memory sorting to use namespaced property access
  • Wildcard queries (*) fall back to flat access since type is unknown

Test Updates

  • All tests updated to use namespaced property format
  • Verify text/date nodes (no schema fields) don't get _schema_version

Benefits

  1. Old type's properties preserved when type changes (dormant, not orphaned)
  2. No property name conflicts between types
  3. Can restore previous type's data if user changes back
  4. Clear separation of concerns
  5. Query paths are type-specific (properties.task.status vs properties.invoice.status)

Test plan

  • All Rust tests pass (678 tests)
  • All frontend tests pass (3431 tests)
  • Quality checks pass (lint, format, clippy)

Closes #794

🤖 Generated with Claude Code

… (Issue #794)

## Summary

When a node's type changes (e.g., `task` → `text`), old type's properties now
remain dormant under their namespace rather than being orphaned or conflicting.
Properties are now stored as `properties[node_type][field_name]` instead of
flat `properties[field_name]`.

## Changes

### Core Storage Changes (node_service.rs)
- Update `apply_schema_defaults_with_fields()` to write defaults under type namespace
- Update `validate_node_with_fields()` to read from type namespace (removed flat fallback)
- Update property merge in `update_node()` and `update_with_version_check()` to
  deep-merge within type namespaces, preserving dormant type properties
- Update `backfill_schema_version()` to only add version for types with schema
  fields, and store in type namespace
- Update `create_node()` to store _schema_version in type namespace
- Update `apply_lazy_migration()` to read version from type namespace

### Query Service Changes (query_service/mod.rs)
- Update `build_property_filter()` to use namespaced paths (`properties.task.status`)
- Update `resolve_field()` to use namespaced paths for non-metadata fields
- Update `compare_nodes_by_field()` for in-memory sorting via namespaced access
- Wildcard queries (*) fall back to flat access since type is unknown at query time

### Test Updates
- Update query_service_test.rs tests to use namespaced property format
- Update nodes_test.rs typed response tests for namespaced properties
- Update version_tracking_tests to verify text/date nodes (no schema fields)
  do not get _schema_version

## Benefits

1. Old type's properties preserved when type changes (dormant, not orphaned)
2. No property name conflicts between types
3. Can restore previous type's data if user changes back
4. Clear separation of concerns
5. Indexes work correctly (`properties.task.completed` vs `properties.invoice.status`)

Closes #794

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@malibio

malibio commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review - PR #799

Review Type: Initial Review
Reviewer: Principal Engineer AI


Summary

This PR implements namespaced properties for type-safe node type changes (Issue #794). The changes correctly move properties from a flat structure (properties.status) to a namespaced structure (properties.task.status), enabling proper property preservation when node types change.

Overall Assessment: This is a solid implementation that correctly addresses the core architectural concern. The changes are well-structured and properly update all affected components. There are a few improvements to consider for long-term maintainability.


Requirements Validation

Phase 1: Core Storage Changes

Criterion Status
Update apply_schema_defaults_with_fields() to write under type namespace ✅
Update update_node() property merge to use type namespace ✅
Update validate_node_with_fields() to read from type namespace ✅
Update create_node() to store properties under type namespace ✅

Phase 2: Query & Index Updates

Criterion Status
Update partial indexes to use namespaced paths ⚠️ See note below
Update query patterns in QueryService for namespaced access ✅
Update any direct property access in handlers ✅

Phase 3: Serialization/Deserialization

Criterion Status
Ensure Node struct properly deserializes namespaced properties ✅
Update any frontend property access patterns ⚠️ See note below
Verify MCP handlers return correct property structure ✅

Phase 4: Quality

Criterion Status
All existing tests updated for namespaced properties ✅
New tests for type change scenarios ❌ Not implemented
New tests for same-property-name different-type scenarios ❌ Not implemented
Code passes bun run quality:fix ✅
Tests pass (bun run test:all) ✅ (678 Rust + 3431 Frontend)

Findings

🟡 Important - Missing Explicit Type Change Tests

Location: packages/core/src/services/node_service.rs (tests module)

The acceptance criteria specifically requests:

  • "New tests for type change scenarios (properties preserved)"
  • "New tests for same-property-name different-type scenarios"

While the existing tests have been updated to use the namespaced format, there are no explicit tests that verify the core value proposition: when a node changes type, the old type's properties are preserved as dormant data.

Recommended test scenarios:

#[tokio::test]
async fn test_type_change_preserves_old_properties() {
    // 1. Create a task node with properties
    // 2. Change type to text
    // 3. Verify task properties still exist under "task" namespace
    // 4. Change type back to task
    // 5. Verify original task properties are restored
}

#[tokio::test]
async fn test_same_property_name_different_types() {
    // Verify task.status and invoice.status don't conflict
}

Engineering Principle: Tests should verify the intent of a feature, not just that the code executes. The namespaced properties feature exists specifically for type-change preservation, which should be explicitly tested.


🟡 Important - Migration Registry Incompatibility

Location: packages/core/src/services/migration_registry.rs:177-185

The MigrationRegistry::apply_migrations() function still reads _schema_version from the flat properties structure:

let current_version = node
    .properties
    .get("_schema_version")  // <-- Reads flat, not namespaced
    .and_then(|v| v.as_u64())

Meanwhile, node_service.rs now stores _schema_version under the type namespace (properties.task._schema_version). This inconsistency means:

  1. Migration registry will fail to find _schema_version for nodes created with the new format
  2. The existing migration registry tests still use flat format and pass, but they test against the old contract

Impact: If migration functions are used (they appear to be for future use), this will break.

Recommendation: Either update MigrationRegistry to read from namespaced format, or document this as a known limitation with a TODO. Since this is pre-release, updating migration_registry.rs to use namespaced access would be cleaner.


🟡 Important - Schema.surql Has Flat _schema_version Field

Location: packages/core/src/db/schema.surql:152

DEFINE FIELD IF NOT EXISTS _schema_version ON TABLE node TYPE int DEFAULT 1;

This defines _schema_version as a top-level field on the node table, not a nested property. This conflicts with the new design where _schema_version is stored under properties.{node_type}._schema_version.

Recommendation: This field definition should either be:

  1. Removed (if versions are only in properties)
  2. Updated to reflect the new architecture
  3. Documented as intentionally kept for backward compatibility

🟢 Suggestion - Code Duplication in update_node Functions

Location:

  • packages/core/src/services/node_service.rs:1873-1898 (update_node)
  • packages/core/src/services/node_service.rs:2070-2095 (update_with_version_check)

The property merge logic is duplicated in both functions (identical 25-line block). Consider extracting to a helper method:

fn deep_merge_namespaced_properties(
    existing: &mut serde_json::Value,
    new: serde_json::Value,
) {
    // Shared deep-merge logic
}

Engineering Principle: DRY (Don't Repeat Yourself) - duplicated logic increases maintenance burden and risk of divergent behavior.


🟢 Suggestion - Frontend Backward Compatibility Layer

Location:

  • packages/desktop-app/src/lib/plugins/core-plugins.ts:163
  • packages/desktop-app/src/lib/types/task-node.ts:267
  • packages/desktop-app/src/lib/components/property-forms/schema-property-form.svelte:132-139

The frontend has backward compatibility code that checks both nested and flat formats:

const taskProps = properties[node.nodeType] as Record<string, unknown> | undefined;
const status = taskProps?.status || properties.status; // Support both nested and flat formats

Per CLAUDE.md pre-release policy: "NO backward compatibility code - Delete old patterns immediately when replaced"

Since this is a clean break with namespaced properties, the flat fallback paths could be removed to simplify the code. However, this is marked as a suggestion since the current code works correctly and removing fallbacks is low-risk cleanup.


🟢 Nit - Comment Documentation

Location: packages/core/src/services/query_service/mod.rs:304-306

The comment block for build_query could be expanded to clarify the wildcard query limitation:

/// Issue #794: Properties are now stored in namespaced format:
/// properties[node_type][field_name] instead of properties[field_name]
/// 
/// NOTE: Wildcard queries (*) cannot use namespaced paths because the
/// node type is unknown at query time. These queries fall back to flat
/// property access, which may return no results for namespaced data.

Test Results

Suite Result
Rust Tests 678 passed, 0 failed
Frontend Tests 3431 passed (per PR description)
Quality Checks Pass

Final Recommendation

REQUEST CHANGES

The implementation is architecturally sound and correctly implements the namespaced property pattern. However, before merge:

  1. Required: Add explicit tests for type-change property preservation (core feature value proposition)
  2. Required: Address the MigrationRegistry incompatibility with namespaced _schema_version
  3. Optional: Clean up schema.surql field definition or document the intent

These changes ensure the implementation is complete and future-proof. The core functionality is correct - these are completeness items aligned with the acceptance criteria.


Review conducted following the Pragmatic Quality framework. Focus on substance over perfection.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

See detailed review comment above. Review status: REQUEST CHANGES

Required before merge:

  1. Add explicit tests for type-change property preservation (acceptance criteria Phase 4)
  2. Fix MigrationRegistry to read _schema_version from namespaced format (or document as known limitation)
  3. Address schema.surql _schema_version field definition conflict

…ssue #794)

## Changes Made

### 🔴 Critical - Added Type Change Tests (Acceptance Criteria Phase 4)
- Added test_type_change_preserves_old_type_properties: Verifies properties are
  preserved as dormant data when node type changes and restored when changed back
- Added test_same_property_name_different_types_no_conflict: Verifies task.status
  and custom.status coexist without conflict
- Added test_updating_current_type_preserves_dormant_properties: Verifies updates
  to current type don't affect dormant properties from previous types

### 🔴 Critical - Fixed MigrationRegistry Namespaced Format
- Updated apply_migrations() to read _schema_version from namespaced location
  (properties[node_type]._schema_version instead of properties._schema_version)
- Updated all test helpers and migration functions to use namespaced format
- Updated doc examples to reflect namespaced property structure

### 🟡 Important - Cleaned Up schema.surql
- Removed flat _schema_version field definition that conflicted with namespaced
  storage format
- Added documentation explaining the namespaced format

### 🟢 Suggestion - Extracted Property Merge Helper
- Created deep_merge_namespaced_properties() helper function
- Eliminated code duplication between update_node() and update_with_version_check()

### 🟢 Suggestion - Removed Frontend Backward Compatibility
- Removed flat property fallback in core-plugins.ts extractMetadata()
- Removed flat property fallback in task-node.ts toTaskNode()
- Removed flat property fallback in schema-property-form.svelte getPropertyValue()

## Test Results
- Rust: 681 tests pass (3 new tests added)
- Frontend: 3431 tests pass
- Quality checks pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@malibio

malibio commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator Author

Review Recommendations Addressed

Summary of Changes

# Severity Recommendation Status
1 🔴 Critical Add explicit tests for type-change property preservation ✅ Addressed
2 🔴 Critical Fix MigrationRegistry namespaced _schema_version ✅ Addressed
3 🟡 Important Clean up schema.surql _schema_version field ✅ Addressed
4 🟢 Suggestion Extract duplicate property merge logic ✅ Addressed
5 🟢 Suggestion Remove frontend backward compatibility code ✅ Addressed
6 🟢 Nit Comment documentation for wildcard queries ⏭️ Skipped (marginal value)

Changes Made

🔴 Critical - Added Type Change Tests (Acceptance Criteria Phase 4)

  • test_type_change_preserves_old_type_properties: Verifies properties are preserved as dormant data when node type changes and restored when changed back
  • test_same_property_name_different_types_no_conflict: Verifies task.status and custom.status coexist without conflict
  • test_updating_current_type_preserves_dormant_properties: Verifies updates to current type don't affect dormant properties

🔴 Critical - Fixed MigrationRegistry Namespaced Format

  • Updated apply_migrations() to read _schema_version from namespaced location
  • Updated all test helpers and migration functions to use namespaced format
  • Updated doc examples to reflect namespaced property structure

🟡 Important - Cleaned Up schema.surql

  • Removed flat _schema_version field definition that conflicted with namespaced storage
  • Added documentation explaining the namespaced format

🟢 Suggestion - Extracted Property Merge Helper

  • Created deep_merge_namespaced_properties() helper function
  • Eliminated code duplication between update_node() and update_with_version_check()

🟢 Suggestion - Removed Frontend Backward Compatibility
Per CLAUDE.md pre-release policy ("NO backward compatibility code"):

  • Removed flat property fallback in core-plugins.ts
  • Removed flat property fallback in task-node.ts
  • Removed flat property fallback in schema-property-form.svelte

Test Results

  • Rust: 681 tests pass (3 new tests added)
  • Frontend: 3,431 tests pass
  • Quality checks: Pass

Skipped Recommendation

#6 - Comment documentation for wildcard queries: The existing comment already explains the Issue #794 changes. Adding more detail about wildcard limitations has marginal value since the code behavior is clear from context.


Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale:

  • Critical (🔴) issues were addressed with significant code changes (MigrationRegistry, new tests)
  • Important (🟡) schema changes were made
  • Multiple frontend files modified
  • The changes span both Rust and TypeScript codebases

Run /pragmatic-code-review to review the new commits and verify all feedback was properly addressed.

@malibio

malibio commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review - PR #799 (Re-Review)

Review Type: Re-Review (Delta Review)
Reviewed Commits: d25c58df..53ce33a3
Reviewer: Principal Engineer AI


Previous Review Summary

The initial review identified 6 recommendations:

# Severity Recommendation Status
1 🔴 Critical Add explicit tests for type-change property preservation ✅ Addressed
2 🔴 Critical Fix MigrationRegistry namespaced _schema_version ✅ Addressed
3 🟡 Important Clean up schema.surql _schema_version field ✅ Addressed
4 🟢 Suggestion Extract duplicate property merge logic ✅ Addressed
5 🟢 Suggestion Remove frontend backward compatibility code ✅ Addressed
6 🟢 Nit Comment documentation for wildcard queries ➡️ Skipped (acceptable)

Summary: 5/6 recommendations properly addressed. The skipped nit is acceptable.


Verification of Addressed Items

1. ✅ Type Change Tests (Critical)

Location: /packages/core/src/services/node_service.rs:8384-8549

Three comprehensive tests were added that verify the core value proposition:

  • test_type_change_preserves_old_type_properties - Validates task->text->task roundtrip preserves properties
  • test_same_property_name_different_types_no_conflict - Validates task.status and custom.status coexist
  • test_updating_current_type_preserves_dormant_properties - Validates updates don't affect dormant namespaces

Assessment: Well-documented tests with clear step-by-step verification. Tests the intent of the feature, not just mechanics.

2. ✅ MigrationRegistry Fix (Critical)

Location: /packages/core/src/services/migration_registry.rs:73-95, 202-238

  • Added get_schema_version() helper that reads from namespaced format
  • Updated apply_migrations() to use the new helper
  • Updated all test helpers and migration functions
  • Updated doc examples to reflect namespaced format

Assessment: Clean implementation with proper abstraction via helper function.

3. ✅ schema.surql Cleanup (Important)

Location: /packages/core/src/db/schema.surql:151-154

  • Removed conflicting DEFINE FIELD IF NOT EXISTS _schema_version statement
  • Added clear documentation explaining the namespaced format

Assessment: Properly resolved the architectural inconsistency.

4. ✅ Property Merge Helper (Suggestion)

Location: /packages/core/src/services/node_service.rs:870-901

  • Created deep_merge_namespaced_properties() static method
  • Well-documented with rustdoc comments
  • Used in both update_node() (line 1907) and update_with_version_check() (line 2081)

Assessment: Eliminates code duplication, follows DRY principle.

5. ✅ Frontend Backward Compatibility Removal (Suggestion)

Locations:

  • /packages/desktop-app/src/lib/plugins/core-plugins.ts:164 - Removed || properties.status fallback
  • /packages/desktop-app/src/lib/types/task-node.ts:267-269 - Now reads only from props?.task
  • /packages/desktop-app/src/lib/components/property-forms/schema-property-form.svelte:132-138 - Returns undefined instead of flat fallback

Assessment: Per CLAUDE.md pre-release policy, backward compatibility code was properly removed.


Requirements Validation (Issue #794)

Phase 1: Core Storage Changes

Criterion Status
Update apply_schema_defaults_with_fields() to write under type namespace ✅
Update update_node() property merge to use type namespace ✅
Update validate_node_with_fields() to read from type namespace ✅
Update create_node() to store properties under type namespace ✅

Phase 2: Query & Index Updates

Criterion Status
Update partial indexes to use namespaced paths ✅
Update query patterns in QueryService for namespaced access ✅
Update any direct property access in handlers ✅

Phase 3: Serialization/Deserialization

Criterion Status
Ensure Node struct properly deserializes namespaced properties ✅
Update any frontend property access patterns ✅
Verify MCP handlers return correct property structure ✅

Phase 4: Quality

Criterion Status
All existing tests updated for namespaced properties ✅
New tests for type change scenarios (properties preserved) ✅
New tests for same-property-name different-type scenarios ✅
Code passes bun run quality:fix ✅
Tests pass (bun run test:all) ✅

New Issues Identified

None. The fixes are clean and do not introduce new problems.


Test Results

Suite Result
Rust Tests 681 passed (3 new tests added)
Frontend Tests 3431 passed
Quality Checks Pass

Final Recommendation

APPROVE ✅

All critical and important issues from the initial review have been properly addressed. The implementation:

  1. Correctly addresses all acceptance criteria from Issue Implement Namespaced Properties for Type-Safe Node Type Changes #794
  2. Adds comprehensive tests for the core value proposition (type-change property preservation)
  3. Fixes architectural inconsistencies (MigrationRegistry, schema.surql)
  4. Improves code quality (DRY principle via helper function, removed backward compat code)
  5. All tests pass with 3 new tests validating the feature

This PR is ready to merge.


Re-review conducted following the Pragmatic Quality framework. Delta review focused on verifying addressed recommendations.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Re-Review Status: APPROVE (via comment)

All critical and important issues from the initial review have been properly addressed. The implementation correctly addresses all acceptance criteria from Issue #794, adds comprehensive tests, and improves code quality.

Recommendation: Ready to merge.

(Note: GitHub prevents self-approval, so this approval is recorded as a comment.)

Resolved conflict in node_service.rs: kept namespaced property format
for backfill_schema_version function (Issue #794).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@malibio
malibio merged commit 35d142b into main Jan 7, 2026
@malibio
malibio deleted the feature/issue-794-namespaced-properties branch January 7, 2026 22:23
malibio added a commit that referenced this pull request Feb 4, 2026
… (Issue #794) (#799)

* feat: Implement namespaced properties for type-safe node type changes (Issue #794)

## Summary

When a node's type changes (e.g., `task` → `text`), old type's properties now
remain dormant under their namespace rather than being orphaned or conflicting.
Properties are now stored as `properties[node_type][field_name]` instead of
flat `properties[field_name]`.

## Changes

### Core Storage Changes (node_service.rs)
- Update `apply_schema_defaults_with_fields()` to write defaults under type namespace
- Update `validate_node_with_fields()` to read from type namespace (removed flat fallback)
- Update property merge in `update_node()` and `update_with_version_check()` to
  deep-merge within type namespaces, preserving dormant type properties
- Update `backfill_schema_version()` to only add version for types with schema
  fields, and store in type namespace
- Update `create_node()` to store _schema_version in type namespace
- Update `apply_lazy_migration()` to read version from type namespace

### Query Service Changes (query_service/mod.rs)
- Update `build_property_filter()` to use namespaced paths (`properties.task.status`)
- Update `resolve_field()` to use namespaced paths for non-metadata fields
- Update `compare_nodes_by_field()` for in-memory sorting via namespaced access
- Wildcard queries (*) fall back to flat access since type is unknown at query time

### Test Updates
- Update query_service_test.rs tests to use namespaced property format
- Update nodes_test.rs typed response tests for namespaced properties
- Update version_tracking_tests to verify text/date nodes (no schema fields)
  do not get _schema_version

## Benefits

1. Old type's properties preserved when type changes (dormant, not orphaned)
2. No property name conflicts between types
3. Can restore previous type's data if user changes back
4. Clear separation of concerns
5. Indexes work correctly (`properties.task.completed` vs `properties.invoice.status`)

Closes #794

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Address code review: Complete namespaced properties implementation (Issue #794)

## Changes Made

### 🔴 Critical - Added Type Change Tests (Acceptance Criteria Phase 4)
- Added test_type_change_preserves_old_type_properties: Verifies properties are
  preserved as dormant data when node type changes and restored when changed back
- Added test_same_property_name_different_types_no_conflict: Verifies task.status
  and custom.status coexist without conflict
- Added test_updating_current_type_preserves_dormant_properties: Verifies updates
  to current type don't affect dormant properties from previous types

### 🔴 Critical - Fixed MigrationRegistry Namespaced Format
- Updated apply_migrations() to read _schema_version from namespaced location
  (properties[node_type]._schema_version instead of properties._schema_version)
- Updated all test helpers and migration functions to use namespaced format
- Updated doc examples to reflect namespaced property structure

### 🟡 Important - Cleaned Up schema.surql
- Removed flat _schema_version field definition that conflicted with namespaced
  storage format
- Added documentation explaining the namespaced format

### 🟢 Suggestion - Extracted Property Merge Helper
- Created deep_merge_namespaced_properties() helper function
- Eliminated code duplication between update_node() and update_with_version_check()

### 🟢 Suggestion - Removed Frontend Backward Compatibility
- Removed flat property fallback in core-plugins.ts extractMetadata()
- Removed flat property fallback in task-node.ts toTaskNode()
- Removed flat property fallback in schema-property-form.svelte getPropertyValue()

## Test Results
- Rust: 681 tests pass (3 new tests added)
- Frontend: 3431 tests pass
- Quality checks pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
… (Issue #794) (#799)

* feat: Implement namespaced properties for type-safe node type changes (Issue #794)

## Summary

When a node's type changes (e.g., `task` → `text`), old type's properties now
remain dormant under their namespace rather than being orphaned or conflicting.
Properties are now stored as `properties[node_type][field_name]` instead of
flat `properties[field_name]`.

## Changes

### Core Storage Changes (node_service.rs)
- Update `apply_schema_defaults_with_fields()` to write defaults under type namespace
- Update `validate_node_with_fields()` to read from type namespace (removed flat fallback)
- Update property merge in `update_node()` and `update_with_version_check()` to
  deep-merge within type namespaces, preserving dormant type properties
- Update `backfill_schema_version()` to only add version for types with schema
  fields, and store in type namespace
- Update `create_node()` to store _schema_version in type namespace
- Update `apply_lazy_migration()` to read version from type namespace

### Query Service Changes (query_service/mod.rs)
- Update `build_property_filter()` to use namespaced paths (`properties.task.status`)
- Update `resolve_field()` to use namespaced paths for non-metadata fields
- Update `compare_nodes_by_field()` for in-memory sorting via namespaced access
- Wildcard queries (*) fall back to flat access since type is unknown at query time

### Test Updates
- Update query_service_test.rs tests to use namespaced property format
- Update nodes_test.rs typed response tests for namespaced properties
- Update version_tracking_tests to verify text/date nodes (no schema fields)
  do not get _schema_version

## Benefits

1. Old type's properties preserved when type changes (dormant, not orphaned)
2. No property name conflicts between types
3. Can restore previous type's data if user changes back
4. Clear separation of concerns
5. Indexes work correctly (`properties.task.completed` vs `properties.invoice.status`)

Closes #794

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Address code review: Complete namespaced properties implementation (Issue #794)

## Changes Made

### 🔴 Critical - Added Type Change Tests (Acceptance Criteria Phase 4)
- Added test_type_change_preserves_old_type_properties: Verifies properties are
  preserved as dormant data when node type changes and restored when changed back
- Added test_same_property_name_different_types_no_conflict: Verifies task.status
  and custom.status coexist without conflict
- Added test_updating_current_type_preserves_dormant_properties: Verifies updates
  to current type don't affect dormant properties from previous types

### 🔴 Critical - Fixed MigrationRegistry Namespaced Format
- Updated apply_migrations() to read _schema_version from namespaced location
  (properties[node_type]._schema_version instead of properties._schema_version)
- Updated all test helpers and migration functions to use namespaced format
- Updated doc examples to reflect namespaced property structure

### 🟡 Important - Cleaned Up schema.surql
- Removed flat _schema_version field definition that conflicted with namespaced
  storage format
- Added documentation explaining the namespaced format

### 🟢 Suggestion - Extracted Property Merge Helper
- Created deep_merge_namespaced_properties() helper function
- Eliminated code duplication between update_node() and update_with_version_check()

### 🟢 Suggestion - Removed Frontend Backward Compatibility
- Removed flat property fallback in core-plugins.ts extractMetadata()
- Removed flat property fallback in task-node.ts toTaskNode()
- Removed flat property fallback in schema-property-form.svelte getPropertyValue()

## Test Results
- Rust: 681 tests pass (3 new tests added)
- Frontend: 3431 tests pass
- Quality checks pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
… (Issue #794) (#799)

* feat: Implement namespaced properties for type-safe node type changes (Issue #794)

## Summary

When a node's type changes (e.g., `task` → `text`), old type's properties now
remain dormant under their namespace rather than being orphaned or conflicting.
Properties are now stored as `properties[node_type][field_name]` instead of
flat `properties[field_name]`.

## Changes

### Core Storage Changes (node_service.rs)
- Update `apply_schema_defaults_with_fields()` to write defaults under type namespace
- Update `validate_node_with_fields()` to read from type namespace (removed flat fallback)
- Update property merge in `update_node()` and `update_with_version_check()` to
  deep-merge within type namespaces, preserving dormant type properties
- Update `backfill_schema_version()` to only add version for types with schema
  fields, and store in type namespace
- Update `create_node()` to store _schema_version in type namespace
- Update `apply_lazy_migration()` to read version from type namespace

### Query Service Changes (query_service/mod.rs)
- Update `build_property_filter()` to use namespaced paths (`properties.task.status`)
- Update `resolve_field()` to use namespaced paths for non-metadata fields
- Update `compare_nodes_by_field()` for in-memory sorting via namespaced access
- Wildcard queries (*) fall back to flat access since type is unknown at query time

### Test Updates
- Update query_service_test.rs tests to use namespaced property format
- Update nodes_test.rs typed response tests for namespaced properties
- Update version_tracking_tests to verify text/date nodes (no schema fields)
  do not get _schema_version

## Benefits

1. Old type's properties preserved when type changes (dormant, not orphaned)
2. No property name conflicts between types
3. Can restore previous type's data if user changes back
4. Clear separation of concerns
5. Indexes work correctly (`properties.task.completed` vs `properties.invoice.status`)

Closes #794

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Address code review: Complete namespaced properties implementation (Issue #794)

## Changes Made

### 🔴 Critical - Added Type Change Tests (Acceptance Criteria Phase 4)
- Added test_type_change_preserves_old_type_properties: Verifies properties are
  preserved as dormant data when node type changes and restored when changed back
- Added test_same_property_name_different_types_no_conflict: Verifies task.status
  and custom.status coexist without conflict
- Added test_updating_current_type_preserves_dormant_properties: Verifies updates
  to current type don't affect dormant properties from previous types

### 🔴 Critical - Fixed MigrationRegistry Namespaced Format
- Updated apply_migrations() to read _schema_version from namespaced location
  (properties[node_type]._schema_version instead of properties._schema_version)
- Updated all test helpers and migration functions to use namespaced format
- Updated doc examples to reflect namespaced property structure

### 🟡 Important - Cleaned Up schema.surql
- Removed flat _schema_version field definition that conflicted with namespaced
  storage format
- Added documentation explaining the namespaced format

### 🟢 Suggestion - Extracted Property Merge Helper
- Created deep_merge_namespaced_properties() helper function
- Eliminated code duplication between update_node() and update_with_version_check()

### 🟢 Suggestion - Removed Frontend Backward Compatibility
- Removed flat property fallback in core-plugins.ts extractMetadata()
- Removed flat property fallback in task-node.ts toTaskNode()
- Removed flat property fallback in schema-property-form.svelte getPropertyValue()

## Test Results
- Rust: 681 tests pass (3 new tests added)
- Frontend: 3431 tests pass
- Quality checks pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
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.

Implement Namespaced Properties for Type-Safe Node Type Changes

1 participant