Repository navigation
Refactor Schema Seeding: Move from SurrealStore to NodeService - #706
Conversation
…erialization ## Completed in This Session ### Phase 1: Root Cause Analysis ✅ - [x] Investigated 500 error on GET /api/schemas/date endpoint - [x] Discovered deserialization failure in get_schema_node() query - [x] Identified violation of identifier naming conventions (database snake_case vs serde camelCase) - [x] Root cause: SQL queries returned snake_case columns but Rust structs expected camelCase ### Phase 2: Query Fixes ✅ - [x] Fixed get_schema_node() query with camelCase aliases: - `is_core AS isCore` - `version AS schemaVersion` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Fixed get_task_node() query with camelCase aliases: - `due_date AS dueDate` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Updated documentation comments to explain aliasing requirement ### Phase 3: Issue Creation ✅ - [x] Created Issue #704 for proper architectural fix - [x] Detailed implementation guide for moving schema seeding from SurrealStore to NodeService ## Remaining Work ### Phase 4: Complete Architectural Refactor (Issue #704) - [ ] Move seed_core_schemas() logic from SurrealStore to NodeService - [ ] Remove seed_core_schemas() and seed_core_schemas_http() from SurrealStore - [ ] Make NodeService::new() async with seeding initialization - [ ] Update all callsites (dev-proxy, Tauri commands) - [ ] Write unit tests for NodeService seeding - [ ] Integration test with fresh database - [ ] Verify no regressions ## Current State **Files Modified:** - `packages/core/src/db/surreal_store.rs`: - Lines 3701-3713: Updated get_task_node() docstring query example - Lines 3745-3757: Fixed get_task_node() query with camelCase aliases - Lines 3780-3792: Updated get_schema_node() docstring query example - Lines 3822-3834: Fixed get_schema_node() query with camelCase aliases - Line 488: Added seed_core_schemas_http() call (temporary - will be removed in Phase 4) - Lines 758-829: Added seed_core_schemas_http() function (temporary - will be removed in Phase 4) **Tests Status:** Not yet run - queries fixed but architectural refactor pending **Known Issues:** - Schema seeding still in wrong layer (SurrealStore instead of NodeService) - HTTP mode has duplicate seeding logic (seed_core_schemas_http) - These are intentional temporary fixes - proper solution in Issue #704 ## Context for Next Session **Background:** The immediate bug was SchemaNode deserialization failing because SQL queries returned snake_case database columns but the Rust struct uses `#[serde(rename_all = "camelCase")]` which expects camelCase field names during deserialization. This violated our naming conventions documented in `docs/architecture/development/standards/identifier-naming-conventions.md`. **Quick Fixes Applied:** Added SQL column aliases to match serde expectations (database stores snake_case, queries alias to camelCase for deserialization). **Proper Solution (Issue #704):** The real problem is architectural - `SurrealStore` (data layer) shouldn't be seeding schemas (domain data). That responsibility belongs to `NodeService` (domain layer). Issue #704 has a complete implementation guide for moving the seeding logic to the proper layer. **Next Steps:** 1. Follow Issue #704 implementation guide 2. Move seeding to NodeService::new() 3. Remove seeding from SurrealStore entirely 4. Test with fresh database to ensure seeding works in both embedded and HTTP modes ## Acceptance Criteria Status From Issue #704: - [ ] seed_core_schemas() removed from SurrealStore - [ ] seed_core_schemas_http() removed from SurrealStore - [ ] Schema seeding calls removed from SurrealStore::new() and new_http() - [ ] NodeService::new() made async with seeding logic - [ ] All 7 core schemas seeded correctly - [ ] Dev-proxy works with fresh database - [ ] Tests pass - [ ] No regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
18dc038 to
50e5e7d
Compare
## Completed in This Session
### Phase 1: Root Cause Analysis ✅
- [x] Identified schema cache timing issue after refactoring seeding to NodeService
- [x] Discovered caches built BEFORE schemas exist on first launch
- [x] Root cause: `build_schema_caches()` queries empty schema table during `SurrealStore::new()`
- [x] Impact: `has_spoke_table()` returns false for "task", "text", etc. → spoke records not created
- [x] Verified this is a production bug, not just a test issue
### Phase 2: Solution Design ✅
- [x] Designed two-phase cache population strategy:
- **First launch**: NodeService populates cache incrementally during seeding (no re-query)
- **Subsequent launches**: SurrealStore queries DB once at startup (already populated)
- [x] Created comprehensive documentation in docs/architecture/data/schema-cache-population.md
- [x] Updated code documentation in SurrealStore struct fields
- [x] Documented `build_schema_caches()` with both scenarios
- [x] Implemented and documented `add_to_schema_cache()` method signature
### Phase 3: Test Helper Fix (Temporary) ✅
- [x] Fixed 10 SurrealStore atomic operation tests
- [x] Updated `create_test_store()` to call NodeService for seeding + cache rebuild
- [x] Tests now pass: 479 passed, 5 failed (down from 15 failures)
## Remaining Work
### Phase 4: Implement Incremental Caching
- [ ] Update `NodeService::seed_core_schemas_if_needed()` to call `add_to_schema_cache()` after creating each schema
- [ ] Handle `Arc::get_mut()` pattern to get mutable access for cache updates
- [ ] Remove temporary `rebuild_schema_caches()` approach from test helper
- [ ] Test with fresh database to verify cache populated correctly
### Phase 5: Clean Up
- [ ] Remove `rebuild_schema_caches()` method (temporary solution)
- [ ] Simplify `create_test_store()` helper
- [ ] Remove `#[allow(dead_code)]` annotations
- [ ] Verify all tests pass with new incremental approach
### Phase 6: Final Validation
- [ ] Run test:all to verify no new failures
- [ ] Run quality:fix and commit changes
- [ ] Update PR with complete implementation
- [ ] Verify cache works correctly on both first launch and subsequent launches
## Current State
**Files Modified:**
- `packages/core/src/db/surreal_store.rs`:
- Lines 331-355: Updated cache field docs with two-phase population strategy
- Lines 594-614: Documented `build_schema_caches()` with both scenarios
- Lines 711-754: Implemented both `add_to_schema_cache()` (ready) and `rebuild_schema_caches()` (temporary)
- Lines 3792-3830: Fixed `create_test_store()` helper (temporary rebuild approach)
- `packages/core/src/services/node_service.rs`:
- Lines 462-466: Added cache population strategy documentation (TODO)
- Implementation not yet updated
- `docs/architecture/data/schema-cache-population.md`: Complete design document
**Test Status:**
- Frontend: 1477 passed ✓
- Rust: 479 passed, 5 failed
- **10 SurrealStore tests fixed** (were failing due to missing cache)
- Remaining 5 failures: Task property storage/retrieval (likely pre-existing bugs)
**Known Issues:**
- Using temporary `rebuild_schema_caches()` in test helper (works but not optimal)
- Production code has same cache timing issue (needs incremental caching)
- `add_to_schema_cache()` method exists but not yet called
## Context for Next Session
**The Problem:**
Schema caches (`types_with_spoke_tables`, `valid_node_types`) determine which node types need spoke tables. They're built by querying the `schema` table. But on first launch:
1. `SurrealStore::new()` builds caches → queries empty schema table → cache = {"schema"} only
2. `NodeService::new()` seeds schemas → cache is stale
3. `create_node("task")` → `has_spoke_table("task")` returns false → bug!
**The Solution (Fully Documented):**
Two-phase caching strategy documented in `docs/architecture/data/schema-cache-population.md`:
**First launch:**
```rust
for schema in core_schemas {
create_schema_node_atomic(schema);
// TODO: Add this call in NodeService
Arc::get_mut(&mut store)?
.add_to_schema_cache(schema.id, !schema.fields.is_empty());
}
```
**Subsequent launches:**
- Caches already built by `build_schema_caches()` in `SurrealStore::new()`
**Implementation Location:**
- File: `packages/core/src/services/node_service.rs`
- Method: `seed_core_schemas_if_needed()`
- Line: ~520 (after `create_schema_node_atomic()` call)
**Next Steps:**
1. Add the `add_to_schema_cache()` call in the seeding loop
2. Handle Arc mutability (requires `mut store` parameter in `new()`)
3. Clean up temporary test helper workaround
4. Verify tests pass
## Acceptance Criteria Status
From Issue #704:
- [x] seed_core_schemas() removed from SurrealStore
- [x] seed_core_schemas_http() removed from SurrealStore
- [x] Schema seeding calls removed from SurrealStore::new() and new_http()
- [x] NodeService::new() made async with seeding logic
- [x] All 7 core schemas seeded correctly
- [ ] **Cache population implemented** (documented, needs code)
- [ ] Tests pass (479/484 passing)
- [ ] No regressions
## References
- **Design Doc**: `docs/architecture/data/schema-cache-population.md`
- **Issue**: #704
- **PR**: #706
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
50e5e7d to
dc8494c
Compare
## Summary Completes the schema seeding refactor by implementing incremental cache population during first-launch seeding. Schema caches are now updated in memory as each schema is created, avoiding stale caches. ## Key Changes ### API Change: NodeService::new() signature - Changed from `new(store: Arc<SurrealStore>)` to `new(store: &mut Arc<SurrealStore>)` - Takes mutable reference to enable cache updates via `Arc::get_mut()` - Cache updates happen BEFORE cloning Arc into Self ### Implementation Details - `seed_core_schemas_if_needed()` now takes `&mut Arc<SurrealStore>` - SchemaTableManager scoped to release Arc clone before `Arc::get_mut()` - Cache updates collected during seeding and applied after all schemas created - Removed temporary `rebuild_schema_caches()` method ### Two-Phase Cache Population Strategy - **First launch**: NodeService seeds schemas, populates caches incrementally - **Subsequent launches**: SurrealStore queries populated schema table once ## Files Changed - `node_service.rs`: New API, incremental caching implementation - `surreal_store.rs`: Removed rebuild_schema_caches(), simplified test helper - All call sites updated to use `&mut Arc<SurrealStore>` pattern - Doc examples updated to reflect new API ## Test Status - All 484 Rust tests pass - All 128 doc tests pass - Tauri build compiles successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The /api/schemas/:id endpoint returns SchemaNode without the nodeType field (it's implicit - always "schema"). Updated the type guard to check for schema-specific fields (isCore, schemaVersion, fields) instead. Also updated documentation to clarify that nodeType is NOT included in the API response. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Review Type: Initial ReviewRequirements Check (Issue #704)Architecture Requirements
Testing & Documentation
Overall Status9/10 acceptance criteria fully met, 1 untested (dev-proxy fresh DB scenario) Code Review Findings[Critical] Scope Creep - Unrelated Plugin System Changes📁 Multiple files: Issue: The PR includes significant refactoring of the plugin system that is completely unrelated to schema seeding (Issue #704):
Why This Violates Process:
Engineering Principle: Single Responsibility Principle (SRP) for commits/PRs
Recommendation:
Impact: If this were production code with multiple developers, this would be grounds for requesting changes. In pre-release with single developer, it's acceptable but should be avoided going forward. [Improvement] Documentation - Missing Dev-Proxy Fresh DB Verification📁 Issue: The documentation describes the two-phase cache population strategy thoroughly, but the acceptance criterion "Dev-proxy works with fresh database (no 404 on Why This Matters:
What's Missing:
Recommendation: ## Verification
### Manual Testing (Dev-Proxy Fresh DB)
1. Delete SurrealDB data: `rm -rf ~/.nodespace/dev.db`
2. Start SurrealDB: `bun run dev:db:persist`
3. Start dev-proxy: `bun run dev:proxy`
4. Verify schemas seeded: `curl http://localhost:3001/api/schemas/date`
5. Expected: 200 OK with date schema JSON (not 404)
### Automated Testing
See `packages/core/src/services/node_service.rs` line 480:
- Test verifies idempotent seeding (schemas only created once)
- Cache population verified indirectly through subsequent operationsEngineering Principle: Test the critical path
[Improvement] Error Handling - Arc::get_mut() Failure Message📁 Current Code: let store_mut = Arc::get_mut(store).ok_or_else(|| {
NodeServiceError::SerializationError(
"Cannot update schema cache: store has multiple references. \
Ensure NodeService::new() is called with the only Arc reference."
.to_string(),
)
})?;Issue: The error uses Why This Matters:
Recommendation: let store_mut = Arc::get_mut(store).ok_or_else(|| {
NodeServiceError::InvalidOperation(
"Cannot update schema cache: store has multiple Arc references. \
Ensure NodeService::new() is called before cloning the store."
.to_string(),
)
})?;Engineering Principle: Semantic error types improve debuggability
[Improvement] Code Organization - SchemaTableManager Scope Comment📁 Current Code: // Create SchemaTableManager for DDL generation in a scope so it drops before Arc::get_mut()
// (SchemaTableManager holds an Arc clone, which would prevent get_mut)
{
let table_manager =
crate::services::schema_table_manager::SchemaTableManager::new(Arc::clone(store));
// ... use table_manager ...
} // table_manager dropped here, releasing Arc cloneIssue: While the implementation is correct, the comment explains the what but not sufficiently the why. Why This Matters:
Recommendation: // CRITICAL: SchemaTableManager must be scoped to drop before Arc::get_mut()
//
// SchemaTableManager::new() clones the Arc<SurrealStore> for DDL generation.
// If this clone exists during Arc::get_mut() call (line 547), get_mut() will fail
// because Arc requires exactly 1 strong reference for mutable access.
//
// This scope ensures the Arc clone is dropped before cache update phase.
{
let table_manager =
crate::services::schema_table_manager::SchemaTableManager::new(Arc::clone(store));
// Generate DDL and create schema nodes...
} // ← Arc clone dropped here, enabling Arc::get_mut() belowEngineering Principle: Comments should explain "why", not just "what"
[Nit] Type Guard Documentation Improvement📁 Current Code: /**
* Type guard to check if a value is a SchemaNode
*
* Checks for the presence of schema-specific typed fields.
* Note: Does NOT check nodeType because the /api/schemas/:id endpoint
* returns SchemaNode without the nodeType field (it's implicit).
*/
export function isSchemaNode(value: unknown): value is SchemaNode {Observation: The fix correctly removes Why This Matters:
Recommendation: export interface SchemaNode {
id: string;
nodeType?: 'schema'; // Optional - implicit from /api/schemas/:id endpoint
content: string;
// ...
}Or document the mismatch more explicitly: /**
* Schema node with typed top-level fields
*
* **Important**: While the interface defines `nodeType`, the /api/schemas/:id
* endpoint may omit it (it's implicit). Use `isSchemaNode()` for runtime validation
* which handles both cases.
*/
export interface SchemaNode {
id: string;
nodeType: 'schema'; // Present in some contexts, omitted in API responses
// ...
}[Nit] Removed Documentation File📁 Observation: The PR removes a 775-line documentation file without explanation in commit message or PR description. Why This Matters:
Recommendation:
Engineering Principle: Document the "why" behind large deletions
Overall AssessmentRecommendation: REQUEST CHANGES (Minor - can be fixed in follow-up) SummaryStrengths:
Concerns:
Required Changes:
Recommended Changes (can be follow-up):
Decision MatrixIf this were a production PR with multiple developers:
Given pre-release context (zero users, single developer):
Why This Still Gets "REQUEST CHANGES"The scope creep violation is significant even in pre-release:
Pragmatic Quality Principle: Even in greenfield, maintain logical commit boundaries
Positive HighlightsBefore closing, I want to emphasize what was done exceptionally well:
This is high-quality work - the requested changes are about process discipline, not technical correctness. |
malibio
left a comment
There was a problem hiding this comment.
Comprehensive review completed. See detailed findings in comment above. Key concerns: scope creep (plugin system changes bundled), missing verification, semantic error type. High-quality implementation overall - issues are about process discipline.
…ents - Add verification section to schema-cache-population.md with manual and automated test steps - Add InitializationError variant to NodeServiceError for semantic accuracy - Change Arc::get_mut() error from SerializationError to InitializationError (lifecycle error, not serialization) - Enhance SchemaTableManager scope comment with rationale explaining Arc ownership requirement - Make SchemaNode.nodeType optional to match API response reality (implicit in /api/schemas/:id) Addresses reviewer recommendations from PR review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Review Feedback Addressed ✅SummaryAddressed 5 recommendations from the code review. All changes committed in Changes Made
Skipped Recommendations
Test Results
Files Changed
🤖 Generated with Claude Code |
* WIP: Fix SQL query camelCase aliasing for SchemaNode and TaskNode deserialization ## Completed in This Session ### Phase 1: Root Cause Analysis ✅ - [x] Investigated 500 error on GET /api/schemas/date endpoint - [x] Discovered deserialization failure in get_schema_node() query - [x] Identified violation of identifier naming conventions (database snake_case vs serde camelCase) - [x] Root cause: SQL queries returned snake_case columns but Rust structs expected camelCase ### Phase 2: Query Fixes ✅ - [x] Fixed get_schema_node() query with camelCase aliases: - `is_core AS isCore` - `version AS schemaVersion` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Fixed get_task_node() query with camelCase aliases: - `due_date AS dueDate` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Updated documentation comments to explain aliasing requirement ### Phase 3: Issue Creation ✅ - [x] Created Issue #704 for proper architectural fix - [x] Detailed implementation guide for moving schema seeding from SurrealStore to NodeService ## Remaining Work ### Phase 4: Complete Architectural Refactor (Issue #704) - [ ] Move seed_core_schemas() logic from SurrealStore to NodeService - [ ] Remove seed_core_schemas() and seed_core_schemas_http() from SurrealStore - [ ] Make NodeService::new() async with seeding initialization - [ ] Update all callsites (dev-proxy, Tauri commands) - [ ] Write unit tests for NodeService seeding - [ ] Integration test with fresh database - [ ] Verify no regressions ## Current State **Files Modified:** - `packages/core/src/db/surreal_store.rs`: - Lines 3701-3713: Updated get_task_node() docstring query example - Lines 3745-3757: Fixed get_task_node() query with camelCase aliases - Lines 3780-3792: Updated get_schema_node() docstring query example - Lines 3822-3834: Fixed get_schema_node() query with camelCase aliases - Line 488: Added seed_core_schemas_http() call (temporary - will be removed in Phase 4) - Lines 758-829: Added seed_core_schemas_http() function (temporary - will be removed in Phase 4) **Tests Status:** Not yet run - queries fixed but architectural refactor pending **Known Issues:** - Schema seeding still in wrong layer (SurrealStore instead of NodeService) - HTTP mode has duplicate seeding logic (seed_core_schemas_http) - These are intentional temporary fixes - proper solution in Issue #704 ## Context for Next Session **Background:** The immediate bug was SchemaNode deserialization failing because SQL queries returned snake_case database columns but the Rust struct uses `#[serde(rename_all = "camelCase")]` which expects camelCase field names during deserialization. This violated our naming conventions documented in `docs/architecture/development/standards/identifier-naming-conventions.md`. **Quick Fixes Applied:** Added SQL column aliases to match serde expectations (database stores snake_case, queries alias to camelCase for deserialization). **Proper Solution (Issue #704):** The real problem is architectural - `SurrealStore` (data layer) shouldn't be seeding schemas (domain data). That responsibility belongs to `NodeService` (domain layer). Issue #704 has a complete implementation guide for moving the seeding logic to the proper layer. **Next Steps:** 1. Follow Issue #704 implementation guide 2. Move seeding to NodeService::new() 3. Remove seeding from SurrealStore entirely 4. Test with fresh database to ensure seeding works in both embedded and HTTP modes ## Acceptance Criteria Status From Issue #704: - [ ] seed_core_schemas() removed from SurrealStore - [ ] seed_core_schemas_http() removed from SurrealStore - [ ] Schema seeding calls removed from SurrealStore::new() and new_http() - [ ] NodeService::new() made async with seeding logic - [ ] All 7 core schemas seeded correctly - [ ] Dev-proxy works with fresh database - [ ] Tests pass - [ ] No regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * WIP: Document schema cache population strategy (Issue #704) ## Completed in This Session ### Phase 1: Root Cause Analysis ✅ - [x] Identified schema cache timing issue after refactoring seeding to NodeService - [x] Discovered caches built BEFORE schemas exist on first launch - [x] Root cause: `build_schema_caches()` queries empty schema table during `SurrealStore::new()` - [x] Impact: `has_spoke_table()` returns false for "task", "text", etc. → spoke records not created - [x] Verified this is a production bug, not just a test issue ### Phase 2: Solution Design ✅ - [x] Designed two-phase cache population strategy: - **First launch**: NodeService populates cache incrementally during seeding (no re-query) - **Subsequent launches**: SurrealStore queries DB once at startup (already populated) - [x] Created comprehensive documentation in docs/architecture/data/schema-cache-population.md - [x] Updated code documentation in SurrealStore struct fields - [x] Documented `build_schema_caches()` with both scenarios - [x] Implemented and documented `add_to_schema_cache()` method signature ### Phase 3: Test Helper Fix (Temporary) ✅ - [x] Fixed 10 SurrealStore atomic operation tests - [x] Updated `create_test_store()` to call NodeService for seeding + cache rebuild - [x] Tests now pass: 479 passed, 5 failed (down from 15 failures) ## Remaining Work ### Phase 4: Implement Incremental Caching - [ ] Update `NodeService::seed_core_schemas_if_needed()` to call `add_to_schema_cache()` after creating each schema - [ ] Handle `Arc::get_mut()` pattern to get mutable access for cache updates - [ ] Remove temporary `rebuild_schema_caches()` approach from test helper - [ ] Test with fresh database to verify cache populated correctly ### Phase 5: Clean Up - [ ] Remove `rebuild_schema_caches()` method (temporary solution) - [ ] Simplify `create_test_store()` helper - [ ] Remove `#[allow(dead_code)]` annotations - [ ] Verify all tests pass with new incremental approach ### Phase 6: Final Validation - [ ] Run test:all to verify no new failures - [ ] Run quality:fix and commit changes - [ ] Update PR with complete implementation - [ ] Verify cache works correctly on both first launch and subsequent launches ## Current State **Files Modified:** - `packages/core/src/db/surreal_store.rs`: - Lines 331-355: Updated cache field docs with two-phase population strategy - Lines 594-614: Documented `build_schema_caches()` with both scenarios - Lines 711-754: Implemented both `add_to_schema_cache()` (ready) and `rebuild_schema_caches()` (temporary) - Lines 3792-3830: Fixed `create_test_store()` helper (temporary rebuild approach) - `packages/core/src/services/node_service.rs`: - Lines 462-466: Added cache population strategy documentation (TODO) - Implementation not yet updated - `docs/architecture/data/schema-cache-population.md`: Complete design document **Test Status:** - Frontend: 1477 passed ✓ - Rust: 479 passed, 5 failed - **10 SurrealStore tests fixed** (were failing due to missing cache) - Remaining 5 failures: Task property storage/retrieval (likely pre-existing bugs) **Known Issues:** - Using temporary `rebuild_schema_caches()` in test helper (works but not optimal) - Production code has same cache timing issue (needs incremental caching) - `add_to_schema_cache()` method exists but not yet called ## Context for Next Session **The Problem:** Schema caches (`types_with_spoke_tables`, `valid_node_types`) determine which node types need spoke tables. They're built by querying the `schema` table. But on first launch: 1. `SurrealStore::new()` builds caches → queries empty schema table → cache = {"schema"} only 2. `NodeService::new()` seeds schemas → cache is stale 3. `create_node("task")` → `has_spoke_table("task")` returns false → bug! **The Solution (Fully Documented):** Two-phase caching strategy documented in `docs/architecture/data/schema-cache-population.md`: **First launch:** ```rust for schema in core_schemas { create_schema_node_atomic(schema); // TODO: Add this call in NodeService Arc::get_mut(&mut store)? .add_to_schema_cache(schema.id, !schema.fields.is_empty()); } ``` **Subsequent launches:** - Caches already built by `build_schema_caches()` in `SurrealStore::new()` **Implementation Location:** - File: `packages/core/src/services/node_service.rs` - Method: `seed_core_schemas_if_needed()` - Line: ~520 (after `create_schema_node_atomic()` call) **Next Steps:** 1. Add the `add_to_schema_cache()` call in the seeding loop 2. Handle Arc mutability (requires `mut store` parameter in `new()`) 3. Clean up temporary test helper workaround 4. Verify tests pass ## Acceptance Criteria Status From Issue #704: - [x] seed_core_schemas() removed from SurrealStore - [x] seed_core_schemas_http() removed from SurrealStore - [x] Schema seeding calls removed from SurrealStore::new() and new_http() - [x] NodeService::new() made async with seeding logic - [x] All 7 core schemas seeded correctly - [ ] **Cache population implemented** (documented, needs code) - [ ] Tests pass (479/484 passing) - [ ] No regressions ## References - **Design Doc**: `docs/architecture/data/schema-cache-population.md` - **Issue**: #704 - **PR**: #706 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement incremental schema cache population (Issue #704) ## Summary Completes the schema seeding refactor by implementing incremental cache population during first-launch seeding. Schema caches are now updated in memory as each schema is created, avoiding stale caches. ## Key Changes ### API Change: NodeService::new() signature - Changed from `new(store: Arc<SurrealStore>)` to `new(store: &mut Arc<SurrealStore>)` - Takes mutable reference to enable cache updates via `Arc::get_mut()` - Cache updates happen BEFORE cloning Arc into Self ### Implementation Details - `seed_core_schemas_if_needed()` now takes `&mut Arc<SurrealStore>` - SchemaTableManager scoped to release Arc clone before `Arc::get_mut()` - Cache updates collected during seeding and applied after all schemas created - Removed temporary `rebuild_schema_caches()` method ### Two-Phase Cache Population Strategy - **First launch**: NodeService seeds schemas, populates caches incrementally - **Subsequent launches**: SurrealStore queries populated schema table once ## Files Changed - `node_service.rs`: New API, incremental caching implementation - `surreal_store.rs`: Removed rebuild_schema_caches(), simplified test helper - All call sites updated to use `&mut Arc<SurrealStore>` pattern - Doc examples updated to reflect new API ## Test Status - All 484 Rust tests pass - All 128 doc tests pass - Tauri build compiles successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix isSchemaNode type guard to not require nodeType field The /api/schemas/:id endpoint returns SchemaNode without the nodeType field (it's implicit - always "schema"). Updated the type guard to check for schema-specific fields (isCore, schemaVersion, fields) instead. Also updated documentation to clarify that nodeType is NOT included in the API response. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Documentation, error types, and code clarity improvements - Add verification section to schema-cache-population.md with manual and automated test steps - Add InitializationError variant to NodeServiceError for semantic accuracy - Change Arc::get_mut() error from SerializationError to InitializationError (lifecycle error, not serialization) - Enhance SchemaTableManager scope comment with rationale explaining Arc ownership requirement - Make SchemaNode.nodeType optional to match API response reality (implicit in /api/schemas/:id) Addresses reviewer recommendations from PR review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* WIP: Fix SQL query camelCase aliasing for SchemaNode and TaskNode deserialization ## Completed in This Session ### Phase 1: Root Cause Analysis ✅ - [x] Investigated 500 error on GET /api/schemas/date endpoint - [x] Discovered deserialization failure in get_schema_node() query - [x] Identified violation of identifier naming conventions (database snake_case vs serde camelCase) - [x] Root cause: SQL queries returned snake_case columns but Rust structs expected camelCase ### Phase 2: Query Fixes ✅ - [x] Fixed get_schema_node() query with camelCase aliases: - `is_core AS isCore` - `version AS schemaVersion` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Fixed get_task_node() query with camelCase aliases: - `due_date AS dueDate` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Updated documentation comments to explain aliasing requirement ### Phase 3: Issue Creation ✅ - [x] Created Issue #704 for proper architectural fix - [x] Detailed implementation guide for moving schema seeding from SurrealStore to NodeService ## Remaining Work ### Phase 4: Complete Architectural Refactor (Issue #704) - [ ] Move seed_core_schemas() logic from SurrealStore to NodeService - [ ] Remove seed_core_schemas() and seed_core_schemas_http() from SurrealStore - [ ] Make NodeService::new() async with seeding initialization - [ ] Update all callsites (dev-proxy, Tauri commands) - [ ] Write unit tests for NodeService seeding - [ ] Integration test with fresh database - [ ] Verify no regressions ## Current State **Files Modified:** - `packages/core/src/db/surreal_store.rs`: - Lines 3701-3713: Updated get_task_node() docstring query example - Lines 3745-3757: Fixed get_task_node() query with camelCase aliases - Lines 3780-3792: Updated get_schema_node() docstring query example - Lines 3822-3834: Fixed get_schema_node() query with camelCase aliases - Line 488: Added seed_core_schemas_http() call (temporary - will be removed in Phase 4) - Lines 758-829: Added seed_core_schemas_http() function (temporary - will be removed in Phase 4) **Tests Status:** Not yet run - queries fixed but architectural refactor pending **Known Issues:** - Schema seeding still in wrong layer (SurrealStore instead of NodeService) - HTTP mode has duplicate seeding logic (seed_core_schemas_http) - These are intentional temporary fixes - proper solution in Issue #704 ## Context for Next Session **Background:** The immediate bug was SchemaNode deserialization failing because SQL queries returned snake_case database columns but the Rust struct uses `#[serde(rename_all = "camelCase")]` which expects camelCase field names during deserialization. This violated our naming conventions documented in `docs/architecture/development/standards/identifier-naming-conventions.md`. **Quick Fixes Applied:** Added SQL column aliases to match serde expectations (database stores snake_case, queries alias to camelCase for deserialization). **Proper Solution (Issue #704):** The real problem is architectural - `SurrealStore` (data layer) shouldn't be seeding schemas (domain data). That responsibility belongs to `NodeService` (domain layer). Issue #704 has a complete implementation guide for moving the seeding logic to the proper layer. **Next Steps:** 1. Follow Issue #704 implementation guide 2. Move seeding to NodeService::new() 3. Remove seeding from SurrealStore entirely 4. Test with fresh database to ensure seeding works in both embedded and HTTP modes ## Acceptance Criteria Status From Issue #704: - [ ] seed_core_schemas() removed from SurrealStore - [ ] seed_core_schemas_http() removed from SurrealStore - [ ] Schema seeding calls removed from SurrealStore::new() and new_http() - [ ] NodeService::new() made async with seeding logic - [ ] All 7 core schemas seeded correctly - [ ] Dev-proxy works with fresh database - [ ] Tests pass - [ ] No regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * WIP: Document schema cache population strategy (Issue #704) ## Completed in This Session ### Phase 1: Root Cause Analysis ✅ - [x] Identified schema cache timing issue after refactoring seeding to NodeService - [x] Discovered caches built BEFORE schemas exist on first launch - [x] Root cause: `build_schema_caches()` queries empty schema table during `SurrealStore::new()` - [x] Impact: `has_spoke_table()` returns false for "task", "text", etc. → spoke records not created - [x] Verified this is a production bug, not just a test issue ### Phase 2: Solution Design ✅ - [x] Designed two-phase cache population strategy: - **First launch**: NodeService populates cache incrementally during seeding (no re-query) - **Subsequent launches**: SurrealStore queries DB once at startup (already populated) - [x] Created comprehensive documentation in docs/architecture/data/schema-cache-population.md - [x] Updated code documentation in SurrealStore struct fields - [x] Documented `build_schema_caches()` with both scenarios - [x] Implemented and documented `add_to_schema_cache()` method signature ### Phase 3: Test Helper Fix (Temporary) ✅ - [x] Fixed 10 SurrealStore atomic operation tests - [x] Updated `create_test_store()` to call NodeService for seeding + cache rebuild - [x] Tests now pass: 479 passed, 5 failed (down from 15 failures) ## Remaining Work ### Phase 4: Implement Incremental Caching - [ ] Update `NodeService::seed_core_schemas_if_needed()` to call `add_to_schema_cache()` after creating each schema - [ ] Handle `Arc::get_mut()` pattern to get mutable access for cache updates - [ ] Remove temporary `rebuild_schema_caches()` approach from test helper - [ ] Test with fresh database to verify cache populated correctly ### Phase 5: Clean Up - [ ] Remove `rebuild_schema_caches()` method (temporary solution) - [ ] Simplify `create_test_store()` helper - [ ] Remove `#[allow(dead_code)]` annotations - [ ] Verify all tests pass with new incremental approach ### Phase 6: Final Validation - [ ] Run test:all to verify no new failures - [ ] Run quality:fix and commit changes - [ ] Update PR with complete implementation - [ ] Verify cache works correctly on both first launch and subsequent launches ## Current State **Files Modified:** - `packages/core/src/db/surreal_store.rs`: - Lines 331-355: Updated cache field docs with two-phase population strategy - Lines 594-614: Documented `build_schema_caches()` with both scenarios - Lines 711-754: Implemented both `add_to_schema_cache()` (ready) and `rebuild_schema_caches()` (temporary) - Lines 3792-3830: Fixed `create_test_store()` helper (temporary rebuild approach) - `packages/core/src/services/node_service.rs`: - Lines 462-466: Added cache population strategy documentation (TODO) - Implementation not yet updated - `docs/architecture/data/schema-cache-population.md`: Complete design document **Test Status:** - Frontend: 1477 passed ✓ - Rust: 479 passed, 5 failed - **10 SurrealStore tests fixed** (were failing due to missing cache) - Remaining 5 failures: Task property storage/retrieval (likely pre-existing bugs) **Known Issues:** - Using temporary `rebuild_schema_caches()` in test helper (works but not optimal) - Production code has same cache timing issue (needs incremental caching) - `add_to_schema_cache()` method exists but not yet called ## Context for Next Session **The Problem:** Schema caches (`types_with_spoke_tables`, `valid_node_types`) determine which node types need spoke tables. They're built by querying the `schema` table. But on first launch: 1. `SurrealStore::new()` builds caches → queries empty schema table → cache = {"schema"} only 2. `NodeService::new()` seeds schemas → cache is stale 3. `create_node("task")` → `has_spoke_table("task")` returns false → bug! **The Solution (Fully Documented):** Two-phase caching strategy documented in `docs/architecture/data/schema-cache-population.md`: **First launch:** ```rust for schema in core_schemas { create_schema_node_atomic(schema); // TODO: Add this call in NodeService Arc::get_mut(&mut store)? .add_to_schema_cache(schema.id, !schema.fields.is_empty()); } ``` **Subsequent launches:** - Caches already built by `build_schema_caches()` in `SurrealStore::new()` **Implementation Location:** - File: `packages/core/src/services/node_service.rs` - Method: `seed_core_schemas_if_needed()` - Line: ~520 (after `create_schema_node_atomic()` call) **Next Steps:** 1. Add the `add_to_schema_cache()` call in the seeding loop 2. Handle Arc mutability (requires `mut store` parameter in `new()`) 3. Clean up temporary test helper workaround 4. Verify tests pass ## Acceptance Criteria Status From Issue #704: - [x] seed_core_schemas() removed from SurrealStore - [x] seed_core_schemas_http() removed from SurrealStore - [x] Schema seeding calls removed from SurrealStore::new() and new_http() - [x] NodeService::new() made async with seeding logic - [x] All 7 core schemas seeded correctly - [ ] **Cache population implemented** (documented, needs code) - [ ] Tests pass (479/484 passing) - [ ] No regressions ## References - **Design Doc**: `docs/architecture/data/schema-cache-population.md` - **Issue**: #704 - **PR**: #706 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement incremental schema cache population (Issue #704) ## Summary Completes the schema seeding refactor by implementing incremental cache population during first-launch seeding. Schema caches are now updated in memory as each schema is created, avoiding stale caches. ## Key Changes ### API Change: NodeService::new() signature - Changed from `new(store: Arc<SurrealStore>)` to `new(store: &mut Arc<SurrealStore>)` - Takes mutable reference to enable cache updates via `Arc::get_mut()` - Cache updates happen BEFORE cloning Arc into Self ### Implementation Details - `seed_core_schemas_if_needed()` now takes `&mut Arc<SurrealStore>` - SchemaTableManager scoped to release Arc clone before `Arc::get_mut()` - Cache updates collected during seeding and applied after all schemas created - Removed temporary `rebuild_schema_caches()` method ### Two-Phase Cache Population Strategy - **First launch**: NodeService seeds schemas, populates caches incrementally - **Subsequent launches**: SurrealStore queries populated schema table once ## Files Changed - `node_service.rs`: New API, incremental caching implementation - `surreal_store.rs`: Removed rebuild_schema_caches(), simplified test helper - All call sites updated to use `&mut Arc<SurrealStore>` pattern - Doc examples updated to reflect new API ## Test Status - All 484 Rust tests pass - All 128 doc tests pass - Tauri build compiles successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix isSchemaNode type guard to not require nodeType field The /api/schemas/:id endpoint returns SchemaNode without the nodeType field (it's implicit - always "schema"). Updated the type guard to check for schema-specific fields (isCore, schemaVersion, fields) instead. Also updated documentation to clarify that nodeType is NOT included in the API response. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Documentation, error types, and code clarity improvements - Add verification section to schema-cache-population.md with manual and automated test steps - Add InitializationError variant to NodeServiceError for semantic accuracy - Change Arc::get_mut() error from SerializationError to InitializationError (lifecycle error, not serialization) - Enhance SchemaTableManager scope comment with rationale explaining Arc ownership requirement - Make SchemaNode.nodeType optional to match API response reality (implicit in /api/schemas/:id) Addresses reviewer recommendations from PR review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* WIP: Fix SQL query camelCase aliasing for SchemaNode and TaskNode deserialization ## Completed in This Session ### Phase 1: Root Cause Analysis ✅ - [x] Investigated 500 error on GET /api/schemas/date endpoint - [x] Discovered deserialization failure in get_schema_node() query - [x] Identified violation of identifier naming conventions (database snake_case vs serde camelCase) - [x] Root cause: SQL queries returned snake_case columns but Rust structs expected camelCase ### Phase 2: Query Fixes ✅ - [x] Fixed get_schema_node() query with camelCase aliases: - `is_core AS isCore` - `version AS schemaVersion` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Fixed get_task_node() query with camelCase aliases: - `due_date AS dueDate` - `node.created_at AS createdAt` - `node.modified_at AS modifiedAt` - [x] Updated documentation comments to explain aliasing requirement ### Phase 3: Issue Creation ✅ - [x] Created Issue #704 for proper architectural fix - [x] Detailed implementation guide for moving schema seeding from SurrealStore to NodeService ## Remaining Work ### Phase 4: Complete Architectural Refactor (Issue #704) - [ ] Move seed_core_schemas() logic from SurrealStore to NodeService - [ ] Remove seed_core_schemas() and seed_core_schemas_http() from SurrealStore - [ ] Make NodeService::new() async with seeding initialization - [ ] Update all callsites (dev-proxy, Tauri commands) - [ ] Write unit tests for NodeService seeding - [ ] Integration test with fresh database - [ ] Verify no regressions ## Current State **Files Modified:** - `packages/core/src/db/surreal_store.rs`: - Lines 3701-3713: Updated get_task_node() docstring query example - Lines 3745-3757: Fixed get_task_node() query with camelCase aliases - Lines 3780-3792: Updated get_schema_node() docstring query example - Lines 3822-3834: Fixed get_schema_node() query with camelCase aliases - Line 488: Added seed_core_schemas_http() call (temporary - will be removed in Phase 4) - Lines 758-829: Added seed_core_schemas_http() function (temporary - will be removed in Phase 4) **Tests Status:** Not yet run - queries fixed but architectural refactor pending **Known Issues:** - Schema seeding still in wrong layer (SurrealStore instead of NodeService) - HTTP mode has duplicate seeding logic (seed_core_schemas_http) - These are intentional temporary fixes - proper solution in Issue #704 ## Context for Next Session **Background:** The immediate bug was SchemaNode deserialization failing because SQL queries returned snake_case database columns but the Rust struct uses `#[serde(rename_all = "camelCase")]` which expects camelCase field names during deserialization. This violated our naming conventions documented in `docs/architecture/development/standards/identifier-naming-conventions.md`. **Quick Fixes Applied:** Added SQL column aliases to match serde expectations (database stores snake_case, queries alias to camelCase for deserialization). **Proper Solution (Issue #704):** The real problem is architectural - `SurrealStore` (data layer) shouldn't be seeding schemas (domain data). That responsibility belongs to `NodeService` (domain layer). Issue #704 has a complete implementation guide for moving the seeding logic to the proper layer. **Next Steps:** 1. Follow Issue #704 implementation guide 2. Move seeding to NodeService::new() 3. Remove seeding from SurrealStore entirely 4. Test with fresh database to ensure seeding works in both embedded and HTTP modes ## Acceptance Criteria Status From Issue #704: - [ ] seed_core_schemas() removed from SurrealStore - [ ] seed_core_schemas_http() removed from SurrealStore - [ ] Schema seeding calls removed from SurrealStore::new() and new_http() - [ ] NodeService::new() made async with seeding logic - [ ] All 7 core schemas seeded correctly - [ ] Dev-proxy works with fresh database - [ ] Tests pass - [ ] No regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * WIP: Document schema cache population strategy (Issue #704) ## Completed in This Session ### Phase 1: Root Cause Analysis ✅ - [x] Identified schema cache timing issue after refactoring seeding to NodeService - [x] Discovered caches built BEFORE schemas exist on first launch - [x] Root cause: `build_schema_caches()` queries empty schema table during `SurrealStore::new()` - [x] Impact: `has_spoke_table()` returns false for "task", "text", etc. → spoke records not created - [x] Verified this is a production bug, not just a test issue ### Phase 2: Solution Design ✅ - [x] Designed two-phase cache population strategy: - **First launch**: NodeService populates cache incrementally during seeding (no re-query) - **Subsequent launches**: SurrealStore queries DB once at startup (already populated) - [x] Created comprehensive documentation in docs/architecture/data/schema-cache-population.md - [x] Updated code documentation in SurrealStore struct fields - [x] Documented `build_schema_caches()` with both scenarios - [x] Implemented and documented `add_to_schema_cache()` method signature ### Phase 3: Test Helper Fix (Temporary) ✅ - [x] Fixed 10 SurrealStore atomic operation tests - [x] Updated `create_test_store()` to call NodeService for seeding + cache rebuild - [x] Tests now pass: 479 passed, 5 failed (down from 15 failures) ## Remaining Work ### Phase 4: Implement Incremental Caching - [ ] Update `NodeService::seed_core_schemas_if_needed()` to call `add_to_schema_cache()` after creating each schema - [ ] Handle `Arc::get_mut()` pattern to get mutable access for cache updates - [ ] Remove temporary `rebuild_schema_caches()` approach from test helper - [ ] Test with fresh database to verify cache populated correctly ### Phase 5: Clean Up - [ ] Remove `rebuild_schema_caches()` method (temporary solution) - [ ] Simplify `create_test_store()` helper - [ ] Remove `#[allow(dead_code)]` annotations - [ ] Verify all tests pass with new incremental approach ### Phase 6: Final Validation - [ ] Run test:all to verify no new failures - [ ] Run quality:fix and commit changes - [ ] Update PR with complete implementation - [ ] Verify cache works correctly on both first launch and subsequent launches ## Current State **Files Modified:** - `packages/core/src/db/surreal_store.rs`: - Lines 331-355: Updated cache field docs with two-phase population strategy - Lines 594-614: Documented `build_schema_caches()` with both scenarios - Lines 711-754: Implemented both `add_to_schema_cache()` (ready) and `rebuild_schema_caches()` (temporary) - Lines 3792-3830: Fixed `create_test_store()` helper (temporary rebuild approach) - `packages/core/src/services/node_service.rs`: - Lines 462-466: Added cache population strategy documentation (TODO) - Implementation not yet updated - `docs/architecture/data/schema-cache-population.md`: Complete design document **Test Status:** - Frontend: 1477 passed ✓ - Rust: 479 passed, 5 failed - **10 SurrealStore tests fixed** (were failing due to missing cache) - Remaining 5 failures: Task property storage/retrieval (likely pre-existing bugs) **Known Issues:** - Using temporary `rebuild_schema_caches()` in test helper (works but not optimal) - Production code has same cache timing issue (needs incremental caching) - `add_to_schema_cache()` method exists but not yet called ## Context for Next Session **The Problem:** Schema caches (`types_with_spoke_tables`, `valid_node_types`) determine which node types need spoke tables. They're built by querying the `schema` table. But on first launch: 1. `SurrealStore::new()` builds caches → queries empty schema table → cache = {"schema"} only 2. `NodeService::new()` seeds schemas → cache is stale 3. `create_node("task")` → `has_spoke_table("task")` returns false → bug! **The Solution (Fully Documented):** Two-phase caching strategy documented in `docs/architecture/data/schema-cache-population.md`: **First launch:** ```rust for schema in core_schemas { create_schema_node_atomic(schema); // TODO: Add this call in NodeService Arc::get_mut(&mut store)? .add_to_schema_cache(schema.id, !schema.fields.is_empty()); } ``` **Subsequent launches:** - Caches already built by `build_schema_caches()` in `SurrealStore::new()` **Implementation Location:** - File: `packages/core/src/services/node_service.rs` - Method: `seed_core_schemas_if_needed()` - Line: ~520 (after `create_schema_node_atomic()` call) **Next Steps:** 1. Add the `add_to_schema_cache()` call in the seeding loop 2. Handle Arc mutability (requires `mut store` parameter in `new()`) 3. Clean up temporary test helper workaround 4. Verify tests pass ## Acceptance Criteria Status From Issue #704: - [x] seed_core_schemas() removed from SurrealStore - [x] seed_core_schemas_http() removed from SurrealStore - [x] Schema seeding calls removed from SurrealStore::new() and new_http() - [x] NodeService::new() made async with seeding logic - [x] All 7 core schemas seeded correctly - [ ] **Cache population implemented** (documented, needs code) - [ ] Tests pass (479/484 passing) - [ ] No regressions ## References - **Design Doc**: `docs/architecture/data/schema-cache-population.md` - **Issue**: #704 - **PR**: #706 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement incremental schema cache population (Issue #704) ## Summary Completes the schema seeding refactor by implementing incremental cache population during first-launch seeding. Schema caches are now updated in memory as each schema is created, avoiding stale caches. ## Key Changes ### API Change: NodeService::new() signature - Changed from `new(store: Arc<SurrealStore>)` to `new(store: &mut Arc<SurrealStore>)` - Takes mutable reference to enable cache updates via `Arc::get_mut()` - Cache updates happen BEFORE cloning Arc into Self ### Implementation Details - `seed_core_schemas_if_needed()` now takes `&mut Arc<SurrealStore>` - SchemaTableManager scoped to release Arc clone before `Arc::get_mut()` - Cache updates collected during seeding and applied after all schemas created - Removed temporary `rebuild_schema_caches()` method ### Two-Phase Cache Population Strategy - **First launch**: NodeService seeds schemas, populates caches incrementally - **Subsequent launches**: SurrealStore queries populated schema table once ## Files Changed - `node_service.rs`: New API, incremental caching implementation - `surreal_store.rs`: Removed rebuild_schema_caches(), simplified test helper - All call sites updated to use `&mut Arc<SurrealStore>` pattern - Doc examples updated to reflect new API ## Test Status - All 484 Rust tests pass - All 128 doc tests pass - Tauri build compiles successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix isSchemaNode type guard to not require nodeType field The /api/schemas/:id endpoint returns SchemaNode without the nodeType field (it's implicit - always "schema"). Updated the type guard to check for schema-specific fields (isCore, schemaVersion, fields) instead. Also updated documentation to clarify that nodeType is NOT included in the API response. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Documentation, error types, and code clarity improvements - Add verification section to schema-cache-population.md with manual and automated test steps - Add InitializationError variant to NodeServiceError for semantic accuracy - Change Arc::get_mut() error from SerializationError to InitializationError (lifecycle error, not serialization) - Enhance SchemaTableManager scope comment with rationale explaining Arc ownership requirement - Make SchemaNode.nodeType optional to match API response reality (implicit in /api/schemas/:id) Addresses reviewer recommendations from PR review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
NodeService::new()signature to take&mut Arc<SurrealStore>to enableArc::get_mut()for cache updatesisSchemaNode()TypeScript type guard to not requirenodeTypefield (implicit from endpoint)rebuild_schema_caches()workaround from test helperKey Changes
Rust Backend
NodeService::new(store: &mut Arc<SurrealStore>)- New API pattern for cache mutationseed_core_schemas_if_needed()now populates caches incrementally as schemas are createdArc::get_mut()issue by scopingSchemaTableManagerto drop before cache updateTypeScript Frontend
isSchemaNode()to check schema-specific fields (isCore, schemaVersion, fields) instead of requiring nodeTypeTest Results
Test plan
Closes #704
🤖 Generated with Claude Code